cid#1640468 Dereference after null check
[LibreOffice.git] / toolkit / source / awt / vclxtoolkit.cxx
blob46367dc8fffbab88ef43a1a70c02b4431ffe647c
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 <sal/config.h>
22 #include <string_view>
23 #include <thread>
25 #ifdef _WIN32
26 #include <prewin.h>
27 #include <postwin.h>
28 #endif
29 #include <config_features.h>
30 #include <com/sun/star/awt/WindowAttribute.hpp>
31 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
32 #include <com/sun/star/awt/WindowClass.hpp>
33 #include <com/sun/star/awt/MessageBoxButtons.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/lang/SystemDependent.hpp>
36 #include <com/sun/star/awt/FocusEvent.hpp>
37 #include <com/sun/star/awt/KeyEvent.hpp>
38 #include <com/sun/star/awt/KeyModifier.hpp>
39 #include <com/sun/star/lang/EventObject.hpp>
40 #include <com/sun/star/uno/Reference.hxx>
41 #include <com/sun/star/uno/Sequence.hxx>
42 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <com/sun/star/uno/XInterface.hpp>
44 #include <com/sun/star/beans/NamedValue.hpp>
45 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
48 #include <com/sun/star/lang/XServiceInfo.hpp>
49 #include <com/sun/star/awt/XToolkitExperimental.hpp>
50 #include <com/sun/star/awt/XToolkitRobot.hpp>
52 #include <cppuhelper/bootstrap.hxx>
53 #include <comphelper/compbase.hxx>
54 #include <cppuhelper/supportsservice.hxx>
55 #include <o3tl/safeint.hxx>
56 #include <osl/conditn.hxx>
57 #include <osl/module.h>
58 #include <osl/thread.hxx>
59 #include <osl/mutex.hxx>
60 #include <rtl/ref.hxx>
61 #include <rtl/process.h>
62 #include <sal/log.hxx>
63 #include <tools/link.hxx>
64 #include <vcl/idletask.hxx>
65 #include <vcl/unohelp.hxx>
66 #include <vcl/wintypes.hxx>
68 #ifdef MACOSX
69 #include <premac.h>
70 #include <Cocoa/Cocoa.h>
71 #include <postmac.h>
72 #endif
74 #include <utility>
75 #include <vcl/sysdata.hxx>
76 #include <vcl/textrectinfo.hxx>
77 #include <vcl/toolkit/vclmedit.hxx>
79 #include <toolkit/awt/vclxwindows.hxx>
80 #include <awt/vclxwindows.hxx>
81 #include <awt/vclxsystemdependentwindow.hxx>
82 #include <awt/vclxregion.hxx>
83 #include <awt/vclxtabpagecontainer.hxx>
84 #include <awt/vclxtopwindow.hxx>
86 #include <awt/animatedimagespeer.hxx>
87 #include <toolkit/awt/vclxwindow.hxx>
88 #include <toolkit/helper/vclunohelper.hxx>
89 #include <helper/property.hxx>
91 #include <controls/filectrl.hxx>
92 #include <controls/svmedit.hxx>
93 #include <controls/table/tablecontrol.hxx>
94 #include <controls/treecontrolpeer.hxx>
95 #include <vcl/toolkit/button.hxx>
96 #include <vcl/toolkit/calendar.hxx>
97 #include <vcl/toolkit/combobox.hxx>
98 #include <vcl/ctrl.hxx>
99 #include <vcl/toolkit/dialog.hxx>
100 #include <vcl/dockingarea.hxx>
101 #include <vcl/dockwin.hxx>
102 #include <vcl/toolkit/edit.hxx>
103 #include <vcl/event.hxx>
104 #include <vcl/toolkit/field.hxx>
105 #include <vcl/toolkit/fixed.hxx>
106 #include <vcl/toolkit/fixedhyper.hxx>
107 #include <vcl/toolkit/floatwin.hxx>
108 #include <vcl/toolkit/fmtfield.hxx>
109 #include <vcl/toolkit/prgsbar.hxx>
110 #include <vcl/scheduler.hxx>
111 #include <vcl/toolkit/lstbox.hxx>
112 #include <vcl/toolkit/longcurr.hxx>
113 #include <vcl/toolkit/menubtn.hxx>
114 #include <vcl/stdtext.hxx>
115 #include <vcl/toolkit/scrbar.hxx>
116 #include <vcl/split.hxx>
117 #include <vcl/splitwin.hxx>
118 #include <vcl/status.hxx>
119 #include <vcl/svapp.hxx>
120 #include <vcl/syschild.hxx>
121 #include <vcl/tabctrl.hxx>
122 #include <vcl/tabpage.hxx>
123 #include <vcl/toolbox.hxx>
124 #include <vcl/virdev.hxx>
125 #include <vcl/window.hxx>
126 #include <vcl/wrkwin.hxx>
127 #include <vcl/toolkit/group.hxx>
128 #include <vcl/toolkit/imgctrl.hxx>
129 #include <vcl/toolkit/morebtn.hxx>
130 #include <vcl/toolkit/roadmap.hxx>
131 #include <vcl/toolkit/spin.hxx>
132 #include <vcl/toolkit/tabdlg.hxx>
133 #include <vcl/toolkit/throbber.hxx>
134 #if HAVE_FEATURE_OPENGL
135 #include <vcl/opengl/OpenGLWrapper.hxx>
136 #endif
137 #include <awt/vclxspinbutton.hxx>
138 #include <tools/debug.hxx>
139 #include <comphelper/lok.hxx>
140 #include <comphelper/diagnose_ex.hxx>
141 #include <comphelper/interfacecontainer4.hxx>
142 #include <comphelper/processfactory.hxx>
143 #include <comphelper/profilezone.hxx>
145 #include <helper/msgbox.hxx>
146 #include <helper/scrollabledialog.hxx>
147 #include <helper/unowrapper.hxx>
149 #if defined(_WIN32)
150 #define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_WIN32
151 #elif defined(MACOSX)
152 #define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_MAC
153 #elif defined(UNX)
154 #define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_XWINDOW
155 #endif
157 void MessBox::ImplInitButtons()
159 ButtonDialogFlags nOKFlags = ButtonDialogFlags::OK;
160 ButtonDialogFlags nCancelFlags = ButtonDialogFlags::Cancel;
161 ButtonDialogFlags nRetryFlags = ButtonDialogFlags::NONE;
162 ButtonDialogFlags nYesFlags = ButtonDialogFlags::NONE;
163 ButtonDialogFlags nNoFlags = ButtonDialogFlags::NONE;
165 if ( mnMessBoxStyle & MessBoxStyle::OkCancel )
167 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
168 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
169 else // MessBoxStyle::DefaultOk
170 nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
172 AddButton( StandardButtonType::OK, RET_OK, nOKFlags );
173 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
175 else if ( mnMessBoxStyle & MessBoxStyle::YesNo )
177 if ( mnMessBoxStyle & MessBoxStyle::DefaultYes )
178 nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
179 else // MessBoxStyle::DefaultNo
180 nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
181 nNoFlags |= ButtonDialogFlags::Cancel;
183 AddButton( StandardButtonType::Yes, RET_YES, nYesFlags );
184 AddButton( StandardButtonType::No, RET_NO, nNoFlags );
186 else if ( mnMessBoxStyle & MessBoxStyle::YesNoCancel )
188 if ( mnMessBoxStyle & MessBoxStyle::DefaultYes )
189 nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
190 else if ( mnMessBoxStyle & MessBoxStyle::DefaultNo )
191 nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
192 else
193 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
195 AddButton( StandardButtonType::Yes, RET_YES, nYesFlags );
196 AddButton( StandardButtonType::No, RET_NO, nNoFlags );
197 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
199 else if ( mnMessBoxStyle & MessBoxStyle::RetryCancel )
201 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
202 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
203 else // MessBoxStyle::DefaultRetry
204 nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
206 AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags );
207 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
209 else if ( mnMessBoxStyle & MessBoxStyle::AbortRetryIgnore )
211 ButtonDialogFlags nAbortFlags = ButtonDialogFlags::NONE;
212 ButtonDialogFlags nIgnoreFlags = ButtonDialogFlags::NONE;
214 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
215 nAbortFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
216 else if ( mnMessBoxStyle & MessBoxStyle::DefaultRetry )
217 nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
218 else if ( mnMessBoxStyle & MessBoxStyle::DefaultIgnore )
219 nIgnoreFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
221 AddButton( StandardButtonType::Abort, RET_CANCEL, nAbortFlags );
222 AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags );
223 AddButton( StandardButtonType::Ignore, RET_IGNORE, nIgnoreFlags );
225 else if ( mnMessBoxStyle & MessBoxStyle::Ok )
227 nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
229 AddButton( StandardButtonType::OK, RET_OK, nOKFlags );
233 MessBox::MessBox(vcl::Window* pParent, MessBoxStyle nMessBoxStyle, WinBits nWinBits,
234 const OUString& rTitle, OUString aMessage) :
235 ButtonDialog( WindowType::MESSBOX ),
236 mbHelpBtn( false ),
237 mnMessBoxStyle( nMessBoxStyle ),
238 maMessText(std::move( aMessage ))
240 ImplLOKNotifier(pParent);
241 ImplInitDialog(pParent, nWinBits | WB_MOVEABLE | WB_HORZ | WB_CENTER);
242 ImplInitButtons();
244 if ( !rTitle.isEmpty() )
245 SetText( rTitle );
248 MessBox::~MessBox()
250 disposeOnce();
253 void MessBox::dispose()
255 mpVCLMultiLineEdit.disposeAndClear();
256 mpFixedImage.disposeAndClear();
257 ButtonDialog::dispose();
260 void MessBox::ImplPosControls()
262 if ( !GetHelpId().isEmpty() )
264 if ( !mbHelpBtn )
266 AddButton( StandardButtonType::Help, RET_HELP, ButtonDialogFlags::Help, 3 );
267 mbHelpBtn = true;
270 else
272 if ( mbHelpBtn )
274 RemoveButton( RET_HELP );
275 mbHelpBtn = false;
279 TextRectInfo aTextInfo;
280 tools::Rectangle aRect( 0, 0, 30000, 30000 );
281 tools::Rectangle aFormatRect;
282 Point aTextPos( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+IMPL_MSGBOX_OFFSET_EXTRA_Y );
283 Size aImageSize;
284 Size aPageSize;
285 Size aMEditSize;
286 tools::Long nTitleWidth;
287 tools::Long nButtonSize = ImplGetButtonSize();
288 tools::Long nMaxLineWidth;
289 tools::Long nWidth;
290 WinBits nWinStyle = WB_LEFT | WB_NOLABEL;
291 DrawTextFlags nTextStyle = DrawTextFlags::MultiLine | DrawTextFlags::Top | DrawTextFlags::Left;
293 mpVCLMultiLineEdit.disposeAndClear();
294 mpFixedImage.disposeAndClear();
296 // Clean up message text with tabs
297 OUString aMessText(maMessText.replaceAll("\t", " "));
299 //If window too small, we make dialog box be wider
300 tools::Long nMaxWidth = 630 * GetDPIScaleFactor();
302 // MessagBox should be at least as wide as to see the title
303 // Extra-Width for Close button, because Close button is set after this call
304 nTitleWidth = CalcTitleWidth();
306 nMaxWidth -= (IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2);
308 // for an image, get its size, create a suitable control and position it
309 aImageSize = maImage.GetSizePixel();
310 if ( aImageSize.Width() )
312 aImageSize.AdjustWidth(4 );
313 aImageSize.AdjustHeight(4 );
314 aTextPos.AdjustX(aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE );
315 mpFixedImage = VclPtr<FixedImage>::Create( this );
316 mpFixedImage->SetPosSizePixel( Point( IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_X,
317 IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_Y ),
318 aImageSize );
319 mpFixedImage->SetImage( maImage );
320 mpFixedImage->Show();
321 nMaxWidth -= aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE;
323 else
324 aTextPos.AdjustX(IMPL_MSGBOX_OFFSET_EXTRA_X );
326 // Determine maximum line length without wordbreak
327 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
328 nMaxLineWidth = aFormatRect.GetWidth();
329 nTextStyle |= DrawTextFlags::WordBreak;
331 // Determine the width for text formatting
332 if ( nMaxLineWidth > 450 )
333 nWidth = 450;
334 else if ( nMaxLineWidth > 300 )
335 nWidth = nMaxLineWidth+5;
336 else
337 nWidth = 300;
339 nWidth *= GetDPIScaleFactor();
341 if ( nButtonSize > nWidth )
342 nWidth = nButtonSize-(aTextPos.X()-IMPL_DIALOG_OFFSET);
343 if ( nWidth > nMaxWidth )
344 nWidth = nMaxWidth;
346 aRect.SetRight( nWidth );
347 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
348 if ( aTextInfo.GetMaxLineWidth() > nWidth )
350 nWidth = aTextInfo.GetMaxLineWidth()+8;
351 aRect.SetRight( nWidth );
352 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
355 // get Style for VCLMultiLineEdit
356 aMEditSize.setWidth( aTextInfo.GetMaxLineWidth()+1 );
357 aMEditSize.setHeight( aFormatRect.GetHeight() );
358 aPageSize.setWidth( aImageSize.Width() );
359 if ( aMEditSize.Height() < aImageSize.Height() )
361 nWinStyle |= WB_VCENTER;
362 aPageSize.setHeight( aImageSize.Height() );
363 aMEditSize.setHeight( aImageSize.Height() );
365 else
367 nWinStyle |= WB_TOP;
368 aPageSize.setHeight( aMEditSize.Height() );
370 if ( aImageSize.Width() )
371 aPageSize.AdjustWidth(IMPL_SEP_MSGBOX_IMAGE );
372 aPageSize.AdjustWidth((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2) );
373 aPageSize.AdjustWidth(aMEditSize.Width()+1 );
374 aPageSize.AdjustHeight((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_Y*2) );
376 if ( aPageSize.Width() < IMPL_MINSIZE_MSGBOX_WIDTH )
377 aPageSize.setWidth( IMPL_MINSIZE_MSGBOX_WIDTH );
378 if ( aPageSize.Width() < nTitleWidth )
379 aPageSize.setWidth( nTitleWidth );
381 mpVCLMultiLineEdit = VclPtr<VclMultiLineEdit>::Create( this, nWinStyle );
382 mpVCLMultiLineEdit->SetText( aMessText );
383 mpVCLMultiLineEdit->SetPosSizePixel( aTextPos, aMEditSize );
384 mpVCLMultiLineEdit->Show();
385 mpVCLMultiLineEdit->SetPaintTransparent(true);
386 mpVCLMultiLineEdit->EnableCursor(false);
387 SetPageSizePixel( aPageSize );
390 void MessBox::StateChanged( StateChangedType nType )
392 if ( nType == StateChangedType::InitShow )
394 ImplPosControls();
396 ButtonDialog::StateChanged( nType );
399 Size MessBox::GetOptimalSize() const
401 // FIXME: base me on the font size ?
402 return Size( 250, 100 );
406 namespace {
408 class Pause : public Idle
410 public:
411 explicit Pause(sal_Int32 nPauseMilliseconds) :
412 Idle("pause"),
413 m_nPauseMilliseconds(nPauseMilliseconds)
415 SetPriority(TaskPriority::HIGHEST);
416 Start();
419 virtual void Invoke() override
421 SolarMutexGuard aSolarGuard;
422 std::this_thread::sleep_for(std::chrono::milliseconds(m_nPauseMilliseconds));
423 Stop();
424 delete this;
427 sal_Int32 m_nPauseMilliseconds;
430 class VCLXToolkit : public comphelper::WeakComponentImplHelper<
431 css::awt::XToolkitExperimental,
432 css::awt::XToolkitRobot,
433 css::lang::XServiceInfo >
435 css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard;
436 css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxSelection;
438 ::comphelper::OInterfaceContainerHelper4<css::awt::XTopWindowListener> m_aTopWindowListeners;
439 ::comphelper::OInterfaceContainerHelper4<css::awt::XKeyHandler> m_aKeyHandlers;
440 ::comphelper::OInterfaceContainerHelper4<css::awt::XFocusListener> m_aFocusListeners;
441 ::Link<VclSimpleEvent&,void> m_aEventListenerLink;
442 ::Link<VclWindowEvent&,bool> m_aKeyListenerLink;
443 bool m_bEventListener;
444 bool m_bKeyListener;
446 DECL_LINK(eventListenerHandler, ::VclSimpleEvent&, void);
448 DECL_LINK(keyListenerHandler, ::VclWindowEvent&, bool);
450 void callTopWindowListeners(
451 ::VclSimpleEvent const * pEvent,
452 void (SAL_CALL css::awt::XTopWindowListener::* pFn)(
453 css::lang::EventObject const &));
455 bool callKeyHandlers(::VclSimpleEvent const * pEvent, bool bPressed);
457 void callFocusListeners(::VclSimpleEvent const * pEvent, bool bGained);
459 protected:
460 virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
462 static vcl::Window* ImplCreateWindow( rtl::Reference<VCLXWindow>* ppNewComp, const css::awt::WindowDescriptor& rDescriptor, vcl::Window* pParent,
463 WinBits nWinBits, MessBoxStyle nMessBoxStyle );
464 static css::uno::Reference< css::awt::XWindowPeer > ImplCreateWindow( const css::awt::WindowDescriptor& Descriptor,
465 MessBoxStyle nForceMessBoxStyle );
467 public:
469 VCLXToolkit();
471 // css::awt::XToolkitExperimental
472 virtual void SAL_CALL processEventsToIdle() override;
474 virtual sal_Int64 SAL_CALL getOpenGLBufferSwapCounter() override;
476 virtual void SAL_CALL setDeterministicScheduling(sal_Bool bDeterministicMode) override;
478 virtual void SAL_CALL pause(sal_Int32 nMilliseconds) override;
480 virtual void SAL_CALL startRecording() override;
482 virtual void SAL_CALL stopRecording() override;
484 css::uno::Sequence< OUString > SAL_CALL getRecordingAndClear() override;
486 virtual void SAL_CALL waitUntilAllIdlesDispatched() override;
488 // css::awt::XToolkit
489 css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getDesktopWindow( ) override;
490 css::awt::Rectangle SAL_CALL getWorkArea( ) override;
491 css::uno::Reference< css::awt::XWindowPeer > SAL_CALL createWindow( const css::awt::WindowDescriptor& Descriptor ) override;
492 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > SAL_CALL createWindows( const css::uno::Sequence< css::awt::WindowDescriptor >& Descriptors ) override;
493 css::uno::Reference< css::awt::XDevice > SAL_CALL createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) override;
494 css::uno::Reference< css::awt::XRegion > SAL_CALL createRegion( ) override;
496 // css::awt::XSystemChildFactory
497 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;
499 // css::awt::XMessageBoxFactory
500 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;
502 // css::awt::XDataTransfer
503 css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL getDragGestureRecognizer( const css::uno::Reference< css::awt::XWindow >& window ) override;
504 css::uno::Reference< css::datatransfer::dnd::XDragSource > SAL_CALL getDragSource( const css::uno::Reference< css::awt::XWindow >& window ) override;
505 css::uno::Reference< css::datatransfer::dnd::XDropTarget > SAL_CALL getDropTarget( const css::uno::Reference< css::awt::XWindow >& window ) override;
506 css::uno::Reference< css::datatransfer::clipboard::XClipboard > SAL_CALL getClipboard( const OUString& clipboardName ) override;
508 // css::lang::XServiceInfo
509 OUString SAL_CALL getImplementationName( ) override;
510 sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
511 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
513 // css::awt::XExtendedToolkit:
515 virtual ::sal_Int32 SAL_CALL getTopWindowCount() override;
517 virtual css::uno::Reference< css::awt::XTopWindow >
518 SAL_CALL getTopWindow(::sal_Int32 nIndex) override;
520 virtual css::uno::Reference< css::awt::XTopWindow >
521 SAL_CALL getActiveTopWindow() override;
523 virtual void SAL_CALL addTopWindowListener(
524 css::uno::Reference<
525 css::awt::XTopWindowListener > const & rListener) override;
527 virtual void SAL_CALL removeTopWindowListener(
528 css::uno::Reference<
529 css::awt::XTopWindowListener > const & rListener) override;
531 virtual void SAL_CALL addKeyHandler(
532 css::uno::Reference<
533 css::awt::XKeyHandler > const & rHandler) override;
535 virtual void SAL_CALL removeKeyHandler(
536 css::uno::Reference<
537 css::awt::XKeyHandler > const & rHandler) override;
539 virtual void SAL_CALL addFocusListener(
540 css::uno::Reference<
541 css::awt::XFocusListener > const & rListener) override;
543 virtual void SAL_CALL removeFocusListener(
544 css::uno::Reference<
545 css::awt::XFocusListener > const & rListener) override;
547 virtual void SAL_CALL fireFocusGained(
548 css::uno::Reference<
549 css::uno::XInterface > const & source) override;
551 virtual void SAL_CALL fireFocusLost(
552 css::uno::Reference<
553 css::uno::XInterface > const & source) override;
555 // css::awt::XReschedule:
556 virtual void SAL_CALL reschedule() override;
558 // css::awt::XFontMappingUse:
559 virtual void SAL_CALL startTrackingFontMappingUse() override;
561 virtual css::uno::Sequence<css::awt::XFontMappingUseItem> SAL_CALL finishTrackingFontMappingUse() override;
563 // css:awt:XToolkitRobot
564 virtual void SAL_CALL keyPress( const css::awt::KeyEvent & aKeyEvent ) override;
566 virtual void SAL_CALL keyRelease( const css::awt::KeyEvent & aKeyEvent ) override;
568 virtual void SAL_CALL mousePress( const css::awt::MouseEvent & aMouseEvent ) override;
570 virtual void SAL_CALL mouseRelease( const css::awt::MouseEvent & aMouseEvent ) override;
572 virtual void SAL_CALL mouseMove( const css::awt::MouseEvent & aMouseEvent ) override;
576 std::pair<WinBits,MessBoxStyle> ImplGetWinBits( sal_uInt32 nComponentAttribs, WindowType nCompType )
578 WinBits nWinBits = 0;
579 MessBoxStyle nStyle = MessBoxStyle::NONE;
581 bool bMessBox = false;
582 if ( ( nCompType == WindowType::INFOBOX ) ||
583 ( nCompType == WindowType::MESSBOX ) ||
584 ( nCompType == WindowType::QUERYBOX ) ||
585 ( nCompType == WindowType::WARNINGBOX ) ||
586 ( nCompType == WindowType::ERRORBOX ) )
588 bMessBox = true;
591 bool bDecoratedWindow = false;
592 if ( bMessBox
593 || ( nCompType == WindowType::DIALOG )
594 || ( nCompType == WindowType::MODELESSDIALOG )
595 || ( nCompType == WindowType::DOCKINGWINDOW )
596 || ( nCompType == WindowType::TABDIALOG )
597 || ( nCompType == WindowType::BUTTONDIALOG )
598 || ( nCompType == WindowType::SYSTEMCHILDWINDOW )
601 bDecoratedWindow = true;
604 if( nComponentAttribs & css::awt::WindowAttribute::BORDER )
605 nWinBits |= WB_BORDER;
606 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::NOBORDER )
607 nWinBits |= WB_NOBORDER;
608 if( nComponentAttribs & css::awt::WindowAttribute::SIZEABLE )
609 nWinBits |= WB_SIZEABLE;
610 if( nComponentAttribs & css::awt::WindowAttribute::MOVEABLE )
611 nWinBits |= WB_MOVEABLE;
612 if( nComponentAttribs & css::awt::WindowAttribute::CLOSEABLE )
613 nWinBits |= WB_CLOSEABLE;
614 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::HSCROLL )
615 nWinBits |= WB_HSCROLL;
616 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::VSCROLL )
617 nWinBits |= WB_VSCROLL;
618 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::LEFT )
619 nWinBits |= WB_LEFT;
620 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::CENTER )
621 nWinBits |= WB_CENTER;
622 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::RIGHT )
623 nWinBits |= WB_RIGHT;
624 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::SPIN )
625 nWinBits |= WB_SPIN;
626 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::SORT )
627 nWinBits |= WB_SORT;
628 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DROPDOWN )
629 nWinBits |= WB_DROPDOWN;
630 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEFBUTTON )
631 nWinBits |= WB_DEFBUTTON;
632 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::READONLY )
633 nWinBits |= WB_READONLY;
634 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::CLIPCHILDREN )
635 nWinBits |= WB_CLIPCHILDREN;
636 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::GROUP )
637 nWinBits |= WB_GROUP;
638 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::NOLABEL ) //added for issue79712
639 nWinBits |= WB_NOLABEL;
641 // These bits are not unique
642 if ( bMessBox )
644 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::OK )
645 nStyle |= MessBoxStyle::Ok;
646 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::OK_CANCEL )
647 nStyle |= MessBoxStyle::OkCancel;
648 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::YES_NO )
649 nStyle |= MessBoxStyle::YesNo;
650 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::YES_NO_CANCEL )
651 nStyle |= MessBoxStyle::YesNoCancel;
652 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::RETRY_CANCEL )
653 nStyle |= MessBoxStyle::RetryCancel;
654 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_OK )
655 nStyle |= MessBoxStyle::DefaultOk;
656 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_CANCEL )
657 nStyle |= MessBoxStyle::DefaultCancel;
658 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_RETRY )
659 nStyle |= MessBoxStyle::DefaultRetry;
660 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_YES )
661 nStyle |= MessBoxStyle::DefaultYes;
662 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_NO )
663 nStyle |= MessBoxStyle::DefaultNo;
665 if ( nCompType == WindowType::MULTILINEEDIT || nCompType == WindowType::DIALOG
666 || nCompType == WindowType::GROUPBOX || nCompType == WindowType::TABPAGE )
668 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::AUTOHSCROLL )
669 nWinBits |= WB_AUTOHSCROLL;
670 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::AUTOVSCROLL )
671 nWinBits |= WB_AUTOVSCROLL;
675 if ( bDecoratedWindow )
677 if( nComponentAttribs & css::awt::WindowAttribute::NODECORATION )
679 // No decoration removes several window attributes and must
680 // set WB_NOBORDER!
681 nWinBits &= ~WB_BORDER;
682 nWinBits &= ~WB_SIZEABLE;
683 nWinBits &= ~WB_MOVEABLE;
684 nWinBits &= ~WB_CLOSEABLE;
685 nWinBits |= WB_NOBORDER;
689 return { nWinBits, nStyle };
692 struct ComponentInfo
694 std::u16string_view sName;
695 WindowType nWinType;
698 ComponentInfo const aComponentInfos [] =
700 { std::u16string_view(u"animatedimages"), WindowType::CONTROL },
701 { std::u16string_view(u"buttondialog"), WindowType::BUTTONDIALOG },
702 { std::u16string_view(u"cancelbutton"), WindowType::CANCELBUTTON },
703 { std::u16string_view(u"checkbox"), WindowType::CHECKBOX },
704 { std::u16string_view(u"combobox"), WindowType::COMBOBOX },
705 { std::u16string_view(u"control"), WindowType::CONTROL },
706 { std::u16string_view(u"currencybox"), WindowType::CURRENCYBOX },
707 { std::u16string_view(u"currencyfield"), WindowType::CURRENCYFIELD },
708 { std::u16string_view(u"datebox"), WindowType::DATEBOX },
709 { std::u16string_view(u"datefield"), WindowType::CONTROL },
710 { std::u16string_view(u"dialog"), WindowType::DIALOG },
711 { std::u16string_view(u"dockingarea"), WindowType::DOCKINGAREA },
712 { std::u16string_view(u"dockingwindow"), WindowType::DOCKINGWINDOW },
713 { std::u16string_view(u"edit"), WindowType::EDIT },
714 { std::u16string_view(u"errorbox"), WindowType::ERRORBOX },
715 { std::u16string_view(u"filecontrol"), WindowType::CONTROL },
716 { std::u16string_view(u"fixedbitmap"), WindowType::FIXEDBITMAP },
717 { std::u16string_view(u"fixedhyperlink"), WindowType::CONTROL },
718 { std::u16string_view(u"fixedimage"), WindowType::FIXEDIMAGE },
719 { std::u16string_view(u"fixedline"), WindowType::FIXEDLINE },
720 { std::u16string_view(u"fixedtext"), WindowType::FIXEDTEXT },
721 { std::u16string_view(u"floatingwindow"), WindowType::FLOATINGWINDOW },
722 { std::u16string_view(u"formattedfield"), WindowType::CONTROL },
723 { std::u16string_view(u"frame"), WindowType::GROUPBOX },
724 { std::u16string_view(u"framewindow"), WindowType::TOOLKIT_FRAMEWINDOW },
725 { std::u16string_view(u"grid"), WindowType::CONTROL },
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 }
774 bool ComponentInfoFindCompare( const ComponentInfo & lhs, const OUString & s)
776 return rtl_ustr_compareIgnoreAsciiCase_WithLength(s.pData->buffer, s.pData->length,
777 lhs.sName.data(), lhs.sName.size()) > 0;
780 WindowType ImplGetComponentType( const OUString& rServiceName )
782 static bool bSorted = false;
783 if( !bSorted )
785 assert( std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos),
786 [](const ComponentInfo & lhs, const ComponentInfo & rhs) {
787 return
788 rtl_ustr_compare_WithLength(
789 lhs.sName.data(), lhs.sName.size(), rhs.sName.data(),
790 rhs.sName.size())
791 < 0;
792 } ) );
793 bSorted = true;
796 OUString sSearch;
797 if ( !rServiceName.isEmpty() )
798 sSearch = rServiceName;
799 else
800 sSearch = "window";
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;
810 struct MessageBoxTypeInfo
812 css::awt::MessageBoxType eType;
813 const char *pName;
814 sal_Int32 nLen;
817 const MessageBoxTypeInfo aMessageBoxTypeInfo[] =
819 { css::awt::MessageBoxType_MESSAGEBOX, RTL_CONSTASCII_STRINGPARAM("messbox") },
820 { css::awt::MessageBoxType_INFOBOX, RTL_CONSTASCII_STRINGPARAM("infobox") },
821 { css::awt::MessageBoxType_WARNINGBOX, RTL_CONSTASCII_STRINGPARAM("warningbox") },
822 { css::awt::MessageBoxType_ERRORBOX, RTL_CONSTASCII_STRINGPARAM("errorbox") },
823 { css::awt::MessageBoxType_QUERYBOX, RTL_CONSTASCII_STRINGPARAM("querybox") },
824 { css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE, nullptr, 0 }
827 bool lcl_convertMessageBoxType(
828 OUString &sType,
829 css::awt::MessageBoxType eType )
831 const MessageBoxTypeInfo *pMap = aMessageBoxTypeInfo;
832 css::awt::MessageBoxType eVal = css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE;
834 while ( pMap->pName )
836 if ( pMap->eType == eType )
838 eVal = eType;
839 sType = OUString( pMap->pName, pMap->nLen, RTL_TEXTENCODING_ASCII_US );
840 break;
842 pMap++;
845 return ( eVal != css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE );
848 #ifndef IOS
850 sal_Int32 nVCLToolkitInstanceCount = 0;
851 bool bInitedByVCLToolkit = false;
853 osl::Mutex & getInitMutex()
855 static osl::Mutex aMutex;
856 return aMutex;
859 osl::Condition & getInitCondition()
861 static osl::Condition aCondition;
862 return aCondition;
865 extern "C"
867 static void ToolkitWorkerFunction( void* pArgs )
869 osl_setThreadName("VCLXToolkit VCL main thread");
871 css::uno::Reference<css::lang::XMultiServiceFactory> xServiceManager;
874 xServiceManager = ::comphelper::getProcessServiceFactory();
876 catch (const css::uno::DeploymentException&)
879 if (!xServiceManager.is())
881 css::uno::Reference<css::uno::XComponentContext> xContext =
882 ::cppu::defaultBootstrap_InitialComponentContext();
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 );
889 VCLXToolkit * pTk = static_cast<VCLXToolkit *>(pArgs);
890 bInitedByVCLToolkit = !IsVCLInit() && InitVCL();
891 if( bInitedByVCLToolkit )
893 UnoWrapper* pUnoWrapper = new UnoWrapper( pTk );
894 UnoWrapperBase::SetUnoWrapper( pUnoWrapper );
896 getInitCondition().set();
897 if( bInitedByVCLToolkit )
900 SolarMutexGuard aGuard;
901 Application::Execute();
905 pTk->dispose();
907 catch( css::uno::Exception & )
910 DeInitVCL();
912 else
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.
920 #endif
922 // constructor, which might initialize VCL
923 VCLXToolkit::VCLXToolkit():
924 m_aEventListenerLink(LINK(this, VCLXToolkit, eventListenerHandler)),
925 m_aKeyListenerLink(LINK(this, VCLXToolkit, keyListenerHandler)),
926 m_bEventListener(false),
927 m_bKeyListener(false)
929 #ifndef IOS
930 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
931 nVCLToolkitInstanceCount++;
932 if( nVCLToolkitInstanceCount == 1 && !Application::IsInMain() &&
933 !comphelper::LibreOfficeKit::isActive() )
935 // setup execute thread
936 CreateMainLoopThread( ToolkitWorkerFunction, this );
937 getInitCondition().wait();
939 #endif
942 void VCLXToolkit::disposing(std::unique_lock<std::mutex>& rGuard)
944 #ifndef IOS
945 rGuard.unlock();
947 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
948 if( --nVCLToolkitInstanceCount == 0 )
950 if( bInitedByVCLToolkit )
952 Application::Quit();
953 JoinMainLoopThread();
954 bInitedByVCLToolkit = false;
958 rGuard.lock();
959 #endif
960 if (m_bEventListener)
962 ::Application::RemoveEventListener(m_aEventListenerLink);
963 m_bEventListener = false;
965 if (m_bKeyListener)
967 ::Application::RemoveKeyListener(m_aKeyListenerLink);
968 m_bKeyListener = false;
970 css::lang::EventObject aEvent(
971 getXWeak());
972 m_aTopWindowListeners.disposeAndClear(rGuard, aEvent);
973 m_aKeyHandlers.disposeAndClear(rGuard, aEvent);
974 m_aFocusListeners.disposeAndClear(rGuard, aEvent);
978 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::getDesktopWindow( )
980 css::uno::Reference< css::awt::XWindowPeer > xRef;
981 // 07/00: AppWindow doesn't exist anymore...
982 return xRef;
985 css::awt::Rectangle VCLXToolkit::getWorkArea( )
987 sal_Int32 nDisplay = Application::GetDisplayBuiltInScreen();
988 AbsoluteScreenPixelRectangle aWorkRect = Application::GetScreenPosSizePixel( nDisplay );
989 css::awt::Rectangle aNotherRect;
990 aNotherRect.X = aWorkRect.Left();
991 aNotherRect.Y = aWorkRect.Top();
992 aNotherRect.Width = aWorkRect.GetWidth();
993 aNotherRect.Height = aWorkRect.GetHeight();
994 return aNotherRect;
997 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::createWindow( const css::awt::WindowDescriptor& rDescriptor )
999 return ImplCreateWindow( rDescriptor, MessBoxStyle::NONE );
1002 css::uno::Reference< css::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height )
1004 rtl::Reference<VCLXVirtualDevice> pVDev = new VCLXVirtualDevice;
1006 SolarMutexGuard aSolarGuard;
1008 VclPtrInstance<VirtualDevice> pV;
1009 pV->SetOutputSizePixel( Size( Width, Height ) );
1010 pVDev->SetVirtualDevice( pV );
1012 return pVDev;
1015 css::uno::Reference< css::awt::XRegion > VCLXToolkit::createRegion( )
1017 css::uno::Reference< css::awt::XRegion > xRef = new VCLXRegion;
1018 return xRef;
1021 class InfoBox : public MessBox
1023 public:
1024 InfoBox(vcl::Window* pParent, const OUString& rMessage)
1025 : MessBox(pParent, MessBoxStyle::Ok | MessBoxStyle::DefaultOk, 0, OUString(), rMessage)
1027 // Default Text is the display title from the application
1028 if (GetText().isEmpty())
1029 SetText(GetStandardInfoBoxText());
1030 SetImage(GetStandardInfoBoxImage());
1034 class ErrorBox : public MessBox
1036 public:
1037 ErrorBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1038 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1040 // Default Text is the display title from the application
1041 if (GetText().isEmpty())
1042 SetText(GetStandardErrorBoxText());
1043 SetImage(GetStandardErrorBoxImage());
1047 class QueryBox : public MessBox
1049 public:
1050 QueryBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1051 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1053 // Default Text is the display title from the application
1054 if (GetText().isEmpty())
1055 SetText(GetStandardQueryBoxText());
1056 SetImage(GetStandardQueryBoxImage());
1060 class WarningBox : public MessBox
1062 public:
1063 WarningBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1064 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1066 // Default Text is the display title from the application
1067 if (GetText().isEmpty())
1068 SetText(GetStandardWarningBoxText());
1069 SetImage(GetStandardWarningBoxImage());
1074 struct RMItemData
1076 bool b_Enabled;
1077 sal_Int32 n_ID;
1078 OUString Label;
1081 typedef ::cppu::ImplInheritanceHelper < VCLXGraphicControl
1082 , css::container::XContainerListener
1083 , css::beans::XPropertyChangeListener
1084 , css::awt::XItemEventBroadcaster
1085 > SVTXRoadmap_Base;
1086 class SVTXRoadmap final : public SVTXRoadmap_Base
1088 public:
1089 SVTXRoadmap();
1091 void SAL_CALL disposing( const css::lang::EventObject& Source ) override { VCLXWindow::disposing( Source ); }
1093 // css::awt::XVclWindowPeer
1094 void SAL_CALL setProperty( const OUString& PropertyName, const css::uno::Any& Value ) override;
1096 css::uno::Any SAL_CALL getProperty( const OUString& PropertyName ) override;
1098 // XContainerListener
1099 void SAL_CALL elementInserted( const css::container::ContainerEvent& rEvent ) override;
1100 void SAL_CALL elementRemoved( const css::container::ContainerEvent& rEvent ) override;
1101 void SAL_CALL elementReplaced( const css::container::ContainerEvent& rEvent ) override;
1103 // XItemEventBroadcaster
1104 virtual void SAL_CALL addItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) override;
1105 virtual void SAL_CALL removeItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) override;
1107 // XPropertyChangeListener
1108 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
1110 private:
1112 // VCLXGraphicControl overridables
1113 virtual void ImplSetNewImage() override;
1115 static void ImplGetPropertyIds( std::vector< sal_uInt16 > &aIds );
1116 virtual void GetPropertyIds( std::vector< sal_uInt16 > &aIds ) override { return ImplGetPropertyIds( aIds ); }
1118 static RMItemData GetRMItemData( const css::container::ContainerEvent& _rEvent );
1120 virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) override;
1122 virtual ~SVTXRoadmap() override;
1124 ItemListenerMultiplexer maItemListeners;
1130 SVTXRoadmap::SVTXRoadmap() : maItemListeners( *this )
1134 SVTXRoadmap::~SVTXRoadmap()
1138 void SVTXRoadmap::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
1140 switch ( rVclWindowEvent.GetId() )
1142 case VclEventId::RoadmapItemSelected:
1144 SolarMutexGuard aGuard;
1145 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1146 if ( pField )
1148 sal_Int16 CurItemID = pField->GetCurrentRoadmapItemID();
1149 css::awt::ItemEvent aEvent;
1150 aEvent.Selected = CurItemID;
1151 aEvent.Highlighted = CurItemID;
1152 aEvent.ItemId = CurItemID;
1153 maItemListeners.itemStateChanged( aEvent );
1156 break;
1157 default:
1158 SVTXRoadmap_Base::ProcessWindowEvent( rVclWindowEvent );
1159 break;
1163 void SVTXRoadmap::propertyChange( const css::beans::PropertyChangeEvent& evt )
1165 SolarMutexGuard aGuard;
1166 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1167 if ( !pField )
1168 return;
1170 css::uno::Reference< css::uno::XInterface > xRoadmapItem = evt.Source;
1171 sal_Int32 nID = 0;
1172 css::uno::Reference< css::beans::XPropertySet > xPropertySet( xRoadmapItem, css::uno::UNO_QUERY );
1173 css::uno::Any aValue = xPropertySet->getPropertyValue(u"ID"_ustr);
1174 aValue >>= nID;
1176 OUString sPropertyName = evt.PropertyName;
1177 if ( sPropertyName == "Enabled" )
1179 bool bEnable = false;
1180 evt.NewValue >>= bEnable;
1181 pField->EnableRoadmapItem( static_cast<vcl::RoadmapTypes::ItemId>(nID) , bEnable );
1183 else if ( sPropertyName == "Label" )
1185 OUString sLabel;
1186 evt.NewValue >>= sLabel;
1187 pField->ChangeRoadmapItemLabel( static_cast<vcl::RoadmapTypes::ItemId>(nID) , sLabel );
1189 else if ( sPropertyName == "ID" )
1191 sal_Int32 nNewID = 0;
1192 evt.NewValue >>= nNewID;
1193 evt.OldValue >>= nID;
1194 pField->ChangeRoadmapItemID( static_cast<vcl::RoadmapTypes::ItemId>(nID), static_cast<vcl::RoadmapTypes::ItemId>(nNewID) );
1196 // else
1197 // TODO handle Interactive appropriately
1200 void SVTXRoadmap::addItemListener( const css::uno::Reference< css::awt::XItemListener >& l )
1202 maItemListeners.addInterface( l );
1205 void SVTXRoadmap::removeItemListener( const css::uno::Reference< css::awt::XItemListener >& l )
1207 maItemListeners.removeInterface( l );
1210 RMItemData SVTXRoadmap::GetRMItemData( const css::container::ContainerEvent& _rEvent )
1212 RMItemData aCurRMItemData;
1213 css::uno::Reference< css::uno::XInterface > xRoadmapItem;
1214 _rEvent.Element >>= xRoadmapItem;
1215 css::uno::Reference< css::beans::XPropertySet > xPropertySet( xRoadmapItem, css::uno::UNO_QUERY );
1216 if ( xPropertySet.is() )
1218 css::uno::Any aValue = xPropertySet->getPropertyValue(u"Label"_ustr);
1219 aValue >>= aCurRMItemData.Label;
1220 aValue = xPropertySet->getPropertyValue(u"ID"_ustr);
1221 aValue >>= aCurRMItemData.n_ID;
1222 aValue = xPropertySet->getPropertyValue(u"Enabled"_ustr);
1223 aValue >>= aCurRMItemData.b_Enabled;
1225 else
1227 aCurRMItemData.b_Enabled = false;
1228 aCurRMItemData.n_ID = 0;
1230 return aCurRMItemData;
1233 void SVTXRoadmap::elementInserted( const css::container::ContainerEvent& _rEvent )
1235 SolarMutexGuard aGuard;
1236 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1237 if ( pField )
1239 RMItemData CurItemData = GetRMItemData( _rEvent );
1240 sal_Int32 InsertIndex = 0;
1241 _rEvent.Accessor >>= InsertIndex;
1242 pField->InsertRoadmapItem( InsertIndex, CurItemData.Label, static_cast<vcl::RoadmapTypes::ItemId>(CurItemData.n_ID), CurItemData.b_Enabled );
1246 void SVTXRoadmap::elementRemoved( const css::container::ContainerEvent& _rEvent )
1248 SolarMutexGuard aGuard;
1249 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1250 if ( pField )
1252 sal_Int32 DelIndex = 0;
1253 _rEvent.Accessor >>= DelIndex;
1254 pField->DeleteRoadmapItem(DelIndex);
1258 void SVTXRoadmap::elementReplaced( const css::container::ContainerEvent& _rEvent )
1260 SolarMutexGuard aGuard;
1261 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1262 if ( pField )
1264 RMItemData CurItemData = GetRMItemData( _rEvent );
1265 sal_Int32 ReplaceIndex = 0;
1266 _rEvent.Accessor >>= ReplaceIndex;
1267 pField->ReplaceRoadmapItem( ReplaceIndex, CurItemData.Label, static_cast<vcl::RoadmapTypes::ItemId>(CurItemData.n_ID), CurItemData.b_Enabled );
1271 void SVTXRoadmap::setProperty( const OUString& PropertyName, const css::uno::Any& Value)
1273 SolarMutexGuard aGuard;
1275 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1276 if ( pField )
1278 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1279 switch (nPropType)
1281 case BASEPROPERTY_COMPLETE:
1283 bool b = false;
1284 Value >>= b;
1285 pField->SetRoadmapComplete( b);
1287 break;
1289 case BASEPROPERTY_ACTIVATED:
1291 bool b = false;
1292 Value >>= b;
1293 pField->SetRoadmapInteractive( b);
1295 break;
1297 case BASEPROPERTY_CURRENTITEMID:
1299 sal_Int32 nId = 0;
1300 Value >>= nId;
1301 pField->SelectRoadmapItemByID( static_cast<vcl::RoadmapTypes::ItemId>(nId) );
1303 break;
1305 case BASEPROPERTY_TEXT:
1307 OUString aStr;
1308 Value >>= aStr;
1309 pField->SetText( aStr );
1310 pField->Invalidate();
1312 break;
1314 default:
1315 SVTXRoadmap_Base::setProperty( PropertyName, Value );
1316 break;
1320 else
1321 SVTXRoadmap_Base::setProperty( PropertyName, Value );
1325 css::uno::Any SVTXRoadmap::getProperty( const OUString& PropertyName )
1327 SolarMutexGuard aGuard;
1329 css::uno::Any aReturn;
1331 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1332 if ( pField )
1334 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1335 switch (nPropType)
1337 case BASEPROPERTY_COMPLETE:
1338 aReturn <<= pField->IsRoadmapComplete();
1339 break;
1340 case BASEPROPERTY_ACTIVATED:
1341 aReturn <<= pField->IsRoadmapInteractive();
1342 break;
1343 case BASEPROPERTY_CURRENTITEMID:
1344 aReturn <<= pField->GetCurrentRoadmapItemID();
1345 break;
1346 default:
1347 aReturn = SVTXRoadmap_Base::getProperty(PropertyName);
1348 break;
1351 return aReturn;
1354 void SVTXRoadmap::ImplSetNewImage()
1356 OSL_PRECOND( GetWindow(), "SVTXRoadmap::ImplSetNewImage: window is required to be not-NULL!" );
1357 VclPtr< ::vcl::ORoadmap > pButton = GetAs< ::vcl::ORoadmap >();
1358 pButton->SetRoadmapBitmap( GetImage().GetBitmapEx() );
1361 void SVTXRoadmap::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds )
1363 PushPropertyIds( rIds,
1364 BASEPROPERTY_COMPLETE,
1365 BASEPROPERTY_ACTIVATED,
1366 BASEPROPERTY_CURRENTITEMID,
1367 BASEPROPERTY_TEXT,
1369 VCLXWindow::ImplGetPropertyIds( rIds, true );
1370 VCLXGraphicControl::ImplGetPropertyIds( rIds );
1373 vcl::Window* VCLXToolkit::ImplCreateWindow( rtl::Reference<VCLXWindow>* ppNewComp,
1374 const css::awt::WindowDescriptor& rDescriptor,
1375 vcl::Window* pParent, WinBits nWinBits, MessBoxStyle nMessBoxStyle )
1377 OUString aServiceName = rDescriptor.WindowServiceName.toAsciiLowerCase();
1379 VclPtr<vcl::Window> pNewWindow;
1380 WindowType nType = ImplGetComponentType( aServiceName );
1381 bool bFrameControl = false;
1382 if ( aServiceName == "frame" )
1383 bFrameControl = true;
1384 if ( aServiceName == "tabcontrolnotabs" )
1386 nWinBits |= WB_NOBORDER;
1387 nType = ImplGetComponentType( u"tabcontrol"_ustr );
1389 if ( !pParent )
1391 // If the component needs a parent, then return NULL,
1392 // some time later css::uno::Exception...
1393 bool bException = true;
1394 if ( ( nType == WindowType::DIALOG )
1395 || ( nType == WindowType::MODELESSDIALOG )
1396 || ( nType == WindowType::MESSBOX )
1397 || ( nType == WindowType::INFOBOX )
1398 || ( nType == WindowType::WARNINGBOX )
1399 || ( nType == WindowType::ERRORBOX )
1400 || ( nType == WindowType::QUERYBOX )
1402 bException = false;
1403 else if ( ( nType == WindowType::WINDOW ) ||
1404 ( nType == WindowType::WORKWINDOW ) ||
1405 ( nType == WindowType::TOOLKIT_FRAMEWINDOW ) )
1407 if ( rDescriptor.Type == css::awt::WindowClass_TOP )
1408 bException = false;
1411 if ( bException )
1413 *ppNewComp = nullptr;
1414 return nullptr;
1418 if ( nType != WindowType::NONE )
1420 SolarMutexGuard aVclGuard;
1421 switch ( nType )
1423 case WindowType::CANCELBUTTON:
1424 pNewWindow = VclPtr<CancelButton>::Create( pParent, nWinBits );
1425 *ppNewComp = new VCLXButton;
1426 break;
1427 case WindowType::CHECKBOX:
1428 pNewWindow = VclPtr<CheckBox>::Create( pParent, nWinBits );
1429 *ppNewComp = new VCLXCheckBox;
1430 break;
1431 case WindowType::COMBOBOX:
1432 pNewWindow = VclPtr<ComboBox>::Create( pParent, nWinBits|WB_AUTOHSCROLL );
1433 static_cast<ComboBox*>(pNewWindow.get())->EnableAutoSize( false );
1434 *ppNewComp = new VCLXComboBox;
1435 break;
1436 case WindowType::CURRENCYBOX:
1437 pNewWindow = VclPtr<CurrencyBox>::Create( pParent, nWinBits );
1438 break;
1439 case WindowType::CURRENCYFIELD:
1440 pNewWindow = VclPtr<CurrencyField>::Create( pParent, nWinBits );
1441 static_cast<CurrencyField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1442 *ppNewComp = new VCLXNumericField;
1443 static_cast<VCLXFormattedSpinField*>((*ppNewComp).get())->SetFormatter( static_cast<FormatterBase*>(static_cast<CurrencyField*>(pNewWindow.get())) );
1444 break;
1445 case WindowType::DATEBOX:
1446 pNewWindow = VclPtr<DateBox>::Create( pParent, nWinBits );
1447 break;
1448 case WindowType::DOCKINGAREA:
1449 pNewWindow = VclPtr<DockingAreaWindow>::Create( pParent );
1450 break;
1451 case WindowType::MULTILINEEDIT:
1452 pNewWindow = VclPtr<MultiLineEdit>::Create(pParent, nWinBits|WB_IGNORETAB);
1453 static_cast<MultiLineEdit*>(pNewWindow.get())->DisableSelectionOnFocus();
1454 *ppNewComp = new VCLXMultiLineEdit;
1455 break;
1456 case WindowType::EDIT:
1457 pNewWindow = VclPtr<Edit>::Create( pParent, nWinBits );
1458 *ppNewComp = new VCLXEdit;
1459 break;
1460 case WindowType::ERRORBOX:
1461 pNewWindow = VclPtr<ErrorBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1462 *ppNewComp = new VCLXMessageBox;
1463 break;
1464 case WindowType::FIXEDBITMAP:
1465 pNewWindow = VclPtr<FixedBitmap>::Create( pParent, nWinBits );
1466 break;
1467 case WindowType::FIXEDIMAGE:
1468 pNewWindow = VclPtr<ImageControl>::Create( pParent, nWinBits );
1469 *ppNewComp = new VCLXImageControl;
1470 break;
1471 case WindowType::FIXEDLINE:
1472 pNewWindow = VclPtr<FixedLine>::Create( pParent, nWinBits );
1473 break;
1474 case WindowType::FIXEDTEXT:
1475 pNewWindow = VclPtr<FixedText>::Create( pParent, nWinBits );
1476 *ppNewComp = new VCLXFixedText;
1477 break;
1478 case WindowType::FLOATINGWINDOW:
1479 pNewWindow = VclPtr<FloatingWindow>::Create( pParent, nWinBits );
1480 break;
1481 case WindowType::GROUPBOX:
1482 pNewWindow = VclPtr<GroupBox>::Create( pParent, nWinBits );
1483 if ( bFrameControl )
1485 GroupBox* pGroupBox = static_cast< GroupBox* >( pNewWindow.get() );
1486 *ppNewComp = new VCLXFrame;
1487 // Frame control needs to receive
1488 // Mouse events
1489 pGroupBox->SetMouseTransparent( false );
1491 break;
1492 case WindowType::HELPBUTTON:
1493 pNewWindow = VclPtr<HelpButton>::Create( pParent, nWinBits );
1494 *ppNewComp = new VCLXButton;
1495 break;
1496 case WindowType::IMAGEBUTTON:
1497 pNewWindow = VclPtr<ImageButton>::Create( pParent, nWinBits );
1498 *ppNewComp = new VCLXButton;
1499 break;
1500 case WindowType::INFOBOX:
1501 pNewWindow = VclPtr<InfoBox>::Create( pParent, OUString() );
1502 *ppNewComp = new VCLXMessageBox;
1503 break;
1504 case WindowType::LISTBOX:
1505 pNewWindow = VclPtr<ListBox>::Create( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL );
1506 static_cast<ListBox*>(pNewWindow.get())->EnableAutoSize( false );
1507 *ppNewComp = new VCLXListBox;
1508 break;
1509 case WindowType::LONGCURRENCYBOX:
1510 pNewWindow = VclPtr<LongCurrencyBox>::Create( pParent, nWinBits );
1511 break;
1512 case WindowType::MENUBUTTON:
1513 pNewWindow = VclPtr<MenuButton>::Create( pParent, nWinBits );
1514 *ppNewComp = new VCLXButton;
1515 break;
1516 case WindowType::MESSBOX:
1517 pNewWindow = VclPtr<MessBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString(), OUString() );
1518 *ppNewComp = new VCLXMessageBox;
1519 break;
1520 case WindowType::METRICBOX:
1521 pNewWindow = VclPtr<MetricBox>::Create( pParent, nWinBits );
1522 break;
1523 case WindowType::METRICFIELD:
1524 pNewWindow = VclPtr<MetricField>::Create( pParent, nWinBits );
1525 *ppNewComp = new VCLXMetricField;
1526 static_cast<VCLXFormattedSpinField*>((*ppNewComp).get())->SetFormatter( static_cast<FormatterBase*>(static_cast<MetricField*>(pNewWindow.get())) );
1527 break;
1528 case WindowType::DIALOG:
1529 case WindowType::MODELESSDIALOG:
1531 // Modal/Modeless only via Show/Execute
1532 if ( (pParent == nullptr ) && ( rDescriptor.ParentIndex == -1 ) )
1533 pNewWindow = VclPtr<toolkit::ScrollableDialog>::Create( nullptr, nWinBits, Dialog::InitFlag::NoParent );
1534 else
1535 pNewWindow = VclPtr<toolkit::ScrollableDialog>::Create( pParent, nWinBits );
1536 // #i70217# Don't always create a new component object. It's possible that VCL has called
1537 // GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() )
1538 // which creates a component object.
1539 css::uno::Reference< css::awt::XWindowPeer > xWinPeer = pNewWindow->GetComponentInterface( false );
1540 if ( xWinPeer.is() )
1541 *ppNewComp = dynamic_cast< VCLXDialog* >( xWinPeer.get() );
1542 else
1543 *ppNewComp = new VCLXDialog;
1545 break;
1546 case WindowType::MOREBUTTON:
1547 pNewWindow = VclPtr<MoreButton>::Create( pParent, nWinBits );
1548 *ppNewComp = new VCLXButton;
1549 break;
1550 case WindowType::MULTILISTBOX:
1551 pNewWindow = VclPtr<MultiListBox>::Create( pParent, nWinBits );
1552 *ppNewComp = new VCLXListBox;
1553 break;
1554 case WindowType::NUMERICBOX:
1555 pNewWindow = VclPtr<NumericBox>::Create( pParent, nWinBits );
1556 break;
1557 case WindowType::OKBUTTON:
1558 pNewWindow = VclPtr<OKButton>::Create( pParent, nWinBits );
1559 *ppNewComp = new VCLXButton;
1560 break;
1561 case WindowType::PATTERNBOX:
1562 pNewWindow = VclPtr<PatternBox>::Create( pParent, nWinBits );
1563 break;
1564 case WindowType::PATTERNFIELD:
1565 pNewWindow = VclPtr<PatternField>::Create( pParent, nWinBits );
1566 *ppNewComp = new VCLXPatternField;
1567 static_cast<VCLXFormattedSpinField*>((*ppNewComp).get())->SetFormatter( static_cast<FormatterBase*>(static_cast<PatternField*>(pNewWindow.get())) );
1568 break;
1569 case WindowType::PUSHBUTTON:
1570 pNewWindow = VclPtr<PushButton>::Create( pParent, nWinBits );
1571 *ppNewComp = new VCLXButton;
1572 break;
1573 case WindowType::QUERYBOX:
1574 pNewWindow = VclPtr<QueryBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1575 *ppNewComp = new VCLXMessageBox;
1576 break;
1577 case WindowType::RADIOBUTTON:
1578 pNewWindow = VclPtr<RadioButton>::Create(pParent, false, nWinBits);
1579 *ppNewComp = new VCLXRadioButton;
1581 // by default, disable RadioCheck
1582 // Since the VCLXRadioButton really cares for its RadioCheck settings, this is important:
1583 // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState
1584 // This leads to a strange behaviour if the control is newly created: when settings the initial
1585 // state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck
1586 // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls
1587 // is not really valid: the controls are grouped after they have been created, but we're still in
1588 // the creation process, so the RadioButton::Check relies on invalid grouping information.
1589 // 07.08.2001 - #87254# - frank.schoenheit@sun.com
1590 static_cast<RadioButton*>(pNewWindow.get())->EnableRadioCheck( false );
1591 break;
1592 case WindowType::SCROLLBAR:
1593 pNewWindow = VclPtr<ScrollBar>::Create( pParent, nWinBits );
1594 *ppNewComp = new VCLXScrollBar;
1595 break;
1596 case WindowType::SCROLLBARBOX:
1597 pNewWindow = VclPtr<ScrollBarBox>::Create( pParent, nWinBits );
1598 break;
1599 case WindowType::SPINBUTTON:
1600 pNewWindow = VclPtr<SpinButton>::Create( pParent, nWinBits );
1601 *ppNewComp = new ::toolkit::VCLXSpinButton;
1602 break;
1603 case WindowType::SPINFIELD:
1604 pNewWindow = VclPtr<SpinField>::Create( pParent, nWinBits );
1605 *ppNewComp = new VCLXNumericField;
1606 break;
1607 case WindowType::SPLITTER:
1608 pNewWindow = VclPtr<Splitter>::Create( pParent, nWinBits );
1609 break;
1610 case WindowType::SPLITWINDOW:
1611 pNewWindow = VclPtr<SplitWindow>::Create( pParent, nWinBits );
1612 break;
1613 case WindowType::STATUSBAR:
1614 pNewWindow = VclPtr<StatusBar>::Create( pParent, nWinBits );
1615 break;
1616 case WindowType::TOOLKIT_SYSTEMCHILDWINDOW:
1617 pNewWindow = VclPtr<SystemChildWindow>::Create( pParent, nWinBits );
1618 *ppNewComp = new VCLXSystemDependentWindow();
1619 break;
1620 case WindowType::TABCONTROL:
1621 pNewWindow = VclPtr<TabControl>::Create( pParent, nWinBits );
1622 *ppNewComp = new VCLXMultiPage;
1623 break;
1624 case WindowType::TABDIALOG:
1625 pNewWindow = VclPtr<TabDialog>::Create( pParent, nWinBits );
1626 break;
1627 case WindowType::TABPAGE:
1629 pNewWindow = VclPtr<TabPage>::Create( pParent, nWinBits );
1630 *ppNewComp = new VCLXTabPage;
1632 break;
1633 case WindowType::TIMEBOX:
1634 pNewWindow = VclPtr<TimeBox>::Create( pParent, nWinBits );
1635 break;
1636 case WindowType::TIMEFIELD:
1637 pNewWindow = VclPtr<TimeField>::Create( pParent, nWinBits );
1638 static_cast<TimeField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1639 *ppNewComp = new VCLXTimeField;
1640 static_cast<VCLXFormattedSpinField*>((*ppNewComp).get())->SetFormatter( static_cast<FormatterBase*>(static_cast<TimeField*>(pNewWindow.get())) );
1641 break;
1642 case WindowType::TOOLBOX:
1643 pNewWindow = VclPtr<ToolBox>::Create( pParent, nWinBits );
1644 *ppNewComp = new VCLXToolBox;
1645 break;
1646 case WindowType::TRISTATEBOX:
1647 pNewWindow = VclPtr<CheckBox>::Create( pParent, nWinBits );
1648 static_cast<CheckBox*>(pNewWindow.get())->EnableTriState(true);
1649 break;
1650 case WindowType::WARNINGBOX:
1651 pNewWindow = VclPtr<WarningBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1652 *ppNewComp = new VCLXMessageBox;
1653 break;
1654 case WindowType::WORKWINDOW:
1655 case WindowType::WINDOW:
1656 case WindowType::TOOLKIT_FRAMEWINDOW:
1657 case WindowType::DOCKINGWINDOW:
1658 if ( rDescriptor.Type == css::awt::WindowClass_TOP )
1660 if (nType == WindowType::DOCKINGWINDOW )
1661 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1662 else
1664 if ((pParent == nullptr) && rDescriptor.Parent.is())
1666 // try to get a system dependent window handle
1667 css::uno::Reference< css::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, css::uno::UNO_QUERY);
1669 if (xSystemDepParent.is())
1671 sal_Int8 processID[16];
1673 rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8*>(processID) );
1675 // coverity[overrun-buffer-arg : FALSE] - coverity has difficulty with css::uno::Sequence
1676 css::uno::Sequence<sal_Int8> processIdSeq(processID, 16);
1678 css::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPE);
1680 // use sal_Int64 here to accommodate all int types
1681 // uno::Any shift operator will upcast if necessary
1682 sal_Int64 nWindowHandle = 0;
1683 bool bXEmbed = false;
1685 bool bUseParentData = true;
1686 if( ! (anyHandle >>= nWindowHandle) )
1688 css::uno::Sequence< css::beans::NamedValue > aProps;
1689 if( anyHandle >>= aProps )
1691 for (const css::beans::NamedValue& rProp : aProps)
1693 if ( rProp.Name == "WINDOW" )
1694 rProp.Value >>= nWindowHandle;
1695 else if ( rProp.Name == "XEMBED" )
1696 rProp.Value >>= bXEmbed;
1699 else
1700 bUseParentData = false;
1703 if( bUseParentData )
1705 SystemParentData aParentData;
1706 aParentData.nSize = sizeof( aParentData );
1707 #if defined MACOSX
1708 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
1709 #elif defined ANDROID
1710 // Nothing
1711 #elif defined IOS
1712 // Nothing
1713 #elif defined UNX
1714 aParentData.aWindow = nWindowHandle;
1715 aParentData.bXEmbedSupport = bXEmbed;
1716 #elif defined _WIN32
1717 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1718 #endif
1719 pNewWindow = VclPtr<WorkWindow>::Create( &aParentData );
1724 if (!pNewWindow)
1725 pNewWindow = VclPtr<WorkWindow>::Create( pParent, nWinBits );
1728 *ppNewComp = new VCLXTopWindow();
1730 else if ( rDescriptor.Type == css::awt::WindowClass_CONTAINER )
1732 if (nType == WindowType::DOCKINGWINDOW )
1733 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1734 else
1735 pNewWindow = VclPtr<vcl::Window>::Create( pParent, nWinBits );
1736 *ppNewComp = new VCLXContainer;
1738 else
1740 if (nType == WindowType::DOCKINGWINDOW )
1741 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1742 else
1743 pNewWindow = VclPtr<vcl::Window>::Create( pParent, nWinBits );
1744 *ppNewComp = new VCLXWindow;
1746 break;
1747 case WindowType::CONTROL:
1748 if ( aServiceName == "tabpagecontainer" )
1750 // TabControl has a special case for tabs without border: they are displayed
1751 // in a different way, so we need to ensure that this style is not set, so
1752 // we can guarantee normal tab behavior
1753 pNewWindow = VclPtr<TabControl>::Create( pParent, nWinBits & (~WB_NOBORDER));
1754 *ppNewComp = new VCLXTabPageContainer;
1756 else if ( aServiceName == "animatedimages" )
1758 pNewWindow = VclPtr<Throbber>::Create( pParent, nWinBits );
1759 *ppNewComp = new ::toolkit::AnimatedImagesPeer;
1761 else if (aServiceName == "roadmap")
1763 pNewWindow = VclPtr<::vcl::ORoadmap>::Create( pParent, WB_TABSTOP );
1764 *ppNewComp = new SVTXRoadmap;
1766 else if (aServiceName == "fixedhyperlink")
1768 pNewWindow = VclPtr<FixedHyperlink>::Create( pParent, nWinBits );
1769 *ppNewComp = new VCLXFixedHyperlink;
1771 else if (aServiceName == "progressbar")
1773 pNewWindow = VclPtr<ProgressBar>::Create( pParent, nWinBits, ProgressBar::BarStyle::Progress );
1774 *ppNewComp = new VCLXProgressBar;
1776 else if (aServiceName == "filecontrol")
1778 pNewWindow = VclPtr<FileControl>::Create( pParent, nWinBits );
1779 *ppNewComp = new VCLXFileControl;
1781 else if (aServiceName == "tree")
1783 rtl::Reference<TreeControlPeer> pPeer = new TreeControlPeer;
1784 *ppNewComp = pPeer;
1785 pNewWindow = pPeer->createVclControl( pParent, nWinBits );
1787 else if (aServiceName == "formattedfield")
1789 pNewWindow = VclPtr<FormattedField>::Create( pParent, nWinBits );
1790 *ppNewComp = new SVTXFormattedField;
1792 else if (aServiceName == "numericfield")
1794 pNewWindow = VclPtr<DoubleNumericField>::Create( pParent, nWinBits );
1795 *ppNewComp = new SVTXNumericField;
1797 else if (aServiceName == "longcurrencyfield")
1799 pNewWindow = VclPtr<DoubleCurrencyField>::Create( pParent, nWinBits );
1800 *ppNewComp = new SVTXCurrencyField;
1802 else if (aServiceName == "datefield")
1804 pNewWindow = VclPtr<CalendarField>::Create(pParent, nWinBits);
1805 static_cast<CalendarField*>(pNewWindow.get())->EnableToday();
1806 static_cast<CalendarField*>(pNewWindow.get())->EnableNone();
1807 static_cast<CalendarField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1808 rtl::Reference<SVTXDateField> newComp = new SVTXDateField;
1809 *ppNewComp = newComp;
1810 newComp->SetFormatter( static_cast<FormatterBase*>(static_cast<DateField*>(pNewWindow.get())) );
1812 else if (aServiceName == "grid")
1814 pNewWindow = VclPtr<::svt::table::TableControl>::Create(pParent, nWinBits);
1815 *ppNewComp = new SVTXGridControl;
1817 break;
1818 default:
1819 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" );
1820 break;
1824 // tdf#126717 default that formcontrols show accelerators
1825 if (Control* pControl = dynamic_cast<Control*>(pNewWindow.get()))
1826 pControl->SetShowAccelerator(true);
1827 return pNewWindow;
1830 // static
1831 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow(
1832 const css::awt::WindowDescriptor& rDescriptor,
1833 MessBoxStyle nForceMessBoxStyle )
1835 SolarMutexGuard aSolarGuard;
1837 css::uno::Reference< css::awt::XVclWindowPeer > xRef;
1839 VclPtr<vcl::Window> pParent;
1840 if ( rDescriptor.Parent.is() )
1842 VCLXWindow* pParentComponent = dynamic_cast<VCLXWindow*>( rDescriptor.Parent.get() );
1844 // #103939# Don't throw assertion, may be it's a system dependent window, used in ImplCreateWindow.
1845 // DBG_ASSERT( pParentComponent, "ParentComponent not valid" );
1847 if ( pParentComponent )
1848 pParent = pParentComponent->GetWindow();
1850 std::pair<WinBits, MessBoxStyle> aPair = ImplGetWinBits( rDescriptor.WindowAttributes,
1851 ImplGetComponentType( rDescriptor.WindowServiceName ) );
1852 WinBits nWinBits = aPair.first;
1853 aPair.second |= nForceMessBoxStyle;
1855 rtl::Reference<VCLXWindow> pNewComp;
1857 vcl::Window* pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits, aPair.second );
1859 DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" );
1860 SAL_INFO_IF( !pNewComp, "toolkit", "createWindow: No special Interface!" );
1862 if ( pNewWindow )
1864 pNewWindow->SetCreatedWithToolkit( true );
1865 //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead
1867 if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::MINSIZE )
1869 pNewWindow->SetSizePixel( Size() );
1871 else if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::FULLSIZE )
1873 if ( pParent )
1874 pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() );
1876 else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) )
1878 tools::Rectangle aRect = vcl::unohelper::ConvertToVCLRect(rDescriptor.Bounds);
1879 pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
1882 if ( !pNewComp )
1884 // Default-Interface
1885 xRef = pNewWindow->GetComponentInterface();
1887 else
1889 xRef = pNewComp;
1890 pNewWindow->SetComponentInterface( xRef );
1892 DBG_ASSERT( pNewWindow->GetComponentInterface( false ) == xRef,
1893 "VCLXToolkit::createWindow: did #133706# resurge?" );
1895 if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::SHOW )
1896 pNewWindow->Show();
1899 return xRef;
1902 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > VCLXToolkit::createWindows( const css::uno::Sequence< css::awt::WindowDescriptor >& rDescriptors )
1904 sal_uInt32 nComponents = rDescriptors.getLength();
1905 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > aSeq( nComponents );
1906 for ( sal_uInt32 n = 0; n < nComponents; n++ )
1908 css::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n];
1910 if ( aDescr.ParentIndex == -1 )
1911 aDescr.Parent = nullptr;
1912 else if ( ( aDescr.ParentIndex >= 0 ) && ( o3tl::make_unsigned(aDescr.ParentIndex) < n ) )
1913 aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex];
1914 aSeq.getArray()[n] = createWindow( aDescr );
1916 return aSeq;
1919 // css::awt::XSystemChildFactory
1920 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::createSystemChild( const css::uno::Any& Parent, const css::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 nSystemType )
1922 VclPtr<vcl::Window> pChildWindow;
1923 if ( nSystemType == SYSTEM_DEPENDENT_TYPE )
1925 // use sal_Int64 here to accommodate all int types
1926 // uno::Any shift operator will upcast if necessary
1927 sal_Int64 nWindowHandle = 0;
1928 bool bXEmbed = false;
1930 bool bUseParentData = true;
1931 if( ! (Parent >>= nWindowHandle) )
1933 css::uno::Sequence< css::beans::NamedValue > aProps;
1934 if( Parent >>= aProps )
1936 for (const css::beans::NamedValue& rProp : aProps)
1938 if ( rProp.Name == "WINDOW" )
1939 rProp.Value >>= nWindowHandle;
1940 else if ( rProp.Name == "XEMBED" )
1941 rProp.Value >>= bXEmbed;
1944 else
1945 bUseParentData = false;
1948 if( bUseParentData )
1950 SystemParentData aParentData;
1951 aParentData.nSize = sizeof( aParentData );
1952 #if defined MACOSX
1953 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
1954 #elif defined ANDROID
1955 // Nothing
1956 #elif defined IOS
1957 // Nothing
1958 #elif defined UNX
1959 aParentData.aWindow = nWindowHandle;
1960 aParentData.bXEmbedSupport = bXEmbed;
1961 #elif defined _WIN32
1962 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1963 #endif
1964 SolarMutexGuard aGuard;
1967 pChildWindow.reset( VclPtr<WorkWindow>::Create( &aParentData ) );
1969 catch ( const css::uno::RuntimeException & )
1971 // system child window could not be created
1972 DBG_UNHANDLED_EXCEPTION("toolkit");
1973 pChildWindow.clear();
1977 else if (nSystemType == css::lang::SystemDependent::SYSTEM_JAVA)
1979 SolarMutexGuard aGuard;
1980 pChildWindow.reset(VclPtr<WorkWindow>::Create(nullptr, Parent));
1983 css::uno::Reference< css::awt::XVclWindowPeer > xPeer;
1984 if ( pChildWindow )
1986 rtl::Reference<VCLXTopWindow> pPeer = new VCLXTopWindow;
1987 SolarMutexGuard aGuard;
1988 pPeer->SetWindow( pChildWindow );
1989 xPeer = pPeer;
1990 pChildWindow->SetWindowPeer(xPeer, pPeer.get());
1993 return xPeer;
1996 // css::awt::XMessageBoxFactory
1997 css::uno::Reference< css::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox(
1998 const css::uno::Reference< css::awt::XWindowPeer >& aParent,
1999 css::awt::MessageBoxType eType,
2000 ::sal_Int32 aButtons,
2001 const OUString& aTitle,
2002 const OUString& aMessage )
2004 css::awt::WindowDescriptor aDescriptor;
2006 sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE;
2008 // Map button definitions to window attributes
2009 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK )
2010 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK;
2011 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL )
2012 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL;
2013 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO )
2014 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO;
2015 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL )
2016 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL;
2017 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL )
2018 nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL;
2020 // Map default button definitions to window attributes
2021 if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK )
2022 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK;
2023 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL )
2024 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL;
2025 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES )
2026 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES;
2027 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO )
2028 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO;
2029 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY )
2030 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY;
2032 // No more bits for VclWindowPeerAttribute possible. Mapping must be
2033 // done explicitly using VCL methods
2034 MessBoxStyle nAddWinBits = MessBoxStyle::NONE;
2035 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY )
2036 nAddWinBits |= MessBoxStyle::AbortRetryIgnore;
2037 if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE )
2038 nAddWinBits |= MessBoxStyle::DefaultIgnore;
2040 OUString aType;
2041 lcl_convertMessageBoxType( aType, eType );
2043 aDescriptor.Type = css::awt::WindowClass_MODALTOP;
2044 aDescriptor.WindowServiceName = aType;
2045 aDescriptor.ParentIndex = -1;
2046 aDescriptor.Parent = aParent;
2047 aDescriptor.WindowAttributes = nWindowAttributes;
2048 css::uno::Reference< css::awt::XMessageBox > xMsgBox(
2049 ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY );
2050 css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY );
2051 if ( xMsgBox.is() && xWindow.is() )
2053 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2054 if ( pWindow )
2056 SolarMutexGuard aGuard;
2057 xMsgBox->setCaptionText( aTitle );
2058 xMsgBox->setMessageText( aMessage );
2062 return xMsgBox;
2065 css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL VCLXToolkit::getDragGestureRecognizer( const css::uno::Reference< css::awt::XWindow >& window )
2067 SolarMutexGuard g;
2069 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
2071 if( pWindow )
2072 return pWindow->GetDragGestureRecognizer();
2074 return css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer >();
2077 css::uno::Reference< css::datatransfer::dnd::XDragSource > SAL_CALL VCLXToolkit::getDragSource( const css::uno::Reference< css::awt::XWindow >& window )
2079 SolarMutexGuard g;
2081 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
2083 if( pWindow )
2084 return pWindow->GetDragSource();
2086 return css::uno::Reference< css::datatransfer::dnd::XDragSource >();
2089 css::uno::Reference< css::datatransfer::dnd::XDropTarget > SAL_CALL VCLXToolkit::getDropTarget( const css::uno::Reference< css::awt::XWindow >& window )
2091 SolarMutexGuard g;
2093 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
2095 if( pWindow )
2096 return pWindow->GetDropTarget();
2098 return css::uno::Reference< css::datatransfer::dnd::XDropTarget >();
2101 css::uno::Reference< css::datatransfer::clipboard::XClipboard > SAL_CALL VCLXToolkit::getClipboard( const OUString& clipboardName )
2103 if( clipboardName.isEmpty() )
2105 if( !mxClipboard.is() )
2107 // remember clipboard here
2108 mxClipboard = css::datatransfer::clipboard::SystemClipboard::create(
2109 comphelper::getProcessComponentContext());
2112 return mxClipboard;
2115 else if( clipboardName == "Selection" )
2117 return mxSelection;
2120 return css::uno::Reference< css::datatransfer::clipboard::XClipboard >();
2123 // XServiceInfo
2124 OUString VCLXToolkit::getImplementationName()
2126 return u"stardiv.Toolkit.VCLXToolkit"_ustr;
2129 sal_Bool VCLXToolkit::supportsService( const OUString& rServiceName )
2131 return cppu::supportsService(this, rServiceName);
2134 css::uno::Sequence< OUString > VCLXToolkit::getSupportedServiceNames()
2136 return css::uno::Sequence<OUString>{
2137 u"com.sun.star.awt.Toolkit"_ustr, u"stardiv.vcl.VclToolkit"_ustr};
2140 // css::awt::XExtendedToolkit:
2142 // virtual
2143 ::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount()
2145 return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount());
2146 // XXX numeric overflow
2149 // virtual
2150 css::uno::Reference< css::awt::XTopWindow > SAL_CALL
2151 VCLXToolkit::getTopWindow(::sal_Int32 nIndex)
2153 vcl::Window * p = ::Application::GetTopWindow(static_cast< tools::Long >(nIndex));
2154 // XXX numeric overflow
2155 return css::uno::Reference< css::awt::XTopWindow >(
2156 p == nullptr ? nullptr : static_cast< css::awt::XWindow * >(p->GetWindowPeer()),
2157 css::uno::UNO_QUERY);
2160 // virtual
2161 css::uno::Reference< css::awt::XTopWindow > SAL_CALL
2162 VCLXToolkit::getActiveTopWindow()
2164 vcl::Window * p = ::Application::GetActiveTopWindow();
2165 return css::uno::Reference< css::awt::XTopWindow >(
2166 p == nullptr ? nullptr : static_cast< css::awt::XWindow * >(p->GetWindowPeer()),
2167 css::uno::UNO_QUERY);
2170 // virtual
2171 void SAL_CALL VCLXToolkit::addTopWindowListener(
2172 css::uno::Reference< css::awt::XTopWindowListener > const & rListener)
2174 OSL_ENSURE(rListener.is(), "Null rListener");
2175 std::unique_lock aGuard(m_aMutex);
2176 if (m_bDisposed)
2178 aGuard.unlock();
2179 rListener->disposing(
2180 css::lang::EventObject(
2181 getXWeak()));
2183 else if (m_aTopWindowListeners.addInterface(aGuard, rListener) == 1
2184 && !m_bEventListener)
2186 m_bEventListener = true;
2187 ::Application::AddEventListener(m_aEventListenerLink);
2191 // virtual
2192 void SAL_CALL VCLXToolkit::removeTopWindowListener(
2193 css::uno::Reference< css::awt::XTopWindowListener > const & rListener)
2195 std::unique_lock aGuard(m_aMutex);
2196 if (!m_bDisposed
2197 && m_aTopWindowListeners.removeInterface(aGuard, rListener) == 0
2198 && m_aFocusListeners.getLength(aGuard) == 0 && m_bEventListener)
2200 ::Application::RemoveEventListener(m_aEventListenerLink);
2201 m_bEventListener = false;
2205 // virtual
2206 void SAL_CALL VCLXToolkit::addKeyHandler(
2207 css::uno::Reference< css::awt::XKeyHandler > const & rHandler)
2209 OSL_ENSURE(rHandler.is(), "Null rHandler");
2210 std::unique_lock aGuard(m_aMutex);
2211 if (m_bDisposed)
2213 aGuard.unlock();
2214 rHandler->disposing(
2215 css::lang::EventObject(
2216 getXWeak()));
2218 else if (m_aKeyHandlers.addInterface(aGuard, rHandler) == 1 && !m_bKeyListener)
2220 m_bKeyListener = true;
2221 ::Application::AddKeyListener(m_aKeyListenerLink);
2225 // virtual
2226 void SAL_CALL VCLXToolkit::removeKeyHandler(
2227 css::uno::Reference< css::awt::XKeyHandler > const & rHandler)
2229 std::unique_lock aGuard(m_aMutex);
2230 if (!m_bDisposed
2231 && m_aKeyHandlers.removeInterface(aGuard, rHandler) == 0 && m_bKeyListener)
2233 ::Application::RemoveKeyListener(m_aKeyListenerLink);
2234 m_bKeyListener = false;
2238 // virtual
2239 void SAL_CALL VCLXToolkit::addFocusListener(
2240 css::uno::Reference< css::awt::XFocusListener > const & rListener)
2242 OSL_ENSURE(rListener.is(), "Null rListener");
2243 std::unique_lock aGuard(m_aMutex);
2244 if (m_bDisposed)
2246 aGuard.unlock();
2247 rListener->disposing(
2248 css::lang::EventObject(
2249 getXWeak()));
2251 else if (m_aFocusListeners.addInterface(aGuard, rListener) == 1
2252 && !m_bEventListener)
2254 m_bEventListener = true;
2255 ::Application::AddEventListener(m_aEventListenerLink);
2259 // virtual
2260 void SAL_CALL VCLXToolkit::removeFocusListener(
2261 css::uno::Reference< css::awt::XFocusListener > const & rListener)
2263 std::unique_lock aGuard(m_aMutex);
2264 if (!m_bDisposed
2265 && m_aFocusListeners.removeInterface(aGuard, rListener) == 0
2266 && m_aTopWindowListeners.getLength(aGuard) == 0 && m_bEventListener)
2268 ::Application::RemoveEventListener(m_aEventListenerLink);
2269 m_bEventListener = false;
2273 // virtual
2274 void SAL_CALL VCLXToolkit::fireFocusGained(
2275 css::uno::Reference<
2276 css::uno::XInterface > const &)
2280 // virtual
2281 void SAL_CALL VCLXToolkit::fireFocusLost(
2282 css::uno::Reference<
2283 css::uno::XInterface > const &)
2288 IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent&, rEvent, void)
2290 switch (rEvent.GetId())
2292 case VclEventId::WindowShow:
2293 callTopWindowListeners(
2294 &rEvent, &css::awt::XTopWindowListener::windowOpened);
2295 break;
2296 case VclEventId::WindowHide:
2297 callTopWindowListeners(
2298 &rEvent, &css::awt::XTopWindowListener::windowClosed);
2299 break;
2300 case VclEventId::WindowActivate:
2301 callTopWindowListeners(
2302 &rEvent, &css::awt::XTopWindowListener::windowActivated);
2303 break;
2304 case VclEventId::WindowDeactivate:
2305 callTopWindowListeners(
2306 &rEvent, &css::awt::XTopWindowListener::windowDeactivated);
2307 break;
2308 case VclEventId::WindowClose:
2309 callTopWindowListeners(
2310 &rEvent, &css::awt::XTopWindowListener::windowClosing);
2311 break;
2312 case VclEventId::WindowGetFocus:
2313 callFocusListeners(&rEvent, true);
2314 break;
2315 case VclEventId::WindowLoseFocus:
2316 callFocusListeners(&rEvent, false);
2317 break;
2318 case VclEventId::WindowMinimize:
2319 callTopWindowListeners(
2320 &rEvent, &css::awt::XTopWindowListener::windowMinimized);
2321 break;
2322 case VclEventId::WindowNormalize:
2323 callTopWindowListeners(
2324 &rEvent, &css::awt::XTopWindowListener::windowNormalized);
2325 break;
2326 default: break;
2330 IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclWindowEvent&, rEvent, bool)
2332 switch (rEvent.GetId())
2334 case VclEventId::WindowKeyInput:
2335 return callKeyHandlers(&rEvent, true);
2336 case VclEventId::WindowKeyUp:
2337 return callKeyHandlers(&rEvent, false);
2338 default: break;
2340 return false;
2343 void VCLXToolkit::callTopWindowListeners(
2344 ::VclSimpleEvent const * pEvent,
2345 void (SAL_CALL css::awt::XTopWindowListener::* pFn)(
2346 css::lang::EventObject const &))
2348 vcl::Window * pWindow
2349 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2350 if (!pWindow->IsTopWindow())
2351 return;
2353 std::unique_lock aGuard(m_aMutex);
2354 if (m_aTopWindowListeners.getLength(aGuard) == 0)
2355 return;
2357 css::lang::EventObject aAwtEvent(
2358 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()));
2359 m_aTopWindowListeners.forEach(aGuard,
2360 [&pFn, &aAwtEvent](const css::uno::Reference<css::awt::XTopWindowListener> & xListener)
2364 (xListener.get()->*pFn)(aAwtEvent);
2366 catch (const css::uno::RuntimeException &)
2368 DBG_UNHANDLED_EXCEPTION("toolkit");
2373 bool VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent,
2374 bool bPressed)
2376 std::unique_lock aGuard(m_aMutex);
2378 if (m_aKeyHandlers.getLength(aGuard) != 0)
2380 vcl::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2382 // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event
2383 ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >(
2384 static_cast< ::VclWindowEvent const * >(pEvent)->GetData());
2385 css::awt::KeyEvent aAwtEvent(
2386 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
2387 (pKeyEvent->GetKeyCode().IsShift()
2388 ? css::awt::KeyModifier::SHIFT : 0)
2389 | (pKeyEvent->GetKeyCode().IsMod1()
2390 ? css::awt::KeyModifier::MOD1 : 0)
2391 | (pKeyEvent->GetKeyCode().IsMod2()
2392 ? css::awt::KeyModifier::MOD2 : 0)
2393 | (pKeyEvent->GetKeyCode().IsMod3()
2394 ? css::awt::KeyModifier::MOD3 : 0),
2395 pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(),
2396 sal::static_int_cast< sal_Int16 >(
2397 pKeyEvent->GetKeyCode().GetFunction()));
2398 comphelper::OInterfaceIteratorHelper4 aIt(aGuard, m_aKeyHandlers);
2399 aGuard.unlock();
2400 while (aIt.hasMoreElements())
2402 css::awt::XKeyHandler* pL = aIt.next().get();
2405 if (bPressed ? pL->keyPressed(aAwtEvent)
2406 : pL->keyReleased(aAwtEvent))
2407 return true;
2409 catch (const css::uno::RuntimeException &)
2411 DBG_UNHANDLED_EXCEPTION("toolkit");
2415 return false;
2418 void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent,
2419 bool bGained)
2421 vcl::Window * pWindow
2422 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2423 if (!pWindow->IsTopWindow())
2424 return;
2426 std::unique_lock aGuard(m_aMutex);
2427 if (m_aFocusListeners.getLength(aGuard) == 0)
2428 return;
2430 // Ignore the interior of compound controls when determining the
2431 // window that gets the focus next (see implementation in
2432 // vclxwindow.cxx for mapping between VCL and UNO AWT event):
2433 css::uno::Reference< css::uno::XInterface > xNext;
2434 vcl::Window * pFocus = ::Application::GetFocusWindow();
2435 for (vcl::Window * p = pFocus; p != nullptr; p = p->GetParent())
2436 if (!p->IsCompoundControl())
2438 pFocus = p;
2439 break;
2441 if (pFocus != nullptr)
2442 xNext = pFocus->GetComponentInterface();
2443 css::awt::FocusEvent aAwtEvent(
2444 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
2445 static_cast<sal_Int16>(pWindow->GetGetFocusFlags()),
2446 xNext, false);
2447 m_aFocusListeners.forEach(aGuard,
2448 [bGained, &aAwtEvent] (const css::uno::Reference<css::awt::XFocusListener> & xListener)
2452 bGained ? xListener->focusGained(aAwtEvent)
2453 : xListener->focusLost(aAwtEvent);
2455 catch (const css::uno::RuntimeException &)
2457 DBG_UNHANDLED_EXCEPTION("toolkit");
2462 // css::awt::XReschedule:
2464 void SAL_CALL VCLXToolkit::reschedule()
2466 SolarMutexGuard aSolarGuard;
2467 Application::Reschedule(true);
2470 // css::awt::XFontMappingUse:
2471 void SAL_CALL VCLXToolkit::startTrackingFontMappingUse()
2473 SolarMutexGuard aSolarGuard;
2474 OutputDevice::StartTrackingFontMappingUse();
2477 css::uno::Sequence<css::awt::XFontMappingUseItem>
2478 SAL_CALL VCLXToolkit::finishTrackingFontMappingUse()
2480 SolarMutexGuard aSolarGuard;
2481 OutputDevice::FontMappingUseData data = OutputDevice::FinishTrackingFontMappingUse();
2482 css::uno::Sequence<css::awt::XFontMappingUseItem> ret( data.size());
2483 css::awt::XFontMappingUseItem* retData = ret.getArray();
2484 for( size_t i = 0; i < data.size(); ++i )
2486 retData[ i ].originalFont = data[ i ].mOriginalFont;
2487 retData[ i ].usedFonts = comphelper::arrayToSequence<OUString,OUString>
2488 (data[ i ].mUsedFonts.data(), data[ i ].mUsedFonts.size());
2489 retData[ i ].count = data[ i ].mCount;
2491 return ret;
2494 // css::awt::XToolkitExperimental
2496 void SAL_CALL VCLXToolkit::processEventsToIdle()
2498 SolarMutexGuard aSolarGuard;
2499 comphelper::ProfileZone aZone("processEvents");
2500 Scheduler::ProcessEventsToIdle();
2503 sal_Int64 SAL_CALL VCLXToolkit::getOpenGLBufferSwapCounter()
2505 #if HAVE_FEATURE_OPENGL
2506 return OpenGLWrapper::getBufferSwapCounter();
2507 #else
2508 return 0;
2509 #endif
2512 void SAL_CALL VCLXToolkit::setDeterministicScheduling(sal_Bool bDeterministicMode)
2514 SolarMutexGuard aSolarGuard;
2515 Scheduler::SetDeterministicMode(bDeterministicMode);
2518 void SAL_CALL VCLXToolkit::pause(sal_Int32 nMilliseconds)
2520 new Pause(nMilliseconds);
2523 void SAL_CALL VCLXToolkit::startRecording()
2525 comphelper::TraceEvent::startRecording();
2528 void SAL_CALL VCLXToolkit::stopRecording()
2530 comphelper::TraceEvent::stopRecording();
2533 css::uno::Sequence< OUString > VCLXToolkit::getRecordingAndClear()
2535 return comphelper::ProfileZone::getRecordingAndClear();
2538 void VCLXToolkit::waitUntilAllIdlesDispatched()
2540 IdleTask::waitUntilIdleDispatched();
2543 // css:awt:XToolkitRobot
2545 void SAL_CALL VCLXToolkit::keyPress( const css::awt::KeyEvent & aKeyEvent )
2547 css::uno::Reference<css::awt::XWindow> xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY_THROW );
2548 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2549 if( !pWindow )
2550 throw css::uno::RuntimeException( u"invalid event source"_ustr );
2552 ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent );
2553 ::Application::PostKeyEvent( VclEventId::WindowKeyInput, pWindow, &aVCLKeyEvent );
2556 void SAL_CALL VCLXToolkit::keyRelease( const css::awt::KeyEvent & aKeyEvent )
2558 css::uno::Reference<css::awt::XWindow> xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY_THROW );
2559 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2560 if( !pWindow )
2561 throw css::uno::RuntimeException( u"invalid event source"_ustr );
2563 ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent );
2564 ::Application::PostKeyEvent( VclEventId::WindowKeyUp, pWindow, &aVCLKeyEvent );
2568 void SAL_CALL VCLXToolkit::mousePress( const css::awt::MouseEvent & aMouseEvent )
2570 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2571 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2572 if( !pWindow )
2573 throw css::uno::RuntimeException( u"invalid event source"_ustr );
2575 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2576 ::Application::PostMouseEvent( VclEventId::WindowMouseButtonDown, pWindow, &aVCLMouseEvent );
2579 void SAL_CALL VCLXToolkit::mouseRelease( const css::awt::MouseEvent & aMouseEvent )
2581 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2582 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2583 if( !pWindow )
2584 throw css::uno::RuntimeException( u"invalid event source"_ustr );
2586 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2587 ::Application::PostMouseEvent( VclEventId::WindowMouseButtonUp, pWindow, &aVCLMouseEvent );
2590 void SAL_CALL VCLXToolkit::mouseMove( const css::awt::MouseEvent & aMouseEvent )
2592 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2593 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2594 if( !pWindow )
2595 throw css::uno::RuntimeException( u"invalid event source"_ustr );
2597 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2598 ::Application::PostMouseEvent( VclEventId::WindowMouseMove, pWindow, &aVCLMouseEvent );
2604 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
2605 stardiv_Toolkit_VCLXToolkit_get_implementation(
2606 css::uno::XComponentContext *,
2607 css::uno::Sequence<css::uno::Any> const &)
2609 return cppu::acquire(new VCLXToolkit());
2612 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */