lwp build fixes
[LibreOffice.git] / toolkit / source / awt / vclxtoolkit.cxx
blob4cc587308dfce3251c97f5c6c629d591c943b49e
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 <boost/ptr_container/ptr_vector.hpp>
22 #include <stdio.h>
23 #ifdef WNT
24 #include <prewin.h>
25 #include <postwin.h>
26 #endif
27 #include <com/sun/star/awt/WindowAttribute.hpp>
28 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
29 #include <com/sun/star/awt/WindowClass.hpp>
30 #include <com/sun/star/awt/MessageBoxButtons.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/lang/SystemDependent.hpp>
33 #include <com/sun/star/awt/FocusEvent.hpp>
34 #include <com/sun/star/awt/KeyEvent.hpp>
35 #include <com/sun/star/awt/KeyModifier.hpp>
36 #include <com/sun/star/lang/EventObject.hpp>
37 #include <com/sun/star/uno/Reference.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
39 #include <com/sun/star/uno/XComponentContext.hpp>
40 #include <com/sun/star/uno/XInterface.hpp>
41 #include <com/sun/star/beans/NamedValue.hpp>
42 #include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <com/sun/star/awt/XToolkitExperimental.hpp>
45 #include <com/sun/star/awt/XMessageBoxFactory.hpp>
47 #include <cppuhelper/bootstrap.hxx>
48 #include <cppuhelper/compbase2.hxx>
49 #include <cppuhelper/interfacecontainer.hxx>
50 #include <cppuhelper/supportsservice.hxx>
51 #include <cppuhelper/typeprovider.hxx>
52 #include <osl/conditn.hxx>
53 #include <osl/module.h>
54 #include <osl/thread.h>
55 #include <osl/mutex.hxx>
56 #include <rtl/uuid.h>
57 #include <rtl/process.h>
58 #include <tools/link.hxx>
59 #include <tools/fract.hxx>
60 #include <tools/wintypes.hxx>
62 #ifdef MACOSX
63 #include "premac.h"
64 #include <Cocoa/Cocoa.h>
65 #include "postmac.h"
66 #endif
68 #ifdef ANDROID
69 #include <sal/ByteBufferWrapper.hxx>
70 using org::libreoffice::touch::ByteBufferWrapper;
71 #endif
73 #include <vcl/sysdata.hxx>
75 #include <toolkit/awt/vclxwindows.hxx>
76 #include <toolkit/awt/vclxsystemdependentwindow.hxx>
77 #include <toolkit/awt/vclxregion.hxx>
78 #include <toolkit/awt/vclxtabpagecontainer.hxx>
80 #include <toolkit/awt/animatedimagespeer.hxx>
81 #include <toolkit/awt/vclxtopwindow.hxx>
82 #include <toolkit/awt/vclxwindow.hxx>
83 #include <toolkit/helper/vclunohelper.hxx>
84 #include <toolkit/helper/servicenames.hxx>
86 #include <toolkit/helper/macros.hxx>
87 #include <toolkit/helper/convert.hxx>
88 #include <vcl/unohelp.hxx>
89 #include <vcl/button.hxx>
90 #include <vcl/combobox.hxx>
91 #include <vcl/ctrl.hxx>
92 #include <vcl/dialog.hxx>
93 #include <vcl/dockingarea.hxx>
94 #include <vcl/dockwin.hxx>
95 #include <vcl/edit.hxx>
96 #include <vcl/field.hxx>
97 #include <vcl/fixed.hxx>
98 #include <vcl/floatwin.hxx>
99 #include <vcl/group.hxx>
100 #include <vcl/imgctrl.hxx>
101 #include <vcl/longcurr.hxx>
102 #include <vcl/lstbox.hxx>
103 #include <vcl/menubtn.hxx>
104 #include <vcl/morebtn.hxx>
105 #include <vcl/msgbox.hxx>
106 #include <vcl/scrbar.hxx>
107 #include <vcl/spin.hxx>
108 #include <vcl/split.hxx>
109 #include <vcl/splitwin.hxx>
110 #include <vcl/status.hxx>
111 #include <vcl/svapp.hxx>
112 #include <vcl/syschild.hxx>
113 #include <vcl/tabctrl.hxx>
114 #include <vcl/tabdlg.hxx>
115 #include <vcl/tabpage.hxx>
116 #include <vcl/toolbox.hxx>
117 #include <vcl/virdev.hxx>
118 #include <vcl/window.hxx>
119 #include <vcl/wrkwin.hxx>
120 #include <vcl/throbber.hxx>
121 #include "toolkit/awt/vclxspinbutton.hxx"
122 #include <tools/debug.hxx>
123 #include <comphelper/processfactory.hxx>
124 #include <toolkit/awt/scrollabledialog.hxx>
126 #include "helper/unowrapper.hxx"
128 #define VCLWINDOW_FRAMEWINDOW 0x1000
129 #define VCLWINDOW_SYSTEMCHILDWINDOW 0x1001
131 #if (defined WNT)
132 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32
133 #elif (defined MACOSX)
134 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_MAC
135 #elif (defined UNX)
136 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW
137 #endif
139 namespace {
141 extern "C" typedef vcl::Window* (SAL_CALL *FN_SvtCreateWindow)(
142 VCLXWindow** ppNewComp,
143 const css::awt::WindowDescriptor* pDescriptor,
144 vcl::Window* pParent,
145 WinBits nWinBits );
147 class VCLXToolkit_Impl
149 protected:
150 ::osl::Mutex maMutex;
153 class VCLXToolkit : public VCLXToolkit_Impl,
154 public cppu::WeakComponentImplHelper2<
155 css::awt::XToolkitExperimental,
156 css::lang::XServiceInfo >
158 css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard;
159 css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxSelection;
161 oslModule hSvToolsLib;
162 FN_SvtCreateWindow fnSvtCreateWindow;
164 ::cppu::OInterfaceContainerHelper m_aTopWindowListeners;
165 ::cppu::OInterfaceContainerHelper m_aKeyHandlers;
166 ::cppu::OInterfaceContainerHelper m_aFocusListeners;
167 ::Link m_aEventListenerLink;
168 ::Link m_aKeyListenerLink;
169 bool m_bEventListener;
170 bool m_bKeyListener;
172 DECL_LINK(eventListenerHandler, ::VclSimpleEvent const *);
174 DECL_LINK(keyListenerHandler, ::VclSimpleEvent const *);
176 void callTopWindowListeners(
177 ::VclSimpleEvent const * pEvent,
178 void (SAL_CALL css::awt::XTopWindowListener::* pFn)(
179 css::lang::EventObject const &));
181 long callKeyHandlers(::VclSimpleEvent const * pEvent, bool bPressed);
183 void callFocusListeners(::VclSimpleEvent const * pEvent, bool bGained);
185 protected:
186 ::osl::Mutex& GetMutex() { return maMutex; }
188 virtual void SAL_CALL disposing() SAL_OVERRIDE;
190 vcl::Window* ImplCreateWindow( VCLXWindow** ppNewComp, const css::awt::WindowDescriptor& rDescriptor, vcl::Window* pParent, WinBits nWinBits );
191 css::uno::Reference< css::awt::XWindowPeer > ImplCreateWindow( const css::awt::WindowDescriptor& Descriptor, WinBits nWinBits );
193 public:
195 VCLXToolkit();
196 virtual ~VCLXToolkit();
198 // css::awt::XToolkitExperimental
199 css::uno::Reference< css::awt::XDevice > SAL_CALL createScreenCompatibleDeviceUsingBuffer( sal_Int32 Width, sal_Int32 Height, sal_Int32 ScaleNumerator, sal_Int32 ScaleDenominator, sal_Int32 XOffset, sal_Int32 YOffset, sal_Int64 AddressOfMemoryBufferForSharedArrayWrapper ) throw
200 (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
201 virtual void SAL_CALL processEventsToIdle()
202 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
204 // css::awt::XToolkit
205 css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getDesktopWindow( ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
206 css::awt::Rectangle SAL_CALL getWorkArea( ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
207 css::uno::Reference< css::awt::XWindowPeer > SAL_CALL createWindow( const css::awt::WindowDescriptor& Descriptor ) throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
208 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > SAL_CALL createWindows( const css::uno::Sequence< css::awt::WindowDescriptor >& Descriptors ) throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
209 css::uno::Reference< css::awt::XDevice > SAL_CALL createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) throw
210 (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
211 css::uno::Reference< css::awt::XRegion > SAL_CALL createRegion( ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
213 // css::awt::XSystemChildFactory
214 css::uno::Reference< css::awt::XWindowPeer > SAL_CALL createSystemChild( const css::uno::Any& Parent, const css::uno::Sequence< sal_Int8 >& ProcessId, sal_Int16 SystemType ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
216 // css::awt::XMessageBoxFactory
217 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 ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
219 // css::awt::XDataTransfer
220 css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL getDragGestureRecognizer( const css::uno::Reference< css::awt::XWindow >& window ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
221 css::uno::Reference< css::datatransfer::dnd::XDragSource > SAL_CALL getDragSource( const css::uno::Reference< css::awt::XWindow >& window ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
222 css::uno::Reference< css::datatransfer::dnd::XDropTarget > SAL_CALL getDropTarget( const css::uno::Reference< css::awt::XWindow >& window ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
223 css::uno::Reference< css::datatransfer::clipboard::XClipboard > SAL_CALL getClipboard( const OUString& clipboardName ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
225 // css::lang::XServiceInfo
226 OUString SAL_CALL getImplementationName( ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
227 sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
228 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
230 // css::awt::XExtendedToolkit:
232 virtual ::sal_Int32 SAL_CALL getTopWindowCount()
233 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
235 virtual css::uno::Reference< css::awt::XTopWindow >
236 SAL_CALL getTopWindow(::sal_Int32 nIndex)
237 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
239 virtual css::uno::Reference< css::awt::XTopWindow >
240 SAL_CALL getActiveTopWindow()
241 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
243 virtual void SAL_CALL addTopWindowListener(
244 css::uno::Reference<
245 css::awt::XTopWindowListener > const & rListener)
246 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
248 virtual void SAL_CALL removeTopWindowListener(
249 css::uno::Reference<
250 css::awt::XTopWindowListener > const & rListener)
251 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
253 virtual void SAL_CALL addKeyHandler(
254 css::uno::Reference<
255 css::awt::XKeyHandler > const & rHandler)
256 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
258 virtual void SAL_CALL removeKeyHandler(
259 css::uno::Reference<
260 css::awt::XKeyHandler > const & rHandler)
261 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
263 virtual void SAL_CALL addFocusListener(
264 css::uno::Reference<
265 css::awt::XFocusListener > const & rListener)
266 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
268 virtual void SAL_CALL removeFocusListener(
269 css::uno::Reference<
270 css::awt::XFocusListener > const & rListener)
271 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
273 virtual void SAL_CALL fireFocusGained(
274 css::uno::Reference<
275 css::uno::XInterface > const & source)
276 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
278 virtual void SAL_CALL fireFocusLost(
279 css::uno::Reference<
280 css::uno::XInterface > const & source)
281 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
283 // css::awt::XReschedule:
284 virtual void SAL_CALL reschedule()
285 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
288 WinBits ImplGetWinBits( sal_uInt32 nComponentAttribs, sal_uInt16 nCompType )
290 WinBits nWinBits = 0;
292 bool bMessBox = false;
293 if ( ( nCompType == WINDOW_INFOBOX ) ||
294 ( nCompType == WINDOW_MESSBOX ) ||
295 ( nCompType == WINDOW_QUERYBOX ) ||
296 ( nCompType == WINDOW_WARNINGBOX ) ||
297 ( nCompType == WINDOW_ERRORBOX ) )
299 bMessBox = true;
302 bool bDecoratedWindow = false;
303 if ( bMessBox
304 || ( nCompType == WINDOW_DIALOG )
305 || ( nCompType == WINDOW_MODELESSDIALOG )
306 || ( nCompType == WINDOW_MODALDIALOG )
307 || ( nCompType == WINDOW_SYSTEMDIALOG )
308 || ( nCompType == WINDOW_PATHDIALOG )
309 || ( nCompType == WINDOW_FILEDIALOG )
310 || ( nCompType == WINDOW_PRINTERSETUPDIALOG )
311 || ( nCompType == WINDOW_PRINTDIALOG )
312 || ( nCompType == WINDOW_COLORDIALOG )
313 || ( nCompType == WINDOW_FONTDIALOG )
314 || ( nCompType == WINDOW_DOCKINGWINDOW )
315 || ( nCompType == WINDOW_TABDIALOG )
316 || ( nCompType == WINDOW_BUTTONDIALOG )
317 || ( nCompType == WINDOW_SYSTEMCHILDWINDOW )
320 bDecoratedWindow = true;
323 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::BORDER )
324 nWinBits |= WB_BORDER;
325 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::NOBORDER )
326 nWinBits |= WB_NOBORDER;
327 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::SIZEABLE )
328 nWinBits |= WB_SIZEABLE;
329 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::MOVEABLE )
330 nWinBits |= WB_MOVEABLE;
331 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::CLOSEABLE )
332 nWinBits |= WB_CLOSEABLE;
333 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::HSCROLL )
334 nWinBits |= WB_HSCROLL;
335 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL )
336 nWinBits |= WB_VSCROLL;
337 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::LEFT )
338 nWinBits |= WB_LEFT;
339 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::CENTER )
340 nWinBits |= WB_CENTER;
341 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::RIGHT )
342 nWinBits |= WB_RIGHT;
343 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::SPIN )
344 nWinBits |= WB_SPIN;
345 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::SORT )
346 nWinBits |= WB_SORT;
347 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DROPDOWN )
348 nWinBits |= WB_DROPDOWN;
349 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEFBUTTON )
350 nWinBits |= WB_DEFBUTTON;
351 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::READONLY )
352 nWinBits |= WB_READONLY;
353 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::CLIPCHILDREN )
354 nWinBits |= WB_CLIPCHILDREN;
355 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::GROUP )
356 nWinBits |= WB_GROUP;
357 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::NOLABEL ) //added for issue79712
358 nWinBits |= WB_NOLABEL;
360 // These bits are not uniqe
361 if ( bMessBox )
363 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::OK )
364 nWinBits |= WB_OK;
365 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::OK_CANCEL )
366 nWinBits |= WB_OK_CANCEL;
367 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO )
368 nWinBits |= WB_YES_NO;
369 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO_CANCEL )
370 nWinBits |= WB_YES_NO_CANCEL;
371 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::RETRY_CANCEL )
372 nWinBits |= WB_RETRY_CANCEL;
373 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_OK )
374 nWinBits |= WB_DEF_OK;
375 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_CANCEL )
376 nWinBits |= WB_DEF_CANCEL;
377 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_RETRY )
378 nWinBits |= WB_DEF_RETRY;
379 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_YES )
380 nWinBits |= WB_DEF_YES;
381 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_NO )
382 nWinBits |= WB_DEF_NO;
384 if ( nCompType == WINDOW_MULTILINEEDIT || nCompType == WINDOW_DIALOG || nCompType == WINDOW_GROUPBOX )
386 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::AUTOHSCROLL )
387 nWinBits |= WB_AUTOHSCROLL;
388 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::AUTOVSCROLL )
389 nWinBits |= WB_AUTOVSCROLL;
393 if ( bDecoratedWindow )
395 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::NODECORATION )
397 // No decoration removes several window attributes and must
398 // set WB_NOBORDER!
399 nWinBits &= ~WB_BORDER;
400 nWinBits &= ~WB_SIZEABLE;
401 nWinBits &= ~WB_MOVEABLE;
402 nWinBits &= ~WB_CLOSEABLE;
403 nWinBits |= WB_NOBORDER;
407 return nWinBits;
410 struct ComponentInfo
412 const char* pName;
413 WindowType nWinType;
416 static ComponentInfo aComponentInfos [] =
418 { "buttondialog", WINDOW_BUTTONDIALOG },
419 { "cancelbutton", WINDOW_CANCELBUTTON },
420 { "checkbox", WINDOW_CHECKBOX },
421 { "combobox", WINDOW_COMBOBOX },
422 { "control", WINDOW_CONTROL },
423 { "currencybox", WINDOW_CURRENCYBOX },
424 { "currencyfield", WINDOW_CURRENCYFIELD },
425 { "datebox", WINDOW_DATEBOX },
426 { "datefield", WINDOW_DATEFIELD },
427 { "dialog", WINDOW_DIALOG },
428 { "dockingarea", WINDOW_DOCKINGAREA },
429 { "dockingwindow", WINDOW_DOCKINGWINDOW },
430 { "edit", WINDOW_EDIT },
431 { "errorbox", WINDOW_ERRORBOX },
432 { "fixedbitmap", WINDOW_FIXEDBITMAP },
433 { "fixedimage", WINDOW_FIXEDIMAGE },
434 { "fixedline", WINDOW_FIXEDLINE },
435 { "fixedtext", WINDOW_FIXEDTEXT },
436 { "floatingwindow", WINDOW_FLOATINGWINDOW },
437 { "framewindow", VCLWINDOW_FRAMEWINDOW },
438 { "groupbox", WINDOW_GROUPBOX },
439 { "frame", WINDOW_GROUPBOX },
440 { "helpbutton", WINDOW_HELPBUTTON },
441 { "imagebutton", WINDOW_IMAGEBUTTON },
442 { "infobox", WINDOW_INFOBOX },
443 { "listbox", WINDOW_LISTBOX },
444 { "longcurrencybox", WINDOW_LONGCURRENCYBOX },
445 { "longcurrencyfield", WINDOW_LONGCURRENCYFIELD },
446 { "menubutton", WINDOW_MENUBUTTON },
447 { "messbox", WINDOW_MESSBOX },
448 { "metricbox", WINDOW_METRICBOX },
449 { "metricfield", WINDOW_METRICFIELD },
450 { "modaldialog", WINDOW_MODALDIALOG },
451 { "modelessdialog", WINDOW_MODELESSDIALOG },
452 { "morebutton", WINDOW_MOREBUTTON },
453 { "multilineedit", WINDOW_MULTILINEEDIT },
454 { "multilistbox", WINDOW_MULTILISTBOX },
455 { "numericbox", WINDOW_NUMERICBOX },
456 { "numericfield", WINDOW_NUMERICFIELD },
457 { "okbutton", WINDOW_OKBUTTON },
458 { "patternbox", WINDOW_PATTERNBOX },
459 { "patternfield", WINDOW_PATTERNFIELD },
460 { "pushbutton", WINDOW_PUSHBUTTON },
461 { "querybox", WINDOW_QUERYBOX },
462 { "radiobutton", WINDOW_RADIOBUTTON },
463 { "scrollbar", WINDOW_SCROLLBAR },
464 { "scrollbarbox", WINDOW_SCROLLBARBOX },
465 { "animatedimages", WINDOW_CONTROL },
466 { "spinbutton", WINDOW_SPINBUTTON },
467 { "spinfield", WINDOW_SPINFIELD },
468 { "splitter", WINDOW_SPLITTER },
469 { "splitwindow", WINDOW_SPLITWINDOW },
470 { "statusbar", WINDOW_STATUSBAR },
471 { "systemchildwindow", VCLWINDOW_SYSTEMCHILDWINDOW },
472 { "tabcontrol", WINDOW_TABCONTROL },
473 { "tabdialog", WINDOW_TABDIALOG },
474 { "tabpage", WINDOW_TABPAGE },
475 { "timebox", WINDOW_TIMEBOX },
476 { "timefield", WINDOW_TIMEFIELD },
477 { "toolbox", WINDOW_TOOLBOX },
478 { "tristatebox", WINDOW_TRISTATEBOX },
479 { "warningbox", WINDOW_WARNINGBOX },
480 { "window", WINDOW_WINDOW },
481 { "workwindow", WINDOW_WORKWINDOW },
482 { "tabpagecontainer", WINDOW_CONTROL },
483 { "tabpagemodel", WINDOW_TABPAGE }
486 extern "C"
488 static int SAL_CALL ComponentInfoCompare( const void* pFirst, const void* pSecond)
490 return( strcmp( ((ComponentInfo*)pFirst)->pName,
491 ((ComponentInfo*)pSecond)->pName ) );
495 sal_uInt16 ImplGetComponentType( const OUString& rServiceName )
497 static bool bSorted = false;
498 if( !bSorted )
500 qsort( (void*) aComponentInfos,
501 sizeof( aComponentInfos ) / sizeof( ComponentInfo ),
502 sizeof( ComponentInfo ),
503 ComponentInfoCompare );
504 bSorted = true;
508 ComponentInfo aSearch;
509 OString aServiceName(OUStringToOString(rServiceName, osl_getThreadTextEncoding()).toAsciiLowerCase());
510 if ( !aServiceName.isEmpty() )
511 aSearch.pName = aServiceName.getStr();
512 else
513 aSearch.pName = "window";
515 ComponentInfo* pInf = (ComponentInfo*) bsearch( &aSearch,
516 (void*) aComponentInfos,
517 sizeof( aComponentInfos ) / sizeof( ComponentInfo ),
518 sizeof( ComponentInfo ),
519 ComponentInfoCompare );
521 return pInf ? pInf->nWinType : 0;
525 namespace
527 struct MessageBoxTypeInfo
529 css::awt::MessageBoxType eType;
530 const sal_Char *pName;
531 sal_Int32 nLen;
534 static const MessageBoxTypeInfo aMessageBoxTypeInfo[] =
536 { css::awt::MessageBoxType_MESSAGEBOX, RTL_CONSTASCII_STRINGPARAM("messbox") },
537 { css::awt::MessageBoxType_INFOBOX, RTL_CONSTASCII_STRINGPARAM("infobox") },
538 { css::awt::MessageBoxType_WARNINGBOX, RTL_CONSTASCII_STRINGPARAM("warningbox") },
539 { css::awt::MessageBoxType_ERRORBOX, RTL_CONSTASCII_STRINGPARAM("errorbox") },
540 { css::awt::MessageBoxType_QUERYBOX, RTL_CONSTASCII_STRINGPARAM("querybox") },
541 { css::awt::MessageBoxType_MAKE_FIXED_SIZE, 0, 0 }
544 static bool lcl_convertMessageBoxType(
545 rtl::OUString &sType,
546 css::awt::MessageBoxType eType )
548 const MessageBoxTypeInfo *pMap = aMessageBoxTypeInfo;
549 css::awt::MessageBoxType eVal = css::awt::MessageBoxType_MAKE_FIXED_SIZE;
551 while ( pMap->pName )
553 if ( pMap->eType == eType )
555 eVal = eType;
556 sType = rtl::OUString( pMap->pName, pMap->nLen, RTL_TEXTENCODING_ASCII_US );
557 break;
559 pMap++;
562 return ( eVal != css::awt::MessageBoxType_MAKE_FIXED_SIZE );
566 static sal_Int32 nVCLToolkitInstanceCount = 0;
567 static bool bInitedByVCLToolkit = false;
569 static osl::Mutex & getInitMutex()
571 static osl::Mutex * pM;
572 if( !pM )
574 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
575 if( !pM )
577 static osl::Mutex aMutex;
578 pM = &aMutex;
581 return *pM;
584 static osl::Condition & getInitCondition()
586 static osl::Condition * pC = 0;
587 if( !pC )
589 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
590 if( !pC )
592 static osl::Condition aCondition;
593 pC = &aCondition;
596 return *pC;
599 extern "C"
601 static void SAL_CALL ToolkitWorkerFunction( void* pArgs )
603 osl_setThreadName("VCLXToolkit VCL main thread");
605 css::uno::Reference<css::lang::XMultiServiceFactory> xServiceManager;
608 xServiceManager = ::comphelper::getProcessServiceFactory();
610 catch (const css::uno::DeploymentException&)
613 if (!xServiceManager.is())
615 css::uno::Reference<css::uno::XComponentContext> xContext =
616 ::cppu::defaultBootstrap_InitialComponentContext();
618 xServiceManager = css::uno::Reference<css::lang::XMultiServiceFactory>(
619 xContext->getServiceManager(), css::uno::UNO_QUERY_THROW );
620 // set global process service factory used by unotools config helpers
621 ::comphelper::setProcessServiceFactory( xServiceManager );
624 VCLXToolkit * pTk = static_cast<VCLXToolkit *>(pArgs);
625 bInitedByVCLToolkit = InitVCL();
626 if( bInitedByVCLToolkit )
628 UnoWrapper* pUnoWrapper = new UnoWrapper( pTk );
629 Application::SetUnoWrapper( pUnoWrapper );
631 getInitCondition().set();
632 if( bInitedByVCLToolkit )
635 SolarMutexGuard aGuard;
636 Application::Execute();
640 pTk->dispose();
642 catch( com::sun::star::uno::Exception & )
645 DeInitVCL();
647 else
649 JoinMainLoopThread();
654 // contructor, which might initialize VCL
655 VCLXToolkit::VCLXToolkit():
656 cppu::WeakComponentImplHelper2<
657 ::com::sun::star::awt::XToolkitExperimental,
658 ::com::sun::star::lang::XServiceInfo>( GetMutex() ),
659 m_aTopWindowListeners(rBHelper.rMutex),
660 m_aKeyHandlers(rBHelper.rMutex),
661 m_aFocusListeners(rBHelper.rMutex),
662 m_aEventListenerLink(LINK(this, VCLXToolkit, eventListenerHandler)),
663 m_aKeyListenerLink(LINK(this, VCLXToolkit, keyListenerHandler)),
664 m_bEventListener(false),
665 m_bKeyListener(false)
667 hSvToolsLib = NULL;
668 fnSvtCreateWindow = NULL;
670 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
671 nVCLToolkitInstanceCount++;
672 if( ( nVCLToolkitInstanceCount == 1 ) && ( !Application::IsInMain() ) )
674 // setup execute thread
675 CreateMainLoopThread( ToolkitWorkerFunction, this );
676 getInitCondition().wait();
680 VCLXToolkit::~VCLXToolkit()
685 void SAL_CALL VCLXToolkit::disposing()
687 #ifndef DISABLE_DYNLOADING
688 if ( hSvToolsLib )
690 osl_unloadModule( hSvToolsLib );
691 hSvToolsLib = NULL;
692 fnSvtCreateWindow = NULL;
694 #endif
697 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
698 if( --nVCLToolkitInstanceCount == 0 )
700 if( bInitedByVCLToolkit )
702 Application::Quit();
703 JoinMainLoopThread();
704 bInitedByVCLToolkit = false;
709 if (m_bEventListener)
711 ::Application::RemoveEventListener(m_aEventListenerLink);
712 m_bEventListener = false;
714 if (m_bKeyListener)
716 ::Application::RemoveKeyListener(m_aKeyListenerLink);
717 m_bKeyListener = false;
719 css::lang::EventObject aEvent(
720 static_cast< ::cppu::OWeakObject * >(this));
721 m_aTopWindowListeners.disposeAndClear(aEvent);
722 m_aKeyHandlers.disposeAndClear(aEvent);
723 m_aFocusListeners.disposeAndClear(aEvent);
727 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::getDesktopWindow( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
729 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef;
730 // 07/00: AppWindow doesn't exist anymore...
731 return xRef;
734 ::com::sun::star::awt::Rectangle VCLXToolkit::getWorkArea( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
736 sal_Int32 nDisplay = Application::GetDisplayBuiltInScreen();
737 Rectangle aWorkRect = Application::GetScreenPosSizePixel( nDisplay );
738 com::sun::star::awt::Rectangle aNotherRect;
739 aNotherRect.X = aWorkRect.getX();
740 aNotherRect.Y = aWorkRect.getY();
741 aNotherRect.Width = aWorkRect.getWidth();
742 aNotherRect.Height = aWorkRect.getHeight();
743 return aNotherRect;
746 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::createWindow( const ::com::sun::star::awt::WindowDescriptor& rDescriptor ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
748 return ImplCreateWindow( rDescriptor, WinBits(0) );
751 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) throw(::com::sun::star::uno::RuntimeException, std::exception)
753 return createScreenCompatibleDeviceUsingBuffer( Width, Height, 1, 1, 0, 0, 0 );
756 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXToolkit::createScreenCompatibleDeviceUsingBuffer( sal_Int32 Width, sal_Int32 Height, sal_Int32 ScaleNumerator, sal_Int32 ScaleDenominator, sal_Int32 XOffset, sal_Int32 YOffset, sal_Int64 addressOfMemoryBufferForSharedArrayWrapper ) throw(::com::sun::star::uno::RuntimeException, std::exception)
758 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
760 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > xRef;
761 VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
763 SolarMutexGuard aSolarGuard;
765 VirtualDevice* pV = new VirtualDevice;
766 if ( addressOfMemoryBufferForSharedArrayWrapper != 0 ) {
767 #if defined(ANDROID)
768 ByteBufferWrapper *bbw = (ByteBufferWrapper *) (intptr_t) addressOfMemoryBufferForSharedArrayWrapper;
769 pV->SetOutputSizePixelScaleOffsetAndBuffer( Size( Width, Height ), Fraction(ScaleNumerator, ScaleDenominator), Point( XOffset, YOffset), basebmp::RawMemorySharedArray( bbw->pointer(), *bbw ));
770 #else
771 pV->SetOutputSizePixelScaleOffsetAndBuffer( Size( Width, Height ),
772 Fraction(ScaleNumerator, ScaleDenominator), Point( XOffset, YOffset),
773 basebmp::RawMemorySharedArray( reinterpret_cast<sal_uInt8*>( addressOfMemoryBufferForSharedArrayWrapper )));
774 #endif
775 } else {
776 pV->SetOutputSizePixel( Size( Width, Height ) );
778 pVDev->SetVirtualDevice( pV );
780 xRef = pVDev;
781 return xRef;
784 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion > VCLXToolkit::createRegion( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
786 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
788 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion > xRef = new VCLXRegion;
789 return xRef;
792 vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp,
793 const ::com::sun::star::awt::WindowDescriptor& rDescriptor,
794 vcl::Window* pParent, WinBits nWinBits )
796 OUString aServiceName( rDescriptor.WindowServiceName );
797 aServiceName = aServiceName.toAsciiLowerCase();
799 vcl::Window* pNewWindow = NULL;
800 sal_uInt16 nType = ImplGetComponentType( aServiceName );
801 bool bFrameControl = false;
802 if ( aServiceName == "frame" )
803 bFrameControl = true;
804 if ( aServiceName == "tabcontrolnotabs" )
806 nWinBits |= WB_NOBORDER;
807 nType = ImplGetComponentType( OUString( "tabcontrol" ) );
809 if ( !pParent )
811 // Wenn die Component einen Parent braucht, dann NULL zurueckgeben,
812 // spaeter mal ::com::sun::star::uno::Exception...
813 bool bException = true;
814 if ( ( nType == WINDOW_DIALOG )
815 || ( nType == WINDOW_MODALDIALOG )
816 || ( nType == WINDOW_MODELESSDIALOG )
817 || ( nType == WINDOW_MESSBOX )
818 || ( nType == WINDOW_INFOBOX )
819 || ( nType == WINDOW_WARNINGBOX )
820 || ( nType == WINDOW_ERRORBOX )
821 || ( nType == WINDOW_QUERYBOX )
823 bException = false;
824 else if ( ( nType == WINDOW_WINDOW ) ||
825 ( nType == WINDOW_WORKWINDOW ) ||
826 ( nType == VCLWINDOW_FRAMEWINDOW ) )
828 if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP )
829 bException = false;
832 if ( bException )
834 *ppNewComp = NULL;
835 return NULL;
839 if ( nType )
841 SolarMutexGuard aVclGuard;
842 switch ( (WindowType)nType )
844 case WINDOW_CANCELBUTTON:
845 pNewWindow = new CancelButton( pParent, nWinBits );
846 *ppNewComp = new VCLXButton;
847 break;
848 case WINDOW_CHECKBOX:
849 pNewWindow = new CheckBox( pParent, nWinBits );
850 *ppNewComp = new VCLXCheckBox;
851 break;
852 case WINDOW_COMBOBOX:
853 pNewWindow = new ComboBox( pParent, nWinBits|WB_AUTOHSCROLL );
854 static_cast<ComboBox*>(pNewWindow)->EnableAutoSize( false );
855 *ppNewComp = new VCLXComboBox;
856 break;
857 case WINDOW_CURRENCYBOX:
858 pNewWindow = new CurrencyBox( pParent, nWinBits );
859 break;
860 case WINDOW_CURRENCYFIELD:
861 pNewWindow = new CurrencyField( pParent, nWinBits );
862 static_cast<CurrencyField*>(pNewWindow)->EnableEmptyFieldValue( true );
863 *ppNewComp = new VCLXNumericField;
864 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( (FormatterBase*)static_cast<CurrencyField*>(pNewWindow) );
865 break;
866 case WINDOW_DATEBOX:
867 pNewWindow = new DateBox( pParent, nWinBits );
868 break;
869 case WINDOW_DATEFIELD:
870 pNewWindow = new DateField( pParent, nWinBits );
871 static_cast<DateField*>(pNewWindow)->EnableEmptyFieldValue( true );
872 *ppNewComp = new VCLXDateField;
873 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( (FormatterBase*)static_cast<DateField*>(pNewWindow) );
874 break;
875 case WINDOW_DOCKINGAREA:
876 pNewWindow = new DockingAreaWindow( pParent );
877 break;
878 case WINDOW_MULTILINEEDIT:
879 case WINDOW_EDIT:
880 pNewWindow = new Edit( pParent, nWinBits );
881 *ppNewComp = new VCLXEdit;
882 break;
883 case WINDOW_ERRORBOX:
884 pNewWindow = new ErrorBox( pParent, nWinBits, OUString() );
885 *ppNewComp = new VCLXMessageBox;
886 break;
887 case WINDOW_FIXEDBITMAP:
888 pNewWindow = new FixedBitmap( pParent, nWinBits );
889 break;
890 case WINDOW_FIXEDIMAGE:
891 pNewWindow = new ImageControl( pParent, nWinBits );
892 *ppNewComp = new VCLXImageControl;
893 break;
894 case WINDOW_FIXEDLINE:
895 pNewWindow = new FixedLine( pParent, nWinBits );
896 break;
897 case WINDOW_FIXEDTEXT:
898 pNewWindow = new FixedText( pParent, nWinBits );
899 *ppNewComp = new VCLXFixedText;
900 break;
901 case WINDOW_FLOATINGWINDOW:
902 pNewWindow = new FloatingWindow( pParent, nWinBits );
903 break;
904 case WINDOW_GROUPBOX:
905 pNewWindow = new GroupBox( pParent, nWinBits );
906 if ( bFrameControl )
908 GroupBox* pGroupBox = static_cast< GroupBox* >( pNewWindow );
909 *ppNewComp = new VCLXFrame;
910 // Frame control needs to receive
911 // Mouse events
912 pGroupBox->SetMouseTransparent( false );
914 break;
915 case WINDOW_HELPBUTTON:
916 pNewWindow = new HelpButton( pParent, nWinBits );
917 *ppNewComp = new VCLXButton;
918 break;
919 case WINDOW_IMAGEBUTTON:
920 pNewWindow = new ImageButton( pParent, nWinBits );
921 *ppNewComp = new VCLXButton;
922 break;
923 case WINDOW_INFOBOX:
924 pNewWindow = new InfoBox( pParent, OUString() );
925 *ppNewComp = new VCLXMessageBox;
926 break;
927 case WINDOW_LISTBOX:
928 pNewWindow = new ListBox( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL );
929 static_cast<ListBox*>(pNewWindow)->EnableAutoSize( false );
930 *ppNewComp = new VCLXListBox;
931 break;
932 case WINDOW_LONGCURRENCYBOX:
933 pNewWindow = new LongCurrencyBox( pParent, nWinBits );
934 break;
935 case WINDOW_LONGCURRENCYFIELD:
936 pNewWindow = new LongCurrencyField( pParent, nWinBits );
937 *ppNewComp = new VCLXCurrencyField;
938 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( (FormatterBase*)static_cast<LongCurrencyField*>(pNewWindow) );
939 break;
940 case WINDOW_MENUBUTTON:
941 pNewWindow = new MenuButton( pParent, nWinBits );
942 *ppNewComp = new VCLXButton;
943 break;
944 case WINDOW_MESSBOX:
945 pNewWindow = new MessBox( pParent, nWinBits, OUString(), OUString() );
946 *ppNewComp = new VCLXMessageBox;
947 break;
948 case WINDOW_METRICBOX:
949 pNewWindow = new MetricBox( pParent, nWinBits );
950 break;
951 case WINDOW_METRICFIELD:
952 pNewWindow = new MetricField( pParent, nWinBits );
953 *ppNewComp = new VCLXMetricField;
954 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( (FormatterBase*)static_cast<MetricField*>(pNewWindow) );
955 break;
956 case WINDOW_DIALOG:
957 case WINDOW_MODALDIALOG:
958 case WINDOW_MODELESSDIALOG:
960 // Modal/Modeless nur durch Show/Execute
961 if ( (pParent == NULL ) && ( rDescriptor.ParentIndex == -1 ) )
962 pParent = DIALOG_NO_PARENT;
963 pNewWindow = new toolkit::ScrollableWrapper<Dialog>( pParent, nWinBits );
964 // #i70217# Don't always create a new component object. It's possible that VCL has called
965 // GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() )
966 // which creates a component object.
967 css::uno::Reference< css::awt::XWindowPeer > xWinPeer = pNewWindow->GetComponentInterface( false );
968 if ( xWinPeer.is() )
969 *ppNewComp = dynamic_cast< VCLXDialog* >( xWinPeer.get() );
970 else
971 *ppNewComp = new VCLXDialog;
973 break;
974 case WINDOW_MOREBUTTON:
975 pNewWindow = new MoreButton( pParent, nWinBits );
976 *ppNewComp = new VCLXButton;
977 break;
978 case WINDOW_MULTILISTBOX:
979 pNewWindow = new MultiListBox( pParent, nWinBits );
980 *ppNewComp = new VCLXListBox;
981 break;
982 case WINDOW_NUMERICBOX:
983 pNewWindow = new NumericBox( pParent, nWinBits );
984 break;
985 case WINDOW_NUMERICFIELD:
986 pNewWindow = new NumericField( pParent, nWinBits );
987 static_cast<NumericField*>(pNewWindow)->EnableEmptyFieldValue( true );
988 *ppNewComp = new VCLXNumericField;
989 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( (FormatterBase*)static_cast<NumericField*>(pNewWindow) );
990 break;
991 case WINDOW_OKBUTTON:
992 pNewWindow = new OKButton( pParent, nWinBits );
993 *ppNewComp = new VCLXButton;
994 break;
995 case WINDOW_PATTERNBOX:
996 pNewWindow = new PatternBox( pParent, nWinBits );
997 break;
998 case WINDOW_PATTERNFIELD:
999 pNewWindow = new PatternField( pParent, nWinBits );
1000 *ppNewComp = new VCLXPatternField;
1001 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( (FormatterBase*)static_cast<PatternField*>(pNewWindow) );
1002 break;
1003 case WINDOW_PUSHBUTTON:
1004 pNewWindow = new PushButton( pParent, nWinBits );
1005 *ppNewComp = new VCLXButton;
1006 break;
1007 case WINDOW_QUERYBOX:
1008 pNewWindow = new QueryBox( pParent, nWinBits, OUString() );
1009 *ppNewComp = new VCLXMessageBox;
1010 break;
1011 case WINDOW_RADIOBUTTON:
1012 pNewWindow = new RadioButton( pParent, nWinBits );
1013 *ppNewComp = new VCLXRadioButton;
1015 // by default, disable RadioCheck
1016 // Since the VCLXRadioButton really cares for it's RadioCheck settings, this is important:
1017 // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState
1018 // This leads to a strange behaviour if the control is newly created: when settings the initial
1019 // state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck
1020 // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls
1021 // is not really valid: the controls are grouped after they have been created, but we're still in
1022 // the creation process, so the RadioButton::Check relies on invalid grouping information.
1023 // 07.08.2001 - #87254# - frank.schoenheit@sun.com
1024 static_cast<RadioButton*>(pNewWindow)->EnableRadioCheck( false );
1025 break;
1026 case WINDOW_SCROLLBAR:
1027 pNewWindow = new ScrollBar( pParent, nWinBits );
1028 *ppNewComp = new VCLXScrollBar;
1029 break;
1030 case WINDOW_SCROLLBARBOX:
1031 pNewWindow = new ScrollBarBox( pParent, nWinBits );
1032 break;
1033 case WINDOW_SPINBUTTON:
1034 pNewWindow = new SpinButton( pParent, nWinBits );
1035 *ppNewComp = new ::toolkit::VCLXSpinButton;
1036 break;
1037 case WINDOW_SPINFIELD:
1038 pNewWindow = new SpinField( pParent, nWinBits );
1039 *ppNewComp = new VCLXNumericField;
1040 break;
1041 case WINDOW_SPLITTER:
1042 pNewWindow = new Splitter( pParent, nWinBits );
1043 break;
1044 case WINDOW_SPLITWINDOW:
1045 pNewWindow = new SplitWindow( pParent, nWinBits );
1046 break;
1047 case WINDOW_STATUSBAR:
1048 pNewWindow = new StatusBar( pParent, nWinBits );
1049 break;
1050 case VCLWINDOW_SYSTEMCHILDWINDOW:
1051 pNewWindow = new SystemChildWindow( pParent, nWinBits );
1052 *ppNewComp = new VCLXSystemDependentWindow();
1053 break;
1054 case WINDOW_TABCONTROL:
1055 pNewWindow = new TabControl( pParent, nWinBits );
1056 *ppNewComp = new VCLXMultiPage;
1057 break;
1058 case WINDOW_TABDIALOG:
1059 pNewWindow = new TabDialog( pParent, nWinBits );
1060 break;
1061 case WINDOW_TABPAGE:
1063 pNewWindow = new TabPage( pParent, nWinBits );
1064 *ppNewComp = new VCLXTabPage;
1066 break;
1067 case WINDOW_TIMEBOX:
1068 pNewWindow = new TimeBox( pParent, nWinBits );
1069 break;
1070 case WINDOW_TIMEFIELD:
1071 pNewWindow = new TimeField( pParent, nWinBits );
1072 static_cast<TimeField*>(pNewWindow)->EnableEmptyFieldValue( true );
1073 *ppNewComp = new VCLXTimeField;
1074 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( (FormatterBase*)static_cast<TimeField*>(pNewWindow) );
1075 break;
1076 case WINDOW_TOOLBOX:
1077 pNewWindow = new ToolBox( pParent, nWinBits );
1078 *ppNewComp = new VCLXToolBox;
1079 break;
1080 case WINDOW_TRISTATEBOX:
1081 pNewWindow = new TriStateBox( pParent, nWinBits );
1082 break;
1083 case WINDOW_WARNINGBOX:
1084 pNewWindow = new WarningBox( pParent, nWinBits, OUString() );
1085 *ppNewComp = new VCLXMessageBox;
1086 break;
1087 case WINDOW_WORKWINDOW:
1088 case WINDOW_WINDOW:
1089 case VCLWINDOW_FRAMEWINDOW:
1090 case WINDOW_DOCKINGWINDOW:
1091 if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP )
1093 if (nType == WINDOW_DOCKINGWINDOW )
1094 pNewWindow = new DockingWindow( pParent, nWinBits );
1095 else
1097 if ((pParent == NULL) && rDescriptor.Parent.is())
1099 // try to get a system dependent window handle
1100 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, ::com::sun::star::uno::UNO_QUERY);
1102 if (xSystemDepParent.is())
1104 sal_Int8 processID[16];
1106 rtl_getGlobalProcessId( (sal_uInt8*)processID );
1108 ::com::sun::star::uno::Sequence<sal_Int8> processIdSeq((sal_Int8*)processID, 16);
1110 ::com::sun::star::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPE);
1112 // use sal_Int64 here to accommodate all int types
1113 // uno::Any shift operator whill upcast if necessary
1114 sal_Int64 nWindowHandle = 0;
1115 bool bXEmbed = false;
1117 bool bUseParentData = true;
1118 if( ! (anyHandle >>= nWindowHandle) )
1120 css::uno::Sequence< css::beans::NamedValue > aProps;
1121 if( anyHandle >>= aProps )
1123 const int nProps = aProps.getLength();
1124 const css::beans::NamedValue* pProps = aProps.getConstArray();
1125 for( int i = 0; i < nProps; i++ )
1127 if ( pProps[i].Name == "WINDOW" )
1128 pProps[i].Value >>= nWindowHandle;
1129 else if ( pProps[i].Name == "XEMBED" )
1130 pProps[i].Value >>= bXEmbed;
1133 else
1134 bUseParentData = false;
1137 if( bUseParentData )
1139 SystemParentData aParentData;
1140 aParentData.nSize = sizeof( aParentData );
1141 #if defined MACOSX
1142 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
1143 #elif defined ANDROID
1144 // Nothing
1145 #elif defined IOS
1146 // Nothing
1147 #elif defined UNX
1148 aParentData.aWindow = nWindowHandle;
1149 aParentData.bXEmbedSupport = bXEmbed;
1150 #elif defined WNT
1151 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1152 #endif
1153 pNewWindow = new WorkWindow( &aParentData );
1158 if (!pNewWindow)
1159 pNewWindow = new WorkWindow( pParent, nWinBits );
1162 *ppNewComp = new VCLXTopWindow( pNewWindow->GetType() == WINDOW_WORKWINDOW );
1164 else if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_CONTAINER )
1166 if (nType == WINDOW_DOCKINGWINDOW )
1167 pNewWindow = new DockingWindow( pParent, nWinBits );
1168 else
1169 pNewWindow = new vcl::Window( pParent, nWinBits );
1170 *ppNewComp = new VCLXContainer;
1172 else
1174 if (nType == WINDOW_DOCKINGWINDOW )
1175 pNewWindow = new DockingWindow( pParent, nWinBits );
1176 else
1177 pNewWindow = new vcl::Window( pParent, nWinBits );
1178 *ppNewComp = new VCLXWindow;
1180 break;
1181 case WINDOW_CONTROL:
1182 if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase(
1183 "tabpagecontainer" ) )
1185 pNewWindow = new TabControl( pParent, nWinBits );
1186 *ppNewComp = new VCLXTabPageContainer;
1188 else if ( aServiceName == "animatedimages" )
1190 pNewWindow = new Throbber( pParent, nWinBits );
1191 *ppNewComp = new ::toolkit::AnimatedImagesPeer;
1193 break;
1194 default:
1195 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" );
1196 break;
1200 return pNewWindow;
1203 #ifndef DISABLE_DYNLOADING
1205 extern "C" { static void SAL_CALL thisModule() {} }
1207 #else
1209 extern "C" vcl::Window* SAL_CALL CreateWindow( VCLXWindow** ppNewComp, const ::com::sun::star::awt::WindowDescriptor* pDescriptor, vcl::Window* pParent, WinBits nWinBits );
1211 #endif
1213 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow(
1214 const css::awt::WindowDescriptor& rDescriptor,
1215 WinBits nForceWinBits )
1217 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1219 SolarMutexGuard aSolarGuard;
1221 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef;
1223 vcl::Window* pParent = NULL;
1224 if ( rDescriptor.Parent.is() )
1226 VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( rDescriptor.Parent );
1228 // #103939# Don't throw assertion, may be it's a system dependent window, used in ImplCreateWindow.
1229 // DBG_ASSERT( pParentComponent, "ParentComponent not valid" );
1231 if ( pParentComponent )
1232 pParent = pParentComponent->GetWindow();
1234 WinBits nWinBits = ImplGetWinBits( rDescriptor.WindowAttributes,
1235 ImplGetComponentType( rDescriptor.WindowServiceName ) );
1236 nWinBits |= nForceWinBits;
1238 VCLXWindow* pNewComp = NULL;
1240 vcl::Window* pNewWindow = NULL;
1241 // Try to create the window with SvTools
1242 // (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way,
1243 // and we need to stay compatible)
1244 // try to load the lib
1245 if ( !fnSvtCreateWindow
1246 #ifndef DISABLE_DYNLOADING
1247 && !hSvToolsLib
1248 #endif
1251 #ifndef DISABLE_DYNLOADING
1252 OUString aLibName(SVT_DLL_NAME);
1253 hSvToolsLib = osl_loadModuleRelative(
1254 &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT );
1255 if ( hSvToolsLib )
1257 OUString aFunctionName( "CreateWindow" );
1258 fnSvtCreateWindow = (FN_SvtCreateWindow)osl_getFunctionSymbol( hSvToolsLib, aFunctionName.pData );
1260 #else
1261 fnSvtCreateWindow = CreateWindow;
1262 #endif
1264 // ask the SvTool creation function
1265 if ( fnSvtCreateWindow )
1266 pNewWindow = fnSvtCreateWindow( &pNewComp, &rDescriptor, pParent, nWinBits );
1268 // if SvTools could not provide a window, create it ourself
1269 if ( !pNewWindow )
1270 pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits );
1272 DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" );
1273 DBG_ASSERTWARNING( pNewComp, "createWindow: No special Interface!" );
1275 if ( pNewWindow )
1277 pNewWindow->SetCreatedWithToolkit( true );
1278 //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead
1280 if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::MINSIZE )
1282 pNewWindow->SetSizePixel( Size() );
1284 else if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::FULLSIZE )
1286 if ( pParent )
1287 pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() );
1289 else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) )
1291 Rectangle aRect = VCLRectangle( rDescriptor.Bounds );
1292 pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
1295 if ( !pNewComp )
1297 // Default-Interface
1298 xRef = pNewWindow->GetComponentInterface( true );
1300 else
1302 pNewComp->SetCreatedWithToolkit( true );
1303 xRef = pNewComp;
1304 pNewWindow->SetComponentInterface( xRef );
1306 DBG_ASSERT( pNewWindow->GetComponentInterface( false ) == xRef,
1307 "VCLXToolkit::createWindow: did #133706# resurge?" );
1309 if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::SHOW )
1310 pNewWindow->Show();
1313 return xRef;
1316 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > > VCLXToolkit::createWindows( const ::com::sun::star::uno::Sequence< ::com::sun::star::awt::WindowDescriptor >& rDescriptors ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
1318 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1320 sal_uInt32 nComponents = rDescriptors.getLength();
1321 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > > aSeq( nComponents );
1322 for ( sal_uInt32 n = 0; n < nComponents; n++ )
1324 ::com::sun::star::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n];
1326 if ( aDescr.ParentIndex == (-1) )
1327 aDescr.Parent = NULL;
1328 else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < (short)n ) )
1329 aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex];
1330 aSeq.getArray()[n] = createWindow( aDescr );
1332 return aSeq;
1335 // ::com::sun::star::awt::XSystemChildFactory
1336 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::createSystemChild( const ::com::sun::star::uno::Any& Parent, const ::com::sun::star::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 nSystemType ) throw(::com::sun::star::uno::RuntimeException, std::exception)
1338 vcl::Window* pChildWindow = NULL;
1339 if ( nSystemType == SYSTEM_DEPENDENT_TYPE )
1341 // use sal_Int64 here to accommodate all int types
1342 // uno::Any shift operator whill upcast if necessary
1343 sal_Int64 nWindowHandle = 0;
1344 bool bXEmbed = false;
1346 bool bUseParentData = true;
1347 if( ! (Parent >>= nWindowHandle) )
1349 css::uno::Sequence< css::beans::NamedValue > aProps;
1350 if( Parent >>= aProps )
1352 const int nProps = aProps.getLength();
1353 const css::beans::NamedValue* pProps = aProps.getConstArray();
1354 for( int i = 0; i < nProps; i++ )
1356 if ( pProps[i].Name == "WINDOW" )
1357 pProps[i].Value >>= nWindowHandle;
1358 else if ( pProps[i].Name == "XEMBED" )
1359 pProps[i].Value >>= bXEmbed;
1362 else
1363 bUseParentData = false;
1366 if( bUseParentData )
1368 SystemParentData aParentData;
1369 aParentData.nSize = sizeof( aParentData );
1370 #if defined MACOSX
1371 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
1372 #elif defined ANDROID
1373 // Nothing
1374 #elif defined IOS
1375 // Nothing
1376 #elif defined UNX
1377 aParentData.aWindow = nWindowHandle;
1378 aParentData.bXEmbedSupport = bXEmbed;
1379 #elif defined WNT
1380 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1381 #endif
1382 SolarMutexGuard aGuard;
1385 pChildWindow = new WorkWindow( &aParentData );
1387 catch ( const ::com::sun::star::uno::RuntimeException & rEx )
1389 // system child window could not be created
1390 OSL_TRACE(
1391 "VCLXToolkit::createSystemChild: caught %s\n",
1392 OUStringToOString(
1393 rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1394 pChildWindow = NULL;
1398 else if (nSystemType == com::sun::star::lang::SystemDependent::SYSTEM_JAVA)
1400 SolarMutexGuard aGuard;
1401 pChildWindow = new WorkWindow(0, Parent);
1404 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xPeer;
1405 if ( pChildWindow )
1407 VCLXTopWindow* pPeer = new VCLXTopWindow(true);
1408 SolarMutexGuard aGuard;
1409 pPeer->SetWindow( pChildWindow );
1410 xPeer = pPeer;
1413 return xPeer;
1416 // ::com::sun::star::awt::XMessageBoxFactory
1417 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox(
1418 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& aParent,
1419 ::com::sun::star::awt::MessageBoxType eType,
1420 ::sal_Int32 aButtons,
1421 const OUString& aTitle,
1422 const OUString& aMessage ) throw (::com::sun::star::uno::RuntimeException, std::exception)
1424 ::com::sun::star::awt::WindowDescriptor aDescriptor;
1426 sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE;
1428 // Map button definitions to window attributes
1429 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK )
1430 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK;
1431 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL )
1432 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL;
1433 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO )
1434 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO;
1435 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL )
1436 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL;
1437 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL )
1438 nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL;
1440 // Map default button definitions to window attributes
1441 if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK )
1442 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK;
1443 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL )
1444 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL;
1445 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES )
1446 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES;
1447 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO )
1448 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO;
1449 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY )
1450 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY;
1452 // No more bits for VclWindowPeerAttribute possible. Mapping must be
1453 // done explicitly using VCL methods
1454 WinBits nAddWinBits( 0 );
1455 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY )
1456 nAddWinBits |= WB_ABORT_RETRY_IGNORE;
1457 if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE )
1458 nAddWinBits |= WB_DEF_IGNORE;
1460 rtl::OUString aType;
1461 lcl_convertMessageBoxType( aType, eType );
1463 aDescriptor.Type = css::awt::WindowClass_MODALTOP;
1464 aDescriptor.WindowServiceName = aType;
1465 aDescriptor.ParentIndex = -1;
1466 aDescriptor.Parent = aParent;
1467 aDescriptor.WindowAttributes = nWindowAttributes;
1468 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > xMsgBox(
1469 ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY );
1470 css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY );
1471 if ( xMsgBox.is() && xWindow.is() )
1473 vcl::Window * pWindow = VCLUnoHelper::GetWindow( xWindow );
1474 if ( pWindow )
1476 SolarMutexGuard aGuard;
1477 xMsgBox->setCaptionText( aTitle );
1478 xMsgBox->setMessageText( aMessage );
1482 return xMsgBox;
1485 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL VCLXToolkit::getDragGestureRecognizer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& window ) throw(::com::sun::star::uno::RuntimeException, std::exception)
1487 vcl::Window * pWindow = VCLUnoHelper::GetWindow( window );
1489 if( pWindow )
1490 return pWindow->GetDragGestureRecognizer();
1492 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer >();
1495 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource > SAL_CALL VCLXToolkit::getDragSource( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& window ) throw(::com::sun::star::uno::RuntimeException, std::exception)
1497 SolarMutexGuard g;
1499 vcl::Window * pWindow = VCLUnoHelper::GetWindow( window );
1501 if( pWindow )
1502 return pWindow->GetDragSource();
1504 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource >();
1507 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTarget > SAL_CALL VCLXToolkit::getDropTarget( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& window ) throw(::com::sun::star::uno::RuntimeException, std::exception)
1509 SolarMutexGuard g;
1511 vcl::Window * pWindow = VCLUnoHelper::GetWindow( window );
1513 if( pWindow )
1514 return pWindow->GetDropTarget();
1516 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTarget >();
1519 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > SAL_CALL VCLXToolkit::getClipboard( const OUString& clipboardName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
1521 if( clipboardName.isEmpty() )
1523 if( !mxClipboard.is() )
1525 // remember clipboard here
1526 mxClipboard = css::datatransfer::clipboard::SystemClipboard::create(
1527 comphelper::getProcessComponentContext());
1530 return mxClipboard;
1533 else if( clipboardName == "Selection" )
1535 return mxSelection;
1538 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >();
1541 // XServiceInfo
1542 OUString VCLXToolkit::getImplementationName() throw(::com::sun::star::uno::RuntimeException, std::exception)
1544 return OUString("stardiv.Toolkit.VCLXToolkit");
1547 sal_Bool VCLXToolkit::supportsService( const OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
1549 return cppu::supportsService(this, rServiceName);
1552 ::com::sun::star::uno::Sequence< OUString > VCLXToolkit::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception)
1554 OUString aServiceName("com.sun.star.awt.Toolkit");
1555 return ::com::sun::star::uno::Sequence< OUString >( &aServiceName, 1);
1558 // css::awt::XExtendedToolkit:
1560 // virtual
1561 ::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount()
1562 throw (css::uno::RuntimeException, std::exception)
1564 return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount());
1565 // XXX numeric overflow
1568 // virtual
1569 css::uno::Reference< css::awt::XTopWindow > SAL_CALL
1570 VCLXToolkit::getTopWindow(::sal_Int32 nIndex)
1571 throw (css::uno::RuntimeException, std::exception)
1573 vcl::Window * p = ::Application::GetTopWindow(static_cast< long >(nIndex));
1574 // XXX numeric overflow
1575 return css::uno::Reference< css::awt::XTopWindow >(
1576 p == 0 ? 0 : static_cast< css::awt::XWindow * >(p->GetWindowPeer()),
1577 css::uno::UNO_QUERY);
1580 // virtual
1581 css::uno::Reference< css::awt::XTopWindow > SAL_CALL
1582 VCLXToolkit::getActiveTopWindow() throw (css::uno::RuntimeException, std::exception)
1584 vcl::Window * p = ::Application::GetActiveTopWindow();
1585 return css::uno::Reference< css::awt::XTopWindow >(
1586 p == 0 ? 0 : static_cast< css::awt::XWindow * >(p->GetWindowPeer()),
1587 css::uno::UNO_QUERY);
1590 // virtual
1591 void SAL_CALL VCLXToolkit::addTopWindowListener(
1592 css::uno::Reference< css::awt::XTopWindowListener > const & rListener)
1593 throw (css::uno::RuntimeException, std::exception)
1595 OSL_ENSURE(rListener.is(), "Null rListener");
1596 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1597 if (rBHelper.bDisposed || rBHelper.bInDispose)
1599 aGuard.clear();
1600 rListener->disposing(
1601 css::lang::EventObject(
1602 static_cast< ::cppu::OWeakObject * >(this)));
1604 else if (m_aTopWindowListeners.addInterface(rListener) == 1
1605 && !m_bEventListener)
1607 m_bEventListener = true;
1608 ::Application::AddEventListener(m_aEventListenerLink);
1612 // virtual
1613 void SAL_CALL VCLXToolkit::removeTopWindowListener(
1614 css::uno::Reference< css::awt::XTopWindowListener > const & rListener)
1615 throw (css::uno::RuntimeException, std::exception)
1617 ::osl::MutexGuard aGuard(rBHelper.rMutex);
1618 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1619 && m_aTopWindowListeners.removeInterface(rListener) == 0
1620 && m_aFocusListeners.getLength() == 0 && m_bEventListener)
1622 ::Application::RemoveEventListener(m_aEventListenerLink);
1623 m_bEventListener = false;
1627 // virtual
1628 void SAL_CALL VCLXToolkit::addKeyHandler(
1629 css::uno::Reference< css::awt::XKeyHandler > const & rHandler)
1630 throw (css::uno::RuntimeException, std::exception)
1632 OSL_ENSURE(rHandler.is(), "Null rHandler");
1633 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1634 if (rBHelper.bDisposed || rBHelper.bInDispose)
1636 aGuard.clear();
1637 rHandler->disposing(
1638 css::lang::EventObject(
1639 static_cast< ::cppu::OWeakObject * >(this)));
1641 else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener)
1643 m_bKeyListener = true;
1644 ::Application::AddKeyListener(m_aKeyListenerLink);
1648 // virtual
1649 void SAL_CALL VCLXToolkit::removeKeyHandler(
1650 css::uno::Reference< css::awt::XKeyHandler > const & rHandler)
1651 throw (css::uno::RuntimeException, std::exception)
1653 ::osl::MutexGuard aGuard(rBHelper.rMutex);
1654 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1655 && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener)
1657 ::Application::RemoveKeyListener(m_aKeyListenerLink);
1658 m_bKeyListener = false;
1662 // virtual
1663 void SAL_CALL VCLXToolkit::addFocusListener(
1664 css::uno::Reference< css::awt::XFocusListener > const & rListener)
1665 throw (css::uno::RuntimeException, std::exception)
1667 OSL_ENSURE(rListener.is(), "Null rListener");
1668 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1669 if (rBHelper.bDisposed || rBHelper.bInDispose)
1671 aGuard.clear();
1672 rListener->disposing(
1673 css::lang::EventObject(
1674 static_cast< ::cppu::OWeakObject * >(this)));
1676 else if (m_aFocusListeners.addInterface(rListener) == 1
1677 && !m_bEventListener)
1679 m_bEventListener = true;
1680 ::Application::AddEventListener(m_aEventListenerLink);
1684 // virtual
1685 void SAL_CALL VCLXToolkit::removeFocusListener(
1686 css::uno::Reference< css::awt::XFocusListener > const & rListener)
1687 throw (css::uno::RuntimeException, std::exception)
1689 ::osl::MutexGuard aGuard(rBHelper.rMutex);
1690 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1691 && m_aFocusListeners.removeInterface(rListener) == 0
1692 && m_aTopWindowListeners.getLength() == 0 && m_bEventListener)
1694 ::Application::RemoveEventListener(m_aEventListenerLink);
1695 m_bEventListener = false;
1699 // virtual
1700 void SAL_CALL VCLXToolkit::fireFocusGained(
1701 ::com::sun::star::uno::Reference<
1702 ::com::sun::star::uno::XInterface > const &)
1703 throw (::com::sun::star::uno::RuntimeException, std::exception)
1707 // virtual
1708 void SAL_CALL VCLXToolkit::fireFocusLost(
1709 ::com::sun::star::uno::Reference<
1710 ::com::sun::star::uno::XInterface > const &)
1711 throw (::com::sun::star::uno::RuntimeException, std::exception)
1716 IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent const *, pEvent)
1718 switch (pEvent->GetId())
1720 case VCLEVENT_WINDOW_SHOW:
1721 callTopWindowListeners(
1722 pEvent, &css::awt::XTopWindowListener::windowOpened);
1723 break;
1724 case VCLEVENT_WINDOW_HIDE:
1725 callTopWindowListeners(
1726 pEvent, &css::awt::XTopWindowListener::windowClosed);
1727 break;
1728 case VCLEVENT_WINDOW_ACTIVATE:
1729 callTopWindowListeners(
1730 pEvent, &css::awt::XTopWindowListener::windowActivated);
1731 break;
1732 case VCLEVENT_WINDOW_DEACTIVATE:
1733 callTopWindowListeners(
1734 pEvent, &css::awt::XTopWindowListener::windowDeactivated);
1735 break;
1736 case VCLEVENT_WINDOW_CLOSE:
1737 callTopWindowListeners(
1738 pEvent, &css::awt::XTopWindowListener::windowClosing);
1739 break;
1740 case VCLEVENT_WINDOW_GETFOCUS:
1741 callFocusListeners(pEvent, true);
1742 break;
1743 case VCLEVENT_WINDOW_LOSEFOCUS:
1744 callFocusListeners(pEvent, false);
1745 break;
1746 case VCLEVENT_WINDOW_MINIMIZE:
1747 callTopWindowListeners(
1748 pEvent, &css::awt::XTopWindowListener::windowMinimized);
1749 break;
1750 case VCLEVENT_WINDOW_NORMALIZE:
1751 callTopWindowListeners(
1752 pEvent, &css::awt::XTopWindowListener::windowNormalized);
1753 break;
1755 return 0;
1758 IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclSimpleEvent const *, pEvent)
1760 switch (pEvent->GetId())
1762 case VCLEVENT_WINDOW_KEYINPUT:
1763 return callKeyHandlers(pEvent, true);
1764 case VCLEVENT_WINDOW_KEYUP:
1765 return callKeyHandlers(pEvent, false);
1767 return 0;
1770 void VCLXToolkit::callTopWindowListeners(
1771 ::VclSimpleEvent const * pEvent,
1772 void (SAL_CALL css::awt::XTopWindowListener::* pFn)(
1773 css::lang::EventObject const &))
1775 vcl::Window * pWindow
1776 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1777 if (pWindow->IsTopWindow())
1779 css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >
1780 aListeners(m_aTopWindowListeners.getElements());
1781 if (aListeners.hasElements())
1783 css::lang::EventObject aAwtEvent(
1784 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()));
1785 for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i)
1787 css::uno::Reference< css::awt::XTopWindowListener >
1788 xListener(aListeners[i], css::uno::UNO_QUERY);
1791 (xListener.get()->*pFn)(aAwtEvent);
1793 catch (const css::uno::RuntimeException & rEx)
1795 OSL_TRACE(
1796 "VCLXToolkit::callTopWindowListeners: caught %s\n",
1797 OUStringToOString(
1798 rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1805 long VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent,
1806 bool bPressed)
1808 css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >
1809 aHandlers(m_aKeyHandlers.getElements());
1811 if (aHandlers.hasElements())
1813 vcl::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1815 // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event
1816 ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >(
1817 static_cast< ::VclWindowEvent const * >(pEvent)->GetData());
1818 css::awt::KeyEvent aAwtEvent(
1819 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
1820 (pKeyEvent->GetKeyCode().IsShift()
1821 ? css::awt::KeyModifier::SHIFT : 0)
1822 | (pKeyEvent->GetKeyCode().IsMod1()
1823 ? css::awt::KeyModifier::MOD1 : 0)
1824 | (pKeyEvent->GetKeyCode().IsMod2()
1825 ? css::awt::KeyModifier::MOD2 : 0)
1826 | (pKeyEvent->GetKeyCode().IsMod3()
1827 ? css::awt::KeyModifier::MOD3 : 0),
1828 pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(),
1829 sal::static_int_cast< sal_Int16 >(
1830 pKeyEvent->GetKeyCode().GetFunction()));
1831 for (::sal_Int32 i = 0; i < aHandlers.getLength(); ++i)
1833 css::uno::Reference< css::awt::XKeyHandler > xHandler(
1834 aHandlers[i], css::uno::UNO_QUERY);
1837 if ((bPressed ? xHandler->keyPressed(aAwtEvent)
1838 : xHandler->keyReleased(aAwtEvent)))
1839 return 1;
1841 catch (const css::uno::RuntimeException & rEx)
1843 OSL_TRACE(
1844 "VCLXToolkit::callKeyHandlers: caught %s\n",
1845 OUStringToOString(
1846 rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1850 return 0;
1853 void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent,
1854 bool bGained)
1856 vcl::Window * pWindow
1857 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1858 if (pWindow->IsTopWindow())
1860 css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >
1861 aListeners(m_aFocusListeners.getElements());
1862 if (aListeners.hasElements())
1864 // Ignore the interior of compound controls when determining the
1865 // window that gets the focus next (see implementation in
1866 // vclxwindow.cxx for mapping between VCL and UNO AWT event):
1867 css::uno::Reference< css::uno::XInterface > xNext;
1868 vcl::Window * pFocus = ::Application::GetFocusWindow();
1869 for (vcl::Window * p = pFocus; p != 0; p = p->GetParent())
1870 if (!p->IsCompoundControl())
1872 pFocus = p;
1873 break;
1875 if (pFocus != 0)
1876 xNext = pFocus->GetComponentInterface(true);
1877 css::awt::FocusEvent aAwtEvent(
1878 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
1879 pWindow->GetGetFocusFlags(), xNext, false);
1880 for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i)
1882 css::uno::Reference< css::awt::XFocusListener > xListener(
1883 aListeners[i], css::uno::UNO_QUERY);
1886 bGained ? xListener->focusGained(aAwtEvent)
1887 : xListener->focusLost(aAwtEvent);
1889 catch (const css::uno::RuntimeException & rEx)
1891 OSL_TRACE(
1892 "VCLXToolkit::callFocusListeners: caught %s\n",
1893 OUStringToOString(
1894 rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1901 // css::awt::XReschedule:
1903 void SAL_CALL VCLXToolkit::reschedule()
1904 throw (::com::sun::star::uno::RuntimeException, std::exception)
1906 SolarMutexGuard aSolarGuard;
1907 Application::Reschedule(true);
1910 void SAL_CALL VCLXToolkit::processEventsToIdle()
1911 throw (::com::sun::star::uno::RuntimeException, std::exception)
1913 SolarMutexGuard aSolarGuard;
1914 Timer::ProcessAllIdleHandlers();
1919 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
1920 stardiv_Toolkit_VCLXToolkit_get_implementation(
1921 css::uno::XComponentContext *,
1922 css::uno::Sequence<css::uno::Any> const &)
1924 return cppu::acquire(new VCLXToolkit());
1927 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */