Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / toolkit / source / awt / vclxtoolkit.cxx
blobc8e918c2cea3b6f9227b5ccd5cfac8b0d5ca831d
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/basemutex.hxx>
53 #include <cppuhelper/bootstrap.hxx>
54 #include <cppuhelper/compbase.hxx>
55 #include <cppuhelper/supportsservice.hxx>
56 #include <o3tl/safeint.hxx>
57 #include <osl/conditn.hxx>
58 #include <osl/module.h>
59 #include <osl/thread.hxx>
60 #include <osl/mutex.hxx>
61 #include <rtl/ref.hxx>
62 #include <rtl/process.h>
63 #include <sal/log.hxx>
64 #include <tools/link.hxx>
65 #include <vcl/wintypes.hxx>
67 #ifdef MACOSX
68 #include <premac.h>
69 #include <Cocoa/Cocoa.h>
70 #include <postmac.h>
71 #endif
73 #include <utility>
74 #include <vcl/sysdata.hxx>
75 #include <vcl/textrectinfo.hxx>
76 #include <vcl/toolkit/vclmedit.hxx>
78 #include <toolkit/awt/vclxwindows.hxx>
79 #include <awt/vclxwindows.hxx>
80 #include <awt/vclxsystemdependentwindow.hxx>
81 #include <awt/vclxregion.hxx>
82 #include <awt/vclxtabpagecontainer.hxx>
83 #include <awt/vclxtopwindow.hxx>
85 #include <awt/animatedimagespeer.hxx>
86 #include <toolkit/awt/vclxwindow.hxx>
87 #include <toolkit/helper/vclunohelper.hxx>
88 #include <helper/property.hxx>
90 #include <toolkit/helper/convert.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/diagnose_ex.hxx>
140 #include <comphelper/interfacecontainer3.hxx>
141 #include <comphelper/processfactory.hxx>
142 #include <comphelper/profilezone.hxx>
144 #include <helper/msgbox.hxx>
145 #include <helper/scrollabledialog.hxx>
146 #include <helper/unowrapper.hxx>
148 #if defined(_WIN32)
149 #define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_WIN32
150 #elif defined(MACOSX)
151 #define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_MAC
152 #elif defined(UNX)
153 #define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_XWINDOW
154 #endif
156 void MessBox::ImplInitButtons()
158 ButtonDialogFlags nOKFlags = ButtonDialogFlags::OK;
159 ButtonDialogFlags nCancelFlags = ButtonDialogFlags::Cancel;
160 ButtonDialogFlags nRetryFlags = ButtonDialogFlags::NONE;
161 ButtonDialogFlags nYesFlags = ButtonDialogFlags::NONE;
162 ButtonDialogFlags nNoFlags = ButtonDialogFlags::NONE;
164 if ( mnMessBoxStyle & MessBoxStyle::OkCancel )
166 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
167 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
168 else // MessBoxStyle::DefaultOk
169 nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
171 AddButton( StandardButtonType::OK, RET_OK, nOKFlags );
172 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
174 else if ( mnMessBoxStyle & MessBoxStyle::YesNo )
176 if ( mnMessBoxStyle & MessBoxStyle::DefaultYes )
177 nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
178 else // MessBoxStyle::DefaultNo
179 nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
180 nNoFlags |= ButtonDialogFlags::Cancel;
182 AddButton( StandardButtonType::Yes, RET_YES, nYesFlags );
183 AddButton( StandardButtonType::No, RET_NO, nNoFlags );
185 else if ( mnMessBoxStyle & MessBoxStyle::YesNoCancel )
187 if ( mnMessBoxStyle & MessBoxStyle::DefaultYes )
188 nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
189 else if ( mnMessBoxStyle & MessBoxStyle::DefaultNo )
190 nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
191 else
192 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
194 AddButton( StandardButtonType::Yes, RET_YES, nYesFlags );
195 AddButton( StandardButtonType::No, RET_NO, nNoFlags );
196 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
198 else if ( mnMessBoxStyle & MessBoxStyle::RetryCancel )
200 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
201 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
202 else // MessBoxStyle::DefaultRetry
203 nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
205 AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags );
206 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
208 else if ( mnMessBoxStyle & MessBoxStyle::AbortRetryIgnore )
210 ButtonDialogFlags nAbortFlags = ButtonDialogFlags::NONE;
211 ButtonDialogFlags nIgnoreFlags = ButtonDialogFlags::NONE;
213 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
214 nAbortFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
215 else if ( mnMessBoxStyle & MessBoxStyle::DefaultRetry )
216 nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
217 else if ( mnMessBoxStyle & MessBoxStyle::DefaultIgnore )
218 nIgnoreFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
220 AddButton( StandardButtonType::Abort, RET_CANCEL, nAbortFlags );
221 AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags );
222 AddButton( StandardButtonType::Ignore, RET_IGNORE, nIgnoreFlags );
224 else if ( mnMessBoxStyle & MessBoxStyle::Ok )
226 nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
228 AddButton( StandardButtonType::OK, RET_OK, nOKFlags );
232 MessBox::MessBox(vcl::Window* pParent, MessBoxStyle nMessBoxStyle, WinBits nWinBits,
233 const OUString& rTitle, OUString aMessage) :
234 ButtonDialog( WindowType::MESSBOX ),
235 mbHelpBtn( false ),
236 mnMessBoxStyle( nMessBoxStyle ),
237 maMessText(std::move( aMessage ))
239 ImplLOKNotifier(pParent);
240 ImplInitDialog(pParent, nWinBits | WB_MOVEABLE | WB_HORZ | WB_CENTER);
241 ImplInitButtons();
243 if ( !rTitle.isEmpty() )
244 SetText( rTitle );
247 MessBox::~MessBox()
249 disposeOnce();
252 void MessBox::dispose()
254 mpVCLMultiLineEdit.disposeAndClear();
255 mpFixedImage.disposeAndClear();
256 ButtonDialog::dispose();
259 void MessBox::ImplPosControls()
261 if ( !GetHelpId().isEmpty() )
263 if ( !mbHelpBtn )
265 AddButton( StandardButtonType::Help, RET_HELP, ButtonDialogFlags::Help, 3 );
266 mbHelpBtn = true;
269 else
271 if ( mbHelpBtn )
273 RemoveButton( RET_HELP );
274 mbHelpBtn = false;
278 TextRectInfo aTextInfo;
279 tools::Rectangle aRect( 0, 0, 30000, 30000 );
280 tools::Rectangle aFormatRect;
281 Point aTextPos( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+IMPL_MSGBOX_OFFSET_EXTRA_Y );
282 Size aImageSize;
283 Size aPageSize;
284 Size aMEditSize;
285 tools::Long nTitleWidth;
286 tools::Long nButtonSize = ImplGetButtonSize();
287 tools::Long nMaxLineWidth;
288 tools::Long nWidth;
289 WinBits nWinStyle = WB_LEFT | WB_NOLABEL;
290 DrawTextFlags nTextStyle = DrawTextFlags::MultiLine | DrawTextFlags::Top | DrawTextFlags::Left;
292 mpVCLMultiLineEdit.disposeAndClear();
293 mpFixedImage.disposeAndClear();
295 // Clean up message text with tabs
296 OUString aMessText(maMessText.replaceAll("\t", " "));
298 //If window too small, we make dialog box be wider
299 tools::Long nMaxWidth = 630 * GetDPIScaleFactor();
301 // MessagBox should be at least as wide as to see the title
302 // Extra-Width for Close button, because Close button is set after this call
303 nTitleWidth = CalcTitleWidth();
305 nMaxWidth -= (IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2);
307 // for an image, get its size, create a suitable control and position it
308 aImageSize = maImage.GetSizePixel();
309 if ( aImageSize.Width() )
311 aImageSize.AdjustWidth(4 );
312 aImageSize.AdjustHeight(4 );
313 aTextPos.AdjustX(aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE );
314 mpFixedImage = VclPtr<FixedImage>::Create( this );
315 mpFixedImage->SetPosSizePixel( Point( IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_X,
316 IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_Y ),
317 aImageSize );
318 mpFixedImage->SetImage( maImage );
319 mpFixedImage->Show();
320 nMaxWidth -= aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE;
322 else
323 aTextPos.AdjustX(IMPL_MSGBOX_OFFSET_EXTRA_X );
325 // Determine maximum line length without wordbreak
326 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
327 nMaxLineWidth = aFormatRect.GetWidth();
328 nTextStyle |= DrawTextFlags::WordBreak;
330 // Determine the width for text formatting
331 if ( nMaxLineWidth > 450 )
332 nWidth = 450;
333 else if ( nMaxLineWidth > 300 )
334 nWidth = nMaxLineWidth+5;
335 else
336 nWidth = 300;
338 nWidth *= GetDPIScaleFactor();
340 if ( nButtonSize > nWidth )
341 nWidth = nButtonSize-(aTextPos.X()-IMPL_DIALOG_OFFSET);
342 if ( nWidth > nMaxWidth )
343 nWidth = nMaxWidth;
345 aRect.SetRight( nWidth );
346 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
347 if ( aTextInfo.GetMaxLineWidth() > nWidth )
349 nWidth = aTextInfo.GetMaxLineWidth()+8;
350 aRect.SetRight( nWidth );
351 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
354 // get Style for VCLMultiLineEdit
355 aMEditSize.setWidth( aTextInfo.GetMaxLineWidth()+1 );
356 aMEditSize.setHeight( aFormatRect.GetHeight() );
357 aPageSize.setWidth( aImageSize.Width() );
358 if ( aMEditSize.Height() < aImageSize.Height() )
360 nWinStyle |= WB_VCENTER;
361 aPageSize.setHeight( aImageSize.Height() );
362 aMEditSize.setHeight( aImageSize.Height() );
364 else
366 nWinStyle |= WB_TOP;
367 aPageSize.setHeight( aMEditSize.Height() );
369 if ( aImageSize.Width() )
370 aPageSize.AdjustWidth(IMPL_SEP_MSGBOX_IMAGE );
371 aPageSize.AdjustWidth((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2) );
372 aPageSize.AdjustWidth(aMEditSize.Width()+1 );
373 aPageSize.AdjustHeight((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_Y*2) );
375 if ( aPageSize.Width() < IMPL_MINSIZE_MSGBOX_WIDTH )
376 aPageSize.setWidth( IMPL_MINSIZE_MSGBOX_WIDTH );
377 if ( aPageSize.Width() < nTitleWidth )
378 aPageSize.setWidth( nTitleWidth );
380 mpVCLMultiLineEdit = VclPtr<VclMultiLineEdit>::Create( this, nWinStyle );
381 mpVCLMultiLineEdit->SetText( aMessText );
382 mpVCLMultiLineEdit->SetPosSizePixel( aTextPos, aMEditSize );
383 mpVCLMultiLineEdit->Show();
384 mpVCLMultiLineEdit->SetPaintTransparent(true);
385 mpVCLMultiLineEdit->EnableCursor(false);
386 SetPageSizePixel( aPageSize );
389 void MessBox::StateChanged( StateChangedType nType )
391 if ( nType == StateChangedType::InitShow )
393 ImplPosControls();
395 ButtonDialog::StateChanged( nType );
398 Size MessBox::GetOptimalSize() const
400 // FIXME: base me on the font size ?
401 return Size( 250, 100 );
405 namespace {
407 class Pause : public Idle
409 public:
410 explicit Pause(sal_Int32 nPauseMilliseconds) :
411 Idle("pause"),
412 m_nPauseMilliseconds(nPauseMilliseconds)
414 SetPriority(TaskPriority::HIGHEST);
415 Start();
418 virtual void Invoke() override
420 SolarMutexGuard aSolarGuard;
421 std::this_thread::sleep_for(std::chrono::milliseconds(m_nPauseMilliseconds));
422 Stop();
423 delete this;
426 sal_Int32 m_nPauseMilliseconds;
429 class VCLXToolkit : public cppu::BaseMutex,
430 public cppu::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::OInterfaceContainerHelper3<css::awt::XTopWindowListener> m_aTopWindowListeners;
439 ::comphelper::OInterfaceContainerHelper3<css::awt::XKeyHandler> m_aKeyHandlers;
440 ::comphelper::OInterfaceContainerHelper3<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 ::osl::Mutex& GetMutex() { return m_aMutex; }
462 virtual void SAL_CALL disposing() override;
464 static vcl::Window* ImplCreateWindow( rtl::Reference<VCLXWindow>* ppNewComp, const css::awt::WindowDescriptor& rDescriptor, vcl::Window* pParent,
465 WinBits nWinBits, MessBoxStyle nMessBoxStyle );
466 css::uno::Reference< css::awt::XWindowPeer > ImplCreateWindow( const css::awt::WindowDescriptor& Descriptor,
467 MessBoxStyle nForceMessBoxStyle );
469 public:
471 VCLXToolkit();
473 // css::awt::XToolkitExperimental
474 virtual void SAL_CALL processEventsToIdle() override;
476 virtual sal_Int64 SAL_CALL getOpenGLBufferSwapCounter() override;
478 virtual void SAL_CALL setDeterministicScheduling(sal_Bool bDeterministicMode) override;
480 virtual void SAL_CALL pause(sal_Int32 nMilliseconds) override;
482 virtual void SAL_CALL startRecording() override;
484 virtual void SAL_CALL stopRecording() override;
486 css::uno::Sequence< OUString > SAL_CALL getRecordingAndClear() 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 cppu::WeakComponentImplHelper<
925 css::awt::XToolkitExperimental,
926 css::awt::XToolkitRobot,
927 css::lang::XServiceInfo>( GetMutex() ),
928 m_aTopWindowListeners(rBHelper.rMutex),
929 m_aKeyHandlers(rBHelper.rMutex),
930 m_aFocusListeners(rBHelper.rMutex),
931 m_aEventListenerLink(LINK(this, VCLXToolkit, eventListenerHandler)),
932 m_aKeyListenerLink(LINK(this, VCLXToolkit, keyListenerHandler)),
933 m_bEventListener(false),
934 m_bKeyListener(false)
936 #ifndef IOS
937 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
938 nVCLToolkitInstanceCount++;
939 if( ( nVCLToolkitInstanceCount == 1 ) && ( !Application::IsInMain() ) )
941 // setup execute thread
942 CreateMainLoopThread( ToolkitWorkerFunction, this );
943 getInitCondition().wait();
945 #endif
948 void SAL_CALL VCLXToolkit::disposing()
950 #ifndef IOS
952 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
953 if( --nVCLToolkitInstanceCount == 0 )
955 if( bInitedByVCLToolkit )
957 Application::Quit();
958 JoinMainLoopThread();
959 bInitedByVCLToolkit = false;
963 #endif
964 if (m_bEventListener)
966 ::Application::RemoveEventListener(m_aEventListenerLink);
967 m_bEventListener = false;
969 if (m_bKeyListener)
971 ::Application::RemoveKeyListener(m_aKeyListenerLink);
972 m_bKeyListener = false;
974 css::lang::EventObject aEvent(
975 static_cast< ::cppu::OWeakObject * >(this));
976 m_aTopWindowListeners.disposeAndClear(aEvent);
977 m_aKeyHandlers.disposeAndClear(aEvent);
978 m_aFocusListeners.disposeAndClear(aEvent);
982 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::getDesktopWindow( )
984 css::uno::Reference< css::awt::XWindowPeer > xRef;
985 // 07/00: AppWindow doesn't exist anymore...
986 return xRef;
989 css::awt::Rectangle VCLXToolkit::getWorkArea( )
991 sal_Int32 nDisplay = Application::GetDisplayBuiltInScreen();
992 tools::Rectangle aWorkRect = Application::GetScreenPosSizePixel( nDisplay );
993 css::awt::Rectangle aNotherRect;
994 aNotherRect.X = aWorkRect.Left();
995 aNotherRect.Y = aWorkRect.Top();
996 aNotherRect.Width = aWorkRect.getOpenWidth();
997 aNotherRect.Height = aWorkRect.getOpenHeight();
998 return aNotherRect;
1001 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::createWindow( const css::awt::WindowDescriptor& rDescriptor )
1003 return ImplCreateWindow( rDescriptor, MessBoxStyle::NONE );
1006 css::uno::Reference< css::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height )
1008 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1010 rtl::Reference<VCLXVirtualDevice> pVDev = new VCLXVirtualDevice;
1012 SolarMutexGuard aSolarGuard;
1014 VclPtrInstance<VirtualDevice> pV;
1015 pV->SetOutputSizePixel( Size( Width, Height ) );
1016 pVDev->SetVirtualDevice( pV );
1018 return pVDev;
1021 css::uno::Reference< css::awt::XRegion > VCLXToolkit::createRegion( )
1023 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1025 css::uno::Reference< css::awt::XRegion > xRef = new VCLXRegion;
1026 return xRef;
1029 class InfoBox : public MessBox
1031 public:
1032 InfoBox(vcl::Window* pParent, const OUString& rMessage)
1033 : MessBox(pParent, MessBoxStyle::Ok | MessBoxStyle::DefaultOk, 0, OUString(), rMessage)
1035 // Default Text is the display title from the application
1036 if (GetText().isEmpty())
1037 SetText(GetStandardInfoBoxText());
1038 SetImage(GetStandardInfoBoxImage());
1042 class ErrorBox : public MessBox
1044 public:
1045 ErrorBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1046 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1048 // Default Text is the display title from the application
1049 if (GetText().isEmpty())
1050 SetText(GetStandardErrorBoxText());
1051 SetImage(GetStandardErrorBoxImage());
1055 class QueryBox : public MessBox
1057 public:
1058 QueryBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1059 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1061 // Default Text is the display title from the application
1062 if (GetText().isEmpty())
1063 SetText(GetStandardQueryBoxText());
1064 SetImage(GetStandardQueryBoxImage());
1068 class WarningBox : public MessBox
1070 public:
1071 WarningBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1072 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1074 // Default Text is the display title from the application
1075 if (GetText().isEmpty())
1076 SetText(GetStandardWarningBoxText());
1077 SetImage(GetStandardWarningBoxImage());
1082 struct RMItemData
1084 bool b_Enabled;
1085 sal_Int32 n_ID;
1086 OUString Label;
1089 typedef ::cppu::ImplInheritanceHelper < VCLXGraphicControl
1090 , css::container::XContainerListener
1091 , css::beans::XPropertyChangeListener
1092 , css::awt::XItemEventBroadcaster
1093 > SVTXRoadmap_Base;
1094 class SVTXRoadmap final : public SVTXRoadmap_Base
1096 public:
1097 SVTXRoadmap();
1099 void SAL_CALL disposing( const css::lang::EventObject& Source ) override { VCLXWindow::disposing( Source ); }
1101 // css::awt::XVclWindowPeer
1102 void SAL_CALL setProperty( const OUString& PropertyName, const css::uno::Any& Value ) override;
1104 css::uno::Any SAL_CALL getProperty( const OUString& PropertyName ) override;
1106 // XContainerListener
1107 void SAL_CALL elementInserted( const css::container::ContainerEvent& rEvent ) override;
1108 void SAL_CALL elementRemoved( const css::container::ContainerEvent& rEvent ) override;
1109 void SAL_CALL elementReplaced( const css::container::ContainerEvent& rEvent ) override;
1111 // XItemEventBroadcaster
1112 virtual void SAL_CALL addItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) override;
1113 virtual void SAL_CALL removeItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) override;
1115 // XPropertyChangeListener
1116 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
1118 private:
1120 // VCLXGraphicControl overridables
1121 virtual void ImplSetNewImage() override;
1123 static void ImplGetPropertyIds( std::vector< sal_uInt16 > &aIds );
1124 virtual void GetPropertyIds( std::vector< sal_uInt16 > &aIds ) override { return ImplGetPropertyIds( aIds ); }
1126 static RMItemData GetRMItemData( const css::container::ContainerEvent& _rEvent );
1128 virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) override;
1130 virtual ~SVTXRoadmap() override;
1132 ItemListenerMultiplexer maItemListeners;
1138 SVTXRoadmap::SVTXRoadmap() : maItemListeners( *this )
1142 SVTXRoadmap::~SVTXRoadmap()
1146 void SVTXRoadmap::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
1148 switch ( rVclWindowEvent.GetId() )
1150 case VclEventId::RoadmapItemSelected:
1152 SolarMutexGuard aGuard;
1153 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1154 if ( pField )
1156 sal_Int16 CurItemID = pField->GetCurrentRoadmapItemID();
1157 css::awt::ItemEvent aEvent;
1158 aEvent.Selected = CurItemID;
1159 aEvent.Highlighted = CurItemID;
1160 aEvent.ItemId = CurItemID;
1161 maItemListeners.itemStateChanged( aEvent );
1164 break;
1165 default:
1166 SVTXRoadmap_Base::ProcessWindowEvent( rVclWindowEvent );
1167 break;
1171 void SVTXRoadmap::propertyChange( const css::beans::PropertyChangeEvent& evt )
1173 SolarMutexGuard aGuard;
1174 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1175 if ( !pField )
1176 return;
1178 css::uno::Reference< css::uno::XInterface > xRoadmapItem = evt.Source;
1179 sal_Int32 nID = 0;
1180 css::uno::Reference< css::beans::XPropertySet > xPropertySet( xRoadmapItem, css::uno::UNO_QUERY );
1181 css::uno::Any aValue = xPropertySet->getPropertyValue("ID");
1182 aValue >>= nID;
1184 OUString sPropertyName = evt.PropertyName;
1185 if ( sPropertyName == "Enabled" )
1187 bool bEnable = false;
1188 evt.NewValue >>= bEnable;
1189 pField->EnableRoadmapItem( static_cast<vcl::RoadmapTypes::ItemId>(nID) , bEnable );
1191 else if ( sPropertyName == "Label" )
1193 OUString sLabel;
1194 evt.NewValue >>= sLabel;
1195 pField->ChangeRoadmapItemLabel( static_cast<vcl::RoadmapTypes::ItemId>(nID) , sLabel );
1197 else if ( sPropertyName == "ID" )
1199 sal_Int32 nNewID = 0;
1200 evt.NewValue >>= nNewID;
1201 evt.OldValue >>= nID;
1202 pField->ChangeRoadmapItemID( static_cast<vcl::RoadmapTypes::ItemId>(nID), static_cast<vcl::RoadmapTypes::ItemId>(nNewID) );
1204 // else
1205 // TODO handle Interactive appropriately
1208 void SVTXRoadmap::addItemListener( const css::uno::Reference< css::awt::XItemListener >& l )
1210 maItemListeners.addInterface( l );
1213 void SVTXRoadmap::removeItemListener( const css::uno::Reference< css::awt::XItemListener >& l )
1215 maItemListeners.removeInterface( l );
1218 RMItemData SVTXRoadmap::GetRMItemData( const css::container::ContainerEvent& _rEvent )
1220 RMItemData aCurRMItemData;
1221 css::uno::Reference< css::uno::XInterface > xRoadmapItem;
1222 _rEvent.Element >>= xRoadmapItem;
1223 css::uno::Reference< css::beans::XPropertySet > xPropertySet( xRoadmapItem, css::uno::UNO_QUERY );
1224 if ( xPropertySet.is() )
1226 css::uno::Any aValue = xPropertySet->getPropertyValue("Label");
1227 aValue >>= aCurRMItemData.Label;
1228 aValue = xPropertySet->getPropertyValue("ID");
1229 aValue >>= aCurRMItemData.n_ID;
1230 aValue = xPropertySet->getPropertyValue("Enabled");
1231 aValue >>= aCurRMItemData.b_Enabled;
1233 else
1235 aCurRMItemData.b_Enabled = false;
1236 aCurRMItemData.n_ID = 0;
1238 return aCurRMItemData;
1241 void SVTXRoadmap::elementInserted( const css::container::ContainerEvent& _rEvent )
1243 SolarMutexGuard aGuard;
1244 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1245 if ( pField )
1247 RMItemData CurItemData = GetRMItemData( _rEvent );
1248 sal_Int32 InsertIndex = 0;
1249 _rEvent.Accessor >>= InsertIndex;
1250 pField->InsertRoadmapItem( InsertIndex, CurItemData.Label, static_cast<vcl::RoadmapTypes::ItemId>(CurItemData.n_ID), CurItemData.b_Enabled );
1254 void SVTXRoadmap::elementRemoved( const css::container::ContainerEvent& _rEvent )
1256 SolarMutexGuard aGuard;
1257 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1258 if ( pField )
1260 sal_Int32 DelIndex = 0;
1261 _rEvent.Accessor >>= DelIndex;
1262 pField->DeleteRoadmapItem(DelIndex);
1266 void SVTXRoadmap::elementReplaced( const css::container::ContainerEvent& _rEvent )
1268 SolarMutexGuard aGuard;
1269 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1270 if ( pField )
1272 RMItemData CurItemData = GetRMItemData( _rEvent );
1273 sal_Int32 ReplaceIndex = 0;
1274 _rEvent.Accessor >>= ReplaceIndex;
1275 pField->ReplaceRoadmapItem( ReplaceIndex, CurItemData.Label, static_cast<vcl::RoadmapTypes::ItemId>(CurItemData.n_ID), CurItemData.b_Enabled );
1279 void SVTXRoadmap::setProperty( const OUString& PropertyName, const css::uno::Any& Value)
1281 SolarMutexGuard aGuard;
1283 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1284 if ( pField )
1286 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1287 switch (nPropType)
1289 case BASEPROPERTY_COMPLETE:
1291 bool b = false;
1292 Value >>= b;
1293 pField->SetRoadmapComplete( b);
1295 break;
1297 case BASEPROPERTY_ACTIVATED:
1299 bool b = false;
1300 Value >>= b;
1301 pField->SetRoadmapInteractive( b);
1303 break;
1305 case BASEPROPERTY_CURRENTITEMID:
1307 sal_Int32 nId = 0;
1308 Value >>= nId;
1309 pField->SelectRoadmapItemByID( static_cast<vcl::RoadmapTypes::ItemId>(nId) );
1311 break;
1313 case BASEPROPERTY_TEXT:
1315 OUString aStr;
1316 Value >>= aStr;
1317 pField->SetText( aStr );
1318 pField->Invalidate();
1320 break;
1322 default:
1323 SVTXRoadmap_Base::setProperty( PropertyName, Value );
1324 break;
1328 else
1329 SVTXRoadmap_Base::setProperty( PropertyName, Value );
1333 css::uno::Any SVTXRoadmap::getProperty( const OUString& PropertyName )
1335 SolarMutexGuard aGuard;
1337 css::uno::Any aReturn;
1339 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1340 if ( pField )
1342 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1343 switch (nPropType)
1345 case BASEPROPERTY_COMPLETE:
1346 aReturn <<= pField->IsRoadmapComplete();
1347 break;
1348 case BASEPROPERTY_ACTIVATED:
1349 aReturn <<= pField->IsRoadmapInteractive();
1350 break;
1351 case BASEPROPERTY_CURRENTITEMID:
1352 aReturn <<= pField->GetCurrentRoadmapItemID();
1353 break;
1354 default:
1355 aReturn = SVTXRoadmap_Base::getProperty(PropertyName);
1356 break;
1359 return aReturn;
1362 void SVTXRoadmap::ImplSetNewImage()
1364 OSL_PRECOND( GetWindow(), "SVTXRoadmap::ImplSetNewImage: window is required to be not-NULL!" );
1365 VclPtr< ::vcl::ORoadmap > pButton = GetAs< ::vcl::ORoadmap >();
1366 pButton->SetRoadmapBitmap( GetImage().GetBitmapEx() );
1369 void SVTXRoadmap::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds )
1371 PushPropertyIds( rIds,
1372 BASEPROPERTY_COMPLETE,
1373 BASEPROPERTY_ACTIVATED,
1374 BASEPROPERTY_CURRENTITEMID,
1375 BASEPROPERTY_TEXT,
1377 VCLXWindow::ImplGetPropertyIds( rIds, true );
1378 VCLXGraphicControl::ImplGetPropertyIds( rIds );
1381 vcl::Window* VCLXToolkit::ImplCreateWindow( rtl::Reference<VCLXWindow>* ppNewComp,
1382 const css::awt::WindowDescriptor& rDescriptor,
1383 vcl::Window* pParent, WinBits nWinBits, MessBoxStyle nMessBoxStyle )
1385 OUString aServiceName = rDescriptor.WindowServiceName.toAsciiLowerCase();
1387 VclPtr<vcl::Window> pNewWindow;
1388 WindowType nType = ImplGetComponentType( aServiceName );
1389 bool bFrameControl = false;
1390 if ( aServiceName == "frame" )
1391 bFrameControl = true;
1392 if ( aServiceName == "tabcontrolnotabs" )
1394 nWinBits |= WB_NOBORDER;
1395 nType = ImplGetComponentType( "tabcontrol" );
1397 if ( !pParent )
1399 // If the component needs a parent, then return NULL,
1400 // some time later css::uno::Exception...
1401 bool bException = true;
1402 if ( ( nType == WindowType::DIALOG )
1403 || ( nType == WindowType::MODELESSDIALOG )
1404 || ( nType == WindowType::MESSBOX )
1405 || ( nType == WindowType::INFOBOX )
1406 || ( nType == WindowType::WARNINGBOX )
1407 || ( nType == WindowType::ERRORBOX )
1408 || ( nType == WindowType::QUERYBOX )
1410 bException = false;
1411 else if ( ( nType == WindowType::WINDOW ) ||
1412 ( nType == WindowType::WORKWINDOW ) ||
1413 ( nType == WindowType::TOOLKIT_FRAMEWINDOW ) )
1415 if ( rDescriptor.Type == css::awt::WindowClass_TOP )
1416 bException = false;
1419 if ( bException )
1421 *ppNewComp = nullptr;
1422 return nullptr;
1426 if ( nType != WindowType::NONE )
1428 SolarMutexGuard aVclGuard;
1429 switch ( nType )
1431 case WindowType::CANCELBUTTON:
1432 pNewWindow = VclPtr<CancelButton>::Create( pParent, nWinBits );
1433 *ppNewComp = new VCLXButton;
1434 break;
1435 case WindowType::CHECKBOX:
1436 pNewWindow = VclPtr<CheckBox>::Create( pParent, nWinBits );
1437 *ppNewComp = new VCLXCheckBox;
1438 break;
1439 case WindowType::COMBOBOX:
1440 pNewWindow = VclPtr<ComboBox>::Create( pParent, nWinBits|WB_AUTOHSCROLL );
1441 static_cast<ComboBox*>(pNewWindow.get())->EnableAutoSize( false );
1442 *ppNewComp = new VCLXComboBox;
1443 break;
1444 case WindowType::CURRENCYBOX:
1445 pNewWindow = VclPtr<CurrencyBox>::Create( pParent, nWinBits );
1446 break;
1447 case WindowType::CURRENCYFIELD:
1448 pNewWindow = VclPtr<CurrencyField>::Create( pParent, nWinBits );
1449 static_cast<CurrencyField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1450 *ppNewComp = new VCLXNumericField;
1451 static_cast<VCLXFormattedSpinField*>((*ppNewComp).get())->SetFormatter( static_cast<FormatterBase*>(static_cast<CurrencyField*>(pNewWindow.get())) );
1452 break;
1453 case WindowType::DATEBOX:
1454 pNewWindow = VclPtr<DateBox>::Create( pParent, nWinBits );
1455 break;
1456 case WindowType::DOCKINGAREA:
1457 pNewWindow = VclPtr<DockingAreaWindow>::Create( pParent );
1458 break;
1459 case WindowType::MULTILINEEDIT:
1460 pNewWindow = VclPtr<MultiLineEdit>::Create(pParent, nWinBits|WB_IGNORETAB);
1461 static_cast<MultiLineEdit*>(pNewWindow.get())->DisableSelectionOnFocus();
1462 *ppNewComp = new VCLXMultiLineEdit;
1463 break;
1464 case WindowType::EDIT:
1465 pNewWindow = VclPtr<Edit>::Create( pParent, nWinBits );
1466 *ppNewComp = new VCLXEdit;
1467 break;
1468 case WindowType::ERRORBOX:
1469 pNewWindow = VclPtr<ErrorBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1470 *ppNewComp = new VCLXMessageBox;
1471 break;
1472 case WindowType::FIXEDBITMAP:
1473 pNewWindow = VclPtr<FixedBitmap>::Create( pParent, nWinBits );
1474 break;
1475 case WindowType::FIXEDIMAGE:
1476 pNewWindow = VclPtr<ImageControl>::Create( pParent, nWinBits );
1477 *ppNewComp = new VCLXImageControl;
1478 break;
1479 case WindowType::FIXEDLINE:
1480 pNewWindow = VclPtr<FixedLine>::Create( pParent, nWinBits );
1481 break;
1482 case WindowType::FIXEDTEXT:
1483 pNewWindow = VclPtr<FixedText>::Create( pParent, nWinBits );
1484 *ppNewComp = new VCLXFixedText;
1485 break;
1486 case WindowType::FLOATINGWINDOW:
1487 pNewWindow = VclPtr<FloatingWindow>::Create( pParent, nWinBits );
1488 break;
1489 case WindowType::GROUPBOX:
1490 pNewWindow = VclPtr<GroupBox>::Create( pParent, nWinBits );
1491 if ( bFrameControl )
1493 GroupBox* pGroupBox = static_cast< GroupBox* >( pNewWindow.get() );
1494 *ppNewComp = new VCLXFrame;
1495 // Frame control needs to receive
1496 // Mouse events
1497 pGroupBox->SetMouseTransparent( false );
1499 break;
1500 case WindowType::HELPBUTTON:
1501 pNewWindow = VclPtr<HelpButton>::Create( pParent, nWinBits );
1502 *ppNewComp = new VCLXButton;
1503 break;
1504 case WindowType::IMAGEBUTTON:
1505 pNewWindow = VclPtr<ImageButton>::Create( pParent, nWinBits );
1506 *ppNewComp = new VCLXButton;
1507 break;
1508 case WindowType::INFOBOX:
1509 pNewWindow = VclPtr<InfoBox>::Create( pParent, OUString() );
1510 *ppNewComp = new VCLXMessageBox;
1511 break;
1512 case WindowType::LISTBOX:
1513 pNewWindow = VclPtr<ListBox>::Create( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL );
1514 static_cast<ListBox*>(pNewWindow.get())->EnableAutoSize( false );
1515 *ppNewComp = new VCLXListBox;
1516 break;
1517 case WindowType::LONGCURRENCYBOX:
1518 pNewWindow = VclPtr<LongCurrencyBox>::Create( pParent, nWinBits );
1519 break;
1520 case WindowType::MENUBUTTON:
1521 pNewWindow = VclPtr<MenuButton>::Create( pParent, nWinBits );
1522 *ppNewComp = new VCLXButton;
1523 break;
1524 case WindowType::MESSBOX:
1525 pNewWindow = VclPtr<MessBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString(), OUString() );
1526 *ppNewComp = new VCLXMessageBox;
1527 break;
1528 case WindowType::METRICBOX:
1529 pNewWindow = VclPtr<MetricBox>::Create( pParent, nWinBits );
1530 break;
1531 case WindowType::METRICFIELD:
1532 pNewWindow = VclPtr<MetricField>::Create( pParent, nWinBits );
1533 *ppNewComp = new VCLXMetricField;
1534 static_cast<VCLXFormattedSpinField*>((*ppNewComp).get())->SetFormatter( static_cast<FormatterBase*>(static_cast<MetricField*>(pNewWindow.get())) );
1535 break;
1536 case WindowType::DIALOG:
1537 case WindowType::MODELESSDIALOG:
1539 // Modal/Modeless only via Show/Execute
1540 if ( (pParent == nullptr ) && ( rDescriptor.ParentIndex == -1 ) )
1541 pNewWindow = VclPtr<toolkit::ScrollableDialog>::Create( nullptr, nWinBits, Dialog::InitFlag::NoParent );
1542 else
1543 pNewWindow = VclPtr<toolkit::ScrollableDialog>::Create( pParent, nWinBits );
1544 // #i70217# Don't always create a new component object. It's possible that VCL has called
1545 // GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() )
1546 // which creates a component object.
1547 css::uno::Reference< css::awt::XWindowPeer > xWinPeer = pNewWindow->GetComponentInterface( false );
1548 if ( xWinPeer.is() )
1549 *ppNewComp = dynamic_cast< VCLXDialog* >( xWinPeer.get() );
1550 else
1551 *ppNewComp = new VCLXDialog;
1553 break;
1554 case WindowType::MOREBUTTON:
1555 pNewWindow = VclPtr<MoreButton>::Create( pParent, nWinBits );
1556 *ppNewComp = new VCLXButton;
1557 break;
1558 case WindowType::MULTILISTBOX:
1559 pNewWindow = VclPtr<MultiListBox>::Create( pParent, nWinBits );
1560 *ppNewComp = new VCLXListBox;
1561 break;
1562 case WindowType::NUMERICBOX:
1563 pNewWindow = VclPtr<NumericBox>::Create( pParent, nWinBits );
1564 break;
1565 case WindowType::OKBUTTON:
1566 pNewWindow = VclPtr<OKButton>::Create( pParent, nWinBits );
1567 *ppNewComp = new VCLXButton;
1568 break;
1569 case WindowType::PATTERNBOX:
1570 pNewWindow = VclPtr<PatternBox>::Create( pParent, nWinBits );
1571 break;
1572 case WindowType::PATTERNFIELD:
1573 pNewWindow = VclPtr<PatternField>::Create( pParent, nWinBits );
1574 *ppNewComp = new VCLXPatternField;
1575 static_cast<VCLXFormattedSpinField*>((*ppNewComp).get())->SetFormatter( static_cast<FormatterBase*>(static_cast<PatternField*>(pNewWindow.get())) );
1576 break;
1577 case WindowType::PUSHBUTTON:
1578 pNewWindow = VclPtr<PushButton>::Create( pParent, nWinBits );
1579 *ppNewComp = new VCLXButton;
1580 break;
1581 case WindowType::QUERYBOX:
1582 pNewWindow = VclPtr<QueryBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1583 *ppNewComp = new VCLXMessageBox;
1584 break;
1585 case WindowType::RADIOBUTTON:
1586 pNewWindow = VclPtr<RadioButton>::Create(pParent, false, nWinBits);
1587 *ppNewComp = new VCLXRadioButton;
1589 // by default, disable RadioCheck
1590 // Since the VCLXRadioButton really cares for its RadioCheck settings, this is important:
1591 // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState
1592 // This leads to a strange behaviour if the control is newly created: when settings the initial
1593 // state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck
1594 // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls
1595 // is not really valid: the controls are grouped after they have been created, but we're still in
1596 // the creation process, so the RadioButton::Check relies on invalid grouping information.
1597 // 07.08.2001 - #87254# - frank.schoenheit@sun.com
1598 static_cast<RadioButton*>(pNewWindow.get())->EnableRadioCheck( false );
1599 break;
1600 case WindowType::SCROLLBAR:
1601 pNewWindow = VclPtr<ScrollBar>::Create( pParent, nWinBits );
1602 *ppNewComp = new VCLXScrollBar;
1603 break;
1604 case WindowType::SCROLLBARBOX:
1605 pNewWindow = VclPtr<ScrollBarBox>::Create( pParent, nWinBits );
1606 break;
1607 case WindowType::SPINBUTTON:
1608 pNewWindow = VclPtr<SpinButton>::Create( pParent, nWinBits );
1609 *ppNewComp = new ::toolkit::VCLXSpinButton;
1610 break;
1611 case WindowType::SPINFIELD:
1612 pNewWindow = VclPtr<SpinField>::Create( pParent, nWinBits );
1613 *ppNewComp = new VCLXNumericField;
1614 break;
1615 case WindowType::SPLITTER:
1616 pNewWindow = VclPtr<Splitter>::Create( pParent, nWinBits );
1617 break;
1618 case WindowType::SPLITWINDOW:
1619 pNewWindow = VclPtr<SplitWindow>::Create( pParent, nWinBits );
1620 break;
1621 case WindowType::STATUSBAR:
1622 pNewWindow = VclPtr<StatusBar>::Create( pParent, nWinBits );
1623 break;
1624 case WindowType::TOOLKIT_SYSTEMCHILDWINDOW:
1625 pNewWindow = VclPtr<SystemChildWindow>::Create( pParent, nWinBits );
1626 *ppNewComp = new VCLXSystemDependentWindow();
1627 break;
1628 case WindowType::TABCONTROL:
1629 pNewWindow = VclPtr<TabControl>::Create( pParent, nWinBits );
1630 *ppNewComp = new VCLXMultiPage;
1631 break;
1632 case WindowType::TABDIALOG:
1633 pNewWindow = VclPtr<TabDialog>::Create( pParent, nWinBits );
1634 break;
1635 case WindowType::TABPAGE:
1637 pNewWindow = VclPtr<TabPage>::Create( pParent, nWinBits );
1638 *ppNewComp = new VCLXTabPage;
1640 break;
1641 case WindowType::TIMEBOX:
1642 pNewWindow = VclPtr<TimeBox>::Create( pParent, nWinBits );
1643 break;
1644 case WindowType::TIMEFIELD:
1645 pNewWindow = VclPtr<TimeField>::Create( pParent, nWinBits );
1646 static_cast<TimeField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1647 *ppNewComp = new VCLXTimeField;
1648 static_cast<VCLXFormattedSpinField*>((*ppNewComp).get())->SetFormatter( static_cast<FormatterBase*>(static_cast<TimeField*>(pNewWindow.get())) );
1649 break;
1650 case WindowType::TOOLBOX:
1651 pNewWindow = VclPtr<ToolBox>::Create( pParent, nWinBits );
1652 *ppNewComp = new VCLXToolBox;
1653 break;
1654 case WindowType::TRISTATEBOX:
1655 pNewWindow = VclPtr<CheckBox>::Create( pParent, nWinBits );
1656 static_cast<CheckBox*>(pNewWindow.get())->EnableTriState(true);
1657 break;
1658 case WindowType::WARNINGBOX:
1659 pNewWindow = VclPtr<WarningBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1660 *ppNewComp = new VCLXMessageBox;
1661 break;
1662 case WindowType::WORKWINDOW:
1663 case WindowType::WINDOW:
1664 case WindowType::TOOLKIT_FRAMEWINDOW:
1665 case WindowType::DOCKINGWINDOW:
1666 if ( rDescriptor.Type == css::awt::WindowClass_TOP )
1668 if (nType == WindowType::DOCKINGWINDOW )
1669 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1670 else
1672 if ((pParent == nullptr) && rDescriptor.Parent.is())
1674 // try to get a system dependent window handle
1675 css::uno::Reference< css::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, css::uno::UNO_QUERY);
1677 if (xSystemDepParent.is())
1679 sal_Int8 processID[16];
1681 rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8*>(processID) );
1683 // coverity[overrun-buffer-arg : FALSE] - coverity has difficulty with css::uno::Sequence
1684 css::uno::Sequence<sal_Int8> processIdSeq(processID, 16);
1686 css::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPE);
1688 // use sal_Int64 here to accommodate all int types
1689 // uno::Any shift operator will upcast if necessary
1690 sal_Int64 nWindowHandle = 0;
1691 bool bXEmbed = false;
1693 bool bUseParentData = true;
1694 if( ! (anyHandle >>= nWindowHandle) )
1696 css::uno::Sequence< css::beans::NamedValue > aProps;
1697 if( anyHandle >>= aProps )
1699 for( const css::beans::NamedValue& rProp : std::as_const(aProps) )
1701 if ( rProp.Name == "WINDOW" )
1702 rProp.Value >>= nWindowHandle;
1703 else if ( rProp.Name == "XEMBED" )
1704 rProp.Value >>= bXEmbed;
1707 else
1708 bUseParentData = false;
1711 if( bUseParentData )
1713 SystemParentData aParentData;
1714 aParentData.nSize = sizeof( aParentData );
1715 #if defined MACOSX
1716 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
1717 #elif defined ANDROID
1718 // Nothing
1719 #elif defined IOS
1720 // Nothing
1721 #elif defined UNX
1722 aParentData.aWindow = nWindowHandle;
1723 aParentData.bXEmbedSupport = bXEmbed;
1724 #elif defined _WIN32
1725 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1726 #endif
1727 pNewWindow = VclPtr<WorkWindow>::Create( &aParentData );
1732 if (!pNewWindow)
1733 pNewWindow = VclPtr<WorkWindow>::Create( pParent, nWinBits );
1736 *ppNewComp = new VCLXTopWindow();
1738 else if ( rDescriptor.Type == css::awt::WindowClass_CONTAINER )
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 VCLXContainer;
1746 else
1748 if (nType == WindowType::DOCKINGWINDOW )
1749 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1750 else
1751 pNewWindow = VclPtr<vcl::Window>::Create( pParent, nWinBits );
1752 *ppNewComp = new VCLXWindow;
1754 break;
1755 case WindowType::CONTROL:
1756 if ( aServiceName == "tabpagecontainer" )
1758 // TabControl has a special case for tabs without border: they are displayed
1759 // in a different way, so we need to ensure that this style is not set, so
1760 // we can guarantee normal tab behavior
1761 pNewWindow = VclPtr<TabControl>::Create( pParent, nWinBits & (~WB_NOBORDER));
1762 *ppNewComp = new VCLXTabPageContainer;
1764 else if ( aServiceName == "animatedimages" )
1766 pNewWindow = VclPtr<Throbber>::Create( pParent, nWinBits );
1767 *ppNewComp = new ::toolkit::AnimatedImagesPeer;
1769 else if (aServiceName == "roadmap")
1771 pNewWindow = VclPtr<::vcl::ORoadmap>::Create( pParent, WB_TABSTOP );
1772 *ppNewComp = new SVTXRoadmap;
1774 else if (aServiceName == "fixedhyperlink")
1776 pNewWindow = VclPtr<FixedHyperlink>::Create( pParent, nWinBits );
1777 *ppNewComp = new VCLXFixedHyperlink;
1779 else if (aServiceName == "progressbar")
1781 pNewWindow = VclPtr<ProgressBar>::Create( pParent, nWinBits );
1782 *ppNewComp = new VCLXProgressBar;
1784 else if (aServiceName == "filecontrol")
1786 pNewWindow = VclPtr<FileControl>::Create( pParent, nWinBits );
1787 *ppNewComp = new VCLXFileControl;
1789 else if (aServiceName == "tree")
1791 rtl::Reference<TreeControlPeer> pPeer = new TreeControlPeer;
1792 *ppNewComp = pPeer;
1793 pNewWindow = pPeer->createVclControl( pParent, nWinBits );
1795 else if (aServiceName == "formattedfield")
1797 pNewWindow = VclPtr<FormattedField>::Create( pParent, nWinBits );
1798 *ppNewComp = new SVTXFormattedField;
1800 else if (aServiceName == "numericfield")
1802 pNewWindow = VclPtr<DoubleNumericField>::Create( pParent, nWinBits );
1803 *ppNewComp = new SVTXNumericField;
1805 else if (aServiceName == "longcurrencyfield")
1807 pNewWindow = VclPtr<DoubleCurrencyField>::Create( pParent, nWinBits );
1808 *ppNewComp = new SVTXCurrencyField;
1810 else if (aServiceName == "datefield")
1812 pNewWindow = VclPtr<CalendarField>::Create(pParent, nWinBits);
1813 static_cast<CalendarField*>(pNewWindow.get())->EnableToday();
1814 static_cast<CalendarField*>(pNewWindow.get())->EnableNone();
1815 static_cast<CalendarField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1816 rtl::Reference<SVTXDateField> newComp = new SVTXDateField;
1817 *ppNewComp = newComp;
1818 newComp->SetFormatter( static_cast<FormatterBase*>(static_cast<DateField*>(pNewWindow.get())) );
1820 else if (aServiceName == "grid")
1822 pNewWindow = VclPtr<::svt::table::TableControl>::Create(pParent, nWinBits);
1823 *ppNewComp = new SVTXGridControl;
1825 break;
1826 default:
1827 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" );
1828 break;
1832 // tdf#126717 default that formcontrols show accelerators
1833 if (Control* pControl = dynamic_cast<Control*>(pNewWindow.get()))
1834 pControl->SetShowAccelerator(true);
1835 return pNewWindow;
1838 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow(
1839 const css::awt::WindowDescriptor& rDescriptor,
1840 MessBoxStyle nForceMessBoxStyle )
1842 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1844 SolarMutexGuard aSolarGuard;
1846 css::uno::Reference< css::awt::XVclWindowPeer > xRef;
1848 VclPtr<vcl::Window> pParent;
1849 if ( rDescriptor.Parent.is() )
1851 VCLXWindow* pParentComponent = dynamic_cast<VCLXWindow*>( rDescriptor.Parent.get() );
1853 // #103939# Don't throw assertion, may be it's a system dependent window, used in ImplCreateWindow.
1854 // DBG_ASSERT( pParentComponent, "ParentComponent not valid" );
1856 if ( pParentComponent )
1857 pParent = pParentComponent->GetWindow();
1859 std::pair<WinBits, MessBoxStyle> aPair = ImplGetWinBits( rDescriptor.WindowAttributes,
1860 ImplGetComponentType( rDescriptor.WindowServiceName ) );
1861 WinBits nWinBits = aPair.first;
1862 aPair.second |= nForceMessBoxStyle;
1864 rtl::Reference<VCLXWindow> pNewComp;
1866 vcl::Window* pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits, aPair.second );
1868 DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" );
1869 SAL_INFO_IF( !pNewComp, "toolkit", "createWindow: No special Interface!" );
1871 if ( pNewWindow )
1873 pNewWindow->SetCreatedWithToolkit( true );
1874 //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead
1876 if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::MINSIZE )
1878 pNewWindow->SetSizePixel( Size() );
1880 else if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::FULLSIZE )
1882 if ( pParent )
1883 pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() );
1885 else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) )
1887 tools::Rectangle aRect = VCLRectangle( rDescriptor.Bounds );
1888 pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
1891 if ( !pNewComp )
1893 // Default-Interface
1894 xRef = pNewWindow->GetComponentInterface();
1896 else
1898 xRef = pNewComp;
1899 pNewWindow->SetComponentInterface( xRef );
1901 DBG_ASSERT( pNewWindow->GetComponentInterface( false ) == xRef,
1902 "VCLXToolkit::createWindow: did #133706# resurge?" );
1904 if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::SHOW )
1905 pNewWindow->Show();
1908 return xRef;
1911 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > VCLXToolkit::createWindows( const css::uno::Sequence< css::awt::WindowDescriptor >& rDescriptors )
1913 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1915 sal_uInt32 nComponents = rDescriptors.getLength();
1916 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > aSeq( nComponents );
1917 for ( sal_uInt32 n = 0; n < nComponents; n++ )
1919 css::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n];
1921 if ( aDescr.ParentIndex == -1 )
1922 aDescr.Parent = nullptr;
1923 else if ( ( aDescr.ParentIndex >= 0 ) && ( o3tl::make_unsigned(aDescr.ParentIndex) < n ) )
1924 aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex];
1925 aSeq.getArray()[n] = createWindow( aDescr );
1927 return aSeq;
1930 // css::awt::XSystemChildFactory
1931 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::createSystemChild( const css::uno::Any& Parent, const css::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 nSystemType )
1933 VclPtr<vcl::Window> pChildWindow;
1934 if ( nSystemType == SYSTEM_DEPENDENT_TYPE )
1936 // use sal_Int64 here to accommodate all int types
1937 // uno::Any shift operator will upcast if necessary
1938 sal_Int64 nWindowHandle = 0;
1939 bool bXEmbed = false;
1941 bool bUseParentData = true;
1942 if( ! (Parent >>= nWindowHandle) )
1944 css::uno::Sequence< css::beans::NamedValue > aProps;
1945 if( Parent >>= aProps )
1947 for( const css::beans::NamedValue& rProp : std::as_const(aProps) )
1949 if ( rProp.Name == "WINDOW" )
1950 rProp.Value >>= nWindowHandle;
1951 else if ( rProp.Name == "XEMBED" )
1952 rProp.Value >>= bXEmbed;
1955 else
1956 bUseParentData = false;
1959 if( bUseParentData )
1961 SystemParentData aParentData;
1962 aParentData.nSize = sizeof( aParentData );
1963 #if defined MACOSX
1964 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
1965 #elif defined ANDROID
1966 // Nothing
1967 #elif defined IOS
1968 // Nothing
1969 #elif defined UNX
1970 aParentData.aWindow = nWindowHandle;
1971 aParentData.bXEmbedSupport = bXEmbed;
1972 #elif defined _WIN32
1973 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1974 #endif
1975 SolarMutexGuard aGuard;
1978 pChildWindow.reset( VclPtr<WorkWindow>::Create( &aParentData ) );
1980 catch ( const css::uno::RuntimeException & )
1982 // system child window could not be created
1983 DBG_UNHANDLED_EXCEPTION("toolkit");
1984 pChildWindow.clear();
1988 else if (nSystemType == css::lang::SystemDependent::SYSTEM_JAVA)
1990 SolarMutexGuard aGuard;
1991 pChildWindow.reset(VclPtr<WorkWindow>::Create(nullptr, Parent));
1994 css::uno::Reference< css::awt::XVclWindowPeer > xPeer;
1995 if ( pChildWindow )
1997 rtl::Reference<VCLXTopWindow> pPeer = new VCLXTopWindow;
1998 SolarMutexGuard aGuard;
1999 pPeer->SetWindow( pChildWindow );
2000 xPeer = pPeer;
2001 pChildWindow->SetWindowPeer(xPeer, pPeer.get());
2004 return xPeer;
2007 // css::awt::XMessageBoxFactory
2008 css::uno::Reference< css::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox(
2009 const css::uno::Reference< css::awt::XWindowPeer >& aParent,
2010 css::awt::MessageBoxType eType,
2011 ::sal_Int32 aButtons,
2012 const OUString& aTitle,
2013 const OUString& aMessage )
2015 css::awt::WindowDescriptor aDescriptor;
2017 sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE;
2019 // Map button definitions to window attributes
2020 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK )
2021 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK;
2022 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL )
2023 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL;
2024 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO )
2025 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO;
2026 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL )
2027 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL;
2028 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL )
2029 nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL;
2031 // Map default button definitions to window attributes
2032 if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK )
2033 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK;
2034 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL )
2035 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL;
2036 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES )
2037 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES;
2038 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO )
2039 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO;
2040 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY )
2041 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY;
2043 // No more bits for VclWindowPeerAttribute possible. Mapping must be
2044 // done explicitly using VCL methods
2045 MessBoxStyle nAddWinBits = MessBoxStyle::NONE;
2046 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY )
2047 nAddWinBits |= MessBoxStyle::AbortRetryIgnore;
2048 if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE )
2049 nAddWinBits |= MessBoxStyle::DefaultIgnore;
2051 OUString aType;
2052 lcl_convertMessageBoxType( aType, eType );
2054 aDescriptor.Type = css::awt::WindowClass_MODALTOP;
2055 aDescriptor.WindowServiceName = aType;
2056 aDescriptor.ParentIndex = -1;
2057 aDescriptor.Parent = aParent;
2058 aDescriptor.WindowAttributes = nWindowAttributes;
2059 css::uno::Reference< css::awt::XMessageBox > xMsgBox(
2060 ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY );
2061 css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY );
2062 if ( xMsgBox.is() && xWindow.is() )
2064 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2065 if ( pWindow )
2067 SolarMutexGuard aGuard;
2068 xMsgBox->setCaptionText( aTitle );
2069 xMsgBox->setMessageText( aMessage );
2073 return xMsgBox;
2076 css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL VCLXToolkit::getDragGestureRecognizer( const css::uno::Reference< css::awt::XWindow >& window )
2078 SolarMutexGuard g;
2080 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
2082 if( pWindow )
2083 return pWindow->GetDragGestureRecognizer();
2085 return css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer >();
2088 css::uno::Reference< css::datatransfer::dnd::XDragSource > SAL_CALL VCLXToolkit::getDragSource( const css::uno::Reference< css::awt::XWindow >& window )
2090 SolarMutexGuard g;
2092 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
2094 if( pWindow )
2095 return pWindow->GetDragSource();
2097 return css::uno::Reference< css::datatransfer::dnd::XDragSource >();
2100 css::uno::Reference< css::datatransfer::dnd::XDropTarget > SAL_CALL VCLXToolkit::getDropTarget( const css::uno::Reference< css::awt::XWindow >& window )
2102 SolarMutexGuard g;
2104 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
2106 if( pWindow )
2107 return pWindow->GetDropTarget();
2109 return css::uno::Reference< css::datatransfer::dnd::XDropTarget >();
2112 css::uno::Reference< css::datatransfer::clipboard::XClipboard > SAL_CALL VCLXToolkit::getClipboard( const OUString& clipboardName )
2114 if( clipboardName.isEmpty() )
2116 if( !mxClipboard.is() )
2118 // remember clipboard here
2119 mxClipboard = css::datatransfer::clipboard::SystemClipboard::create(
2120 comphelper::getProcessComponentContext());
2123 return mxClipboard;
2126 else if( clipboardName == "Selection" )
2128 return mxSelection;
2131 return css::uno::Reference< css::datatransfer::clipboard::XClipboard >();
2134 // XServiceInfo
2135 OUString VCLXToolkit::getImplementationName()
2137 return "stardiv.Toolkit.VCLXToolkit";
2140 sal_Bool VCLXToolkit::supportsService( const OUString& rServiceName )
2142 return cppu::supportsService(this, rServiceName);
2145 css::uno::Sequence< OUString > VCLXToolkit::getSupportedServiceNames()
2147 return css::uno::Sequence<OUString>{
2148 "com.sun.star.awt.Toolkit", "stardiv.vcl.VclToolkit"};
2151 // css::awt::XExtendedToolkit:
2153 // virtual
2154 ::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount()
2156 return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount());
2157 // XXX numeric overflow
2160 // virtual
2161 css::uno::Reference< css::awt::XTopWindow > SAL_CALL
2162 VCLXToolkit::getTopWindow(::sal_Int32 nIndex)
2164 vcl::Window * p = ::Application::GetTopWindow(static_cast< tools::Long >(nIndex));
2165 // XXX numeric overflow
2166 return css::uno::Reference< css::awt::XTopWindow >(
2167 p == nullptr ? nullptr : static_cast< css::awt::XWindow * >(p->GetWindowPeer()),
2168 css::uno::UNO_QUERY);
2171 // virtual
2172 css::uno::Reference< css::awt::XTopWindow > SAL_CALL
2173 VCLXToolkit::getActiveTopWindow()
2175 vcl::Window * p = ::Application::GetActiveTopWindow();
2176 return css::uno::Reference< css::awt::XTopWindow >(
2177 p == nullptr ? nullptr : static_cast< css::awt::XWindow * >(p->GetWindowPeer()),
2178 css::uno::UNO_QUERY);
2181 // virtual
2182 void SAL_CALL VCLXToolkit::addTopWindowListener(
2183 css::uno::Reference< css::awt::XTopWindowListener > const & rListener)
2185 OSL_ENSURE(rListener.is(), "Null rListener");
2186 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
2187 if (rBHelper.bDisposed || rBHelper.bInDispose)
2189 aGuard.clear();
2190 rListener->disposing(
2191 css::lang::EventObject(
2192 static_cast< ::cppu::OWeakObject * >(this)));
2194 else if (m_aTopWindowListeners.addInterface(rListener) == 1
2195 && !m_bEventListener)
2197 m_bEventListener = true;
2198 ::Application::AddEventListener(m_aEventListenerLink);
2202 // virtual
2203 void SAL_CALL VCLXToolkit::removeTopWindowListener(
2204 css::uno::Reference< css::awt::XTopWindowListener > const & rListener)
2206 ::osl::MutexGuard aGuard(rBHelper.rMutex);
2207 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
2208 && m_aTopWindowListeners.removeInterface(rListener) == 0
2209 && m_aFocusListeners.getLength() == 0 && m_bEventListener)
2211 ::Application::RemoveEventListener(m_aEventListenerLink);
2212 m_bEventListener = false;
2216 // virtual
2217 void SAL_CALL VCLXToolkit::addKeyHandler(
2218 css::uno::Reference< css::awt::XKeyHandler > const & rHandler)
2220 OSL_ENSURE(rHandler.is(), "Null rHandler");
2221 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
2222 if (rBHelper.bDisposed || rBHelper.bInDispose)
2224 aGuard.clear();
2225 rHandler->disposing(
2226 css::lang::EventObject(
2227 static_cast< ::cppu::OWeakObject * >(this)));
2229 else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener)
2231 m_bKeyListener = true;
2232 ::Application::AddKeyListener(m_aKeyListenerLink);
2236 // virtual
2237 void SAL_CALL VCLXToolkit::removeKeyHandler(
2238 css::uno::Reference< css::awt::XKeyHandler > const & rHandler)
2240 ::osl::MutexGuard aGuard(rBHelper.rMutex);
2241 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
2242 && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener)
2244 ::Application::RemoveKeyListener(m_aKeyListenerLink);
2245 m_bKeyListener = false;
2249 // virtual
2250 void SAL_CALL VCLXToolkit::addFocusListener(
2251 css::uno::Reference< css::awt::XFocusListener > const & rListener)
2253 OSL_ENSURE(rListener.is(), "Null rListener");
2254 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
2255 if (rBHelper.bDisposed || rBHelper.bInDispose)
2257 aGuard.clear();
2258 rListener->disposing(
2259 css::lang::EventObject(
2260 static_cast< ::cppu::OWeakObject * >(this)));
2262 else if (m_aFocusListeners.addInterface(rListener) == 1
2263 && !m_bEventListener)
2265 m_bEventListener = true;
2266 ::Application::AddEventListener(m_aEventListenerLink);
2270 // virtual
2271 void SAL_CALL VCLXToolkit::removeFocusListener(
2272 css::uno::Reference< css::awt::XFocusListener > const & rListener)
2274 ::osl::MutexGuard aGuard(rBHelper.rMutex);
2275 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
2276 && m_aFocusListeners.removeInterface(rListener) == 0
2277 && m_aTopWindowListeners.getLength() == 0 && m_bEventListener)
2279 ::Application::RemoveEventListener(m_aEventListenerLink);
2280 m_bEventListener = false;
2284 // virtual
2285 void SAL_CALL VCLXToolkit::fireFocusGained(
2286 css::uno::Reference<
2287 css::uno::XInterface > const &)
2291 // virtual
2292 void SAL_CALL VCLXToolkit::fireFocusLost(
2293 css::uno::Reference<
2294 css::uno::XInterface > const &)
2299 IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent&, rEvent, void)
2301 switch (rEvent.GetId())
2303 case VclEventId::WindowShow:
2304 callTopWindowListeners(
2305 &rEvent, &css::awt::XTopWindowListener::windowOpened);
2306 break;
2307 case VclEventId::WindowHide:
2308 callTopWindowListeners(
2309 &rEvent, &css::awt::XTopWindowListener::windowClosed);
2310 break;
2311 case VclEventId::WindowActivate:
2312 callTopWindowListeners(
2313 &rEvent, &css::awt::XTopWindowListener::windowActivated);
2314 break;
2315 case VclEventId::WindowDeactivate:
2316 callTopWindowListeners(
2317 &rEvent, &css::awt::XTopWindowListener::windowDeactivated);
2318 break;
2319 case VclEventId::WindowClose:
2320 callTopWindowListeners(
2321 &rEvent, &css::awt::XTopWindowListener::windowClosing);
2322 break;
2323 case VclEventId::WindowGetFocus:
2324 callFocusListeners(&rEvent, true);
2325 break;
2326 case VclEventId::WindowLoseFocus:
2327 callFocusListeners(&rEvent, false);
2328 break;
2329 case VclEventId::WindowMinimize:
2330 callTopWindowListeners(
2331 &rEvent, &css::awt::XTopWindowListener::windowMinimized);
2332 break;
2333 case VclEventId::WindowNormalize:
2334 callTopWindowListeners(
2335 &rEvent, &css::awt::XTopWindowListener::windowNormalized);
2336 break;
2337 default: break;
2341 IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclWindowEvent&, rEvent, bool)
2343 switch (rEvent.GetId())
2345 case VclEventId::WindowKeyInput:
2346 return callKeyHandlers(&rEvent, true);
2347 case VclEventId::WindowKeyUp:
2348 return callKeyHandlers(&rEvent, false);
2349 default: break;
2351 return false;
2354 void VCLXToolkit::callTopWindowListeners(
2355 ::VclSimpleEvent const * pEvent,
2356 void (SAL_CALL css::awt::XTopWindowListener::* pFn)(
2357 css::lang::EventObject const &))
2359 vcl::Window * pWindow
2360 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2361 if (!pWindow->IsTopWindow())
2362 return;
2364 std::vector< css::uno::Reference< css::awt::XTopWindowListener > >
2365 aListeners(m_aTopWindowListeners.getElements());
2366 if (aListeners.empty())
2367 return;
2369 css::lang::EventObject aAwtEvent(
2370 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()));
2371 for (const css::uno::Reference<css::awt::XTopWindowListener> & xListener : aListeners)
2375 (xListener.get()->*pFn)(aAwtEvent);
2377 catch (const css::uno::RuntimeException &)
2379 DBG_UNHANDLED_EXCEPTION("toolkit");
2384 bool VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent,
2385 bool bPressed)
2387 std::vector< css::uno::Reference< css::awt::XKeyHandler > >
2388 aHandlers(m_aKeyHandlers.getElements());
2390 if (!aHandlers.empty())
2392 vcl::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2394 // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event
2395 ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >(
2396 static_cast< ::VclWindowEvent const * >(pEvent)->GetData());
2397 css::awt::KeyEvent aAwtEvent(
2398 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
2399 (pKeyEvent->GetKeyCode().IsShift()
2400 ? css::awt::KeyModifier::SHIFT : 0)
2401 | (pKeyEvent->GetKeyCode().IsMod1()
2402 ? css::awt::KeyModifier::MOD1 : 0)
2403 | (pKeyEvent->GetKeyCode().IsMod2()
2404 ? css::awt::KeyModifier::MOD2 : 0)
2405 | (pKeyEvent->GetKeyCode().IsMod3()
2406 ? css::awt::KeyModifier::MOD3 : 0),
2407 pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(),
2408 sal::static_int_cast< sal_Int16 >(
2409 pKeyEvent->GetKeyCode().GetFunction()));
2410 for (const css::uno::Reference<css::awt::XKeyHandler> & xHandler : aHandlers)
2414 if (bPressed ? xHandler->keyPressed(aAwtEvent)
2415 : xHandler->keyReleased(aAwtEvent))
2416 return true;
2418 catch (const css::uno::RuntimeException &)
2420 DBG_UNHANDLED_EXCEPTION("toolkit");
2424 return false;
2427 void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent,
2428 bool bGained)
2430 vcl::Window * pWindow
2431 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2432 if (!pWindow->IsTopWindow())
2433 return;
2435 std::vector< css::uno::Reference< css::awt::XFocusListener > >
2436 aListeners(m_aFocusListeners.getElements());
2437 if (aListeners.empty())
2438 return;
2440 // Ignore the interior of compound controls when determining the
2441 // window that gets the focus next (see implementation in
2442 // vclxwindow.cxx for mapping between VCL and UNO AWT event):
2443 css::uno::Reference< css::uno::XInterface > xNext;
2444 vcl::Window * pFocus = ::Application::GetFocusWindow();
2445 for (vcl::Window * p = pFocus; p != nullptr; p = p->GetParent())
2446 if (!p->IsCompoundControl())
2448 pFocus = p;
2449 break;
2451 if (pFocus != nullptr)
2452 xNext = pFocus->GetComponentInterface();
2453 css::awt::FocusEvent aAwtEvent(
2454 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
2455 static_cast<sal_Int16>(pWindow->GetGetFocusFlags()),
2456 xNext, false);
2457 for (const css::uno::Reference<css::awt::XFocusListener> & xListener : aListeners)
2461 bGained ? xListener->focusGained(aAwtEvent)
2462 : xListener->focusLost(aAwtEvent);
2464 catch (const css::uno::RuntimeException &)
2466 DBG_UNHANDLED_EXCEPTION("toolkit");
2471 // css::awt::XReschedule:
2473 void SAL_CALL VCLXToolkit::reschedule()
2475 SolarMutexGuard aSolarGuard;
2476 Application::Reschedule(true);
2479 // css::awt::XFontMappingUse:
2480 void SAL_CALL VCLXToolkit::startTrackingFontMappingUse()
2482 SolarMutexGuard aSolarGuard;
2483 OutputDevice::StartTrackingFontMappingUse();
2486 css::uno::Sequence<css::awt::XFontMappingUseItem>
2487 SAL_CALL VCLXToolkit::finishTrackingFontMappingUse()
2489 SolarMutexGuard aSolarGuard;
2490 OutputDevice::FontMappingUseData data = OutputDevice::FinishTrackingFontMappingUse();
2491 css::uno::Sequence<css::awt::XFontMappingUseItem> ret( data.size());
2492 css::awt::XFontMappingUseItem* retData = ret.getArray();
2493 for( size_t i = 0; i < data.size(); ++i )
2495 retData[ i ].originalFont = data[ i ].mOriginalFont;
2496 retData[ i ].usedFonts = comphelper::arrayToSequence<OUString,OUString>
2497 (data[ i ].mUsedFonts.data(), data[ i ].mUsedFonts.size());
2498 retData[ i ].count = data[ i ].mCount;
2500 return ret;
2503 // css::awt::XToolkitExperimental
2505 void SAL_CALL VCLXToolkit::processEventsToIdle()
2507 SolarMutexGuard aSolarGuard;
2508 comphelper::ProfileZone aZone("processEvents");
2509 Scheduler::ProcessEventsToIdle();
2512 sal_Int64 SAL_CALL VCLXToolkit::getOpenGLBufferSwapCounter()
2514 #if HAVE_FEATURE_OPENGL
2515 return OpenGLWrapper::getBufferSwapCounter();
2516 #else
2517 return 0;
2518 #endif
2521 void SAL_CALL VCLXToolkit::setDeterministicScheduling(sal_Bool bDeterministicMode)
2523 SolarMutexGuard aSolarGuard;
2524 Scheduler::SetDeterministicMode(bDeterministicMode);
2527 void SAL_CALL VCLXToolkit::pause(sal_Int32 nMilliseconds)
2529 new Pause(nMilliseconds);
2532 void SAL_CALL VCLXToolkit::startRecording()
2534 comphelper::TraceEvent::startRecording();
2537 void SAL_CALL VCLXToolkit::stopRecording()
2539 comphelper::TraceEvent::stopRecording();
2542 css::uno::Sequence< OUString > VCLXToolkit::getRecordingAndClear()
2544 return comphelper::ProfileZone::getRecordingAndClear();
2547 // css:awt:XToolkitRobot
2549 void SAL_CALL VCLXToolkit::keyPress( const css::awt::KeyEvent & aKeyEvent )
2551 css::uno::Reference<css::awt::XWindow> xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY_THROW );
2552 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2553 if( !pWindow )
2554 throw css::uno::RuntimeException( "invalid event source" );
2556 ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent );
2557 ::Application::PostKeyEvent( VclEventId::WindowKeyInput, pWindow, &aVCLKeyEvent );
2560 void SAL_CALL VCLXToolkit::keyRelease( const css::awt::KeyEvent & aKeyEvent )
2562 css::uno::Reference<css::awt::XWindow> xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY_THROW );
2563 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2564 if( !pWindow )
2565 throw css::uno::RuntimeException( "invalid event source" );
2567 ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent );
2568 ::Application::PostKeyEvent( VclEventId::WindowKeyUp, pWindow, &aVCLKeyEvent );
2572 void SAL_CALL VCLXToolkit::mousePress( const css::awt::MouseEvent & aMouseEvent )
2574 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2575 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2576 if( !pWindow )
2577 throw css::uno::RuntimeException( "invalid event source" );
2579 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2580 ::Application::PostMouseEvent( VclEventId::WindowMouseButtonDown, pWindow, &aVCLMouseEvent );
2583 void SAL_CALL VCLXToolkit::mouseRelease( const css::awt::MouseEvent & aMouseEvent )
2585 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2586 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2587 if( !pWindow )
2588 throw css::uno::RuntimeException( "invalid event source" );
2590 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2591 ::Application::PostMouseEvent( VclEventId::WindowMouseButtonUp, pWindow, &aVCLMouseEvent );
2594 void SAL_CALL VCLXToolkit::mouseMove( const css::awt::MouseEvent & aMouseEvent )
2596 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2597 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2598 if( !pWindow )
2599 throw css::uno::RuntimeException( "invalid event source" );
2601 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2602 ::Application::PostMouseEvent( VclEventId::WindowMouseMove, pWindow, &aVCLMouseEvent );
2608 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
2609 stardiv_Toolkit_VCLXToolkit_get_implementation(
2610 css::uno::XComponentContext *,
2611 css::uno::Sequence<css::uno::Any> const &)
2613 return cppu::acquire(new VCLXToolkit());
2616 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */