Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / toolkit / source / awt / vclxtoolkit.cxx
blob8879054c8cead8ca765adf13e583d19e968118ad
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 .
21 #include <boost/ptr_container/ptr_vector.hpp>
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <stdio.h>
26 #ifdef WNT
27 #include <prewin.h>
28 #include <postwin.h>
29 #endif
30 #include <com/sun/star/awt/ImageScaleMode.hpp>
31 #include <com/sun/star/awt/WindowAttribute.hpp>
32 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
33 #include <com/sun/star/awt/WindowClass.hpp>
34 #include <com/sun/star/awt/MessageBoxButtons.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/lang/SystemDependent.hpp>
37 #include <com/sun/star/awt/FocusEvent.hpp>
38 #include <com/sun/star/awt/KeyEvent.hpp>
39 #include <com/sun/star/awt/KeyModifier.hpp>
40 #include <com/sun/star/lang/EventObject.hpp>
41 #include <com/sun/star/uno/Reference.hxx>
42 #include <com/sun/star/uno/Sequence.hxx>
43 #include <com/sun/star/uno/XInterface.hpp>
44 #include <com/sun/star/beans/NamedValue.hpp>
45 #include <cppuhelper/typeprovider.hxx>
46 #include <osl/conditn.hxx>
47 #include <rtl/uuid.h>
48 #include <rtl/process.h>
50 #ifdef QUARTZ
51 #include "premac.h"
52 #include <Cocoa/Cocoa.h>
53 #include "postmac.h"
54 #endif
56 #ifdef ANDROID
57 #include <sal/ByteBufferWrapper.hxx>
58 using org::libreoffice::touch::ByteBufferWrapper;
59 #endif
61 #ifdef IOS
62 #include "premac.h"
63 #include <UIKit/UIKit.h>
64 #include "postmac.h"
65 #endif
67 #include <vcl/sysdata.hxx>
69 #include <toolkit/awt/vclxwindows.hxx>
70 #include <toolkit/awt/vclxsystemdependentwindow.hxx>
71 #include <toolkit/awt/vclxregion.hxx>
72 #include <toolkit/awt/vclxtoolkit.hxx>
73 #include <toolkit/awt/vclxtabpagecontainer.hxx>
74 #include <toolkit/awt/vclxtabpagemodel.hxx>
76 #include <toolkit/awt/xsimpleanimation.hxx>
77 #include <toolkit/awt/xthrobber.hxx>
78 #include <toolkit/awt/animatedimagespeer.hxx>
79 #include <toolkit/awt/vclxtopwindow.hxx>
80 #include <toolkit/awt/vclxwindow.hxx>
81 #include <toolkit/helper/vclunohelper.hxx>
82 #include <toolkit/helper/unowrapper.hxx>
83 #include <toolkit/helper/servicenames.hxx>
85 #include <toolkit/helper/macros.hxx>
86 #include <toolkit/helper/convert.hxx>
87 #include <vcl/unohelp.hxx>
88 #include <vcl/btndlg.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 "toolkit/awt/scrollabledialog.hxx"
123 #include <tools/debug.hxx>
124 #include <comphelper/processfactory.hxx>
125 #include <toolkit/awt/scrollabledialog.hxx>
127 #define VCLWINDOW_FRAMEWINDOW 0x1000
128 #define VCLWINDOW_SYSTEMCHILDWINDOW 0x1001
130 #if (defined WNT)
131 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32
132 #elif (defined QUARTZ)
133 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_MAC
134 #elif (defined UNX)
135 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW
136 #endif
138 TOOLKIT_DLLPUBLIC WinBits ImplGetWinBits( sal_uInt32 nComponentAttribs, sal_uInt16 nCompType )
140 WinBits nWinBits = 0;
142 sal_Bool bMessBox = sal_False;
143 if ( ( nCompType == WINDOW_INFOBOX ) ||
144 ( nCompType == WINDOW_MESSBOX ) ||
145 ( nCompType == WINDOW_QUERYBOX ) ||
146 ( nCompType == WINDOW_WARNINGBOX ) ||
147 ( nCompType == WINDOW_ERRORBOX ) )
149 bMessBox = sal_True;
152 bool bDecoratedWindow = false;
153 if ( bMessBox
154 || ( nCompType == WINDOW_DIALOG )
155 || ( nCompType == WINDOW_MODELESSDIALOG )
156 || ( nCompType == WINDOW_MODALDIALOG )
157 || ( nCompType == WINDOW_SYSTEMDIALOG )
158 || ( nCompType == WINDOW_PATHDIALOG )
159 || ( nCompType == WINDOW_FILEDIALOG )
160 || ( nCompType == WINDOW_PRINTERSETUPDIALOG )
161 || ( nCompType == WINDOW_PRINTDIALOG )
162 || ( nCompType == WINDOW_COLORDIALOG )
163 || ( nCompType == WINDOW_FONTDIALOG )
164 || ( nCompType == WINDOW_DOCKINGWINDOW )
165 || ( nCompType == WINDOW_TABDIALOG )
166 || ( nCompType == WINDOW_BUTTONDIALOG )
167 || ( nCompType == WINDOW_SYSTEMCHILDWINDOW )
170 bDecoratedWindow = true;
173 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::BORDER )
174 nWinBits |= WB_BORDER;
175 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::NOBORDER )
176 nWinBits |= WB_NOBORDER;
177 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::SIZEABLE )
178 nWinBits |= WB_SIZEABLE;
179 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::MOVEABLE )
180 nWinBits |= WB_MOVEABLE;
181 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::CLOSEABLE )
182 nWinBits |= WB_CLOSEABLE;
183 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::HSCROLL )
184 nWinBits |= WB_HSCROLL;
185 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL )
186 nWinBits |= WB_VSCROLL;
187 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::LEFT )
188 nWinBits |= WB_LEFT;
189 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::CENTER )
190 nWinBits |= WB_CENTER;
191 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::RIGHT )
192 nWinBits |= WB_RIGHT;
193 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::SPIN )
194 nWinBits |= WB_SPIN;
195 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::SORT )
196 nWinBits |= WB_SORT;
197 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DROPDOWN )
198 nWinBits |= WB_DROPDOWN;
199 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEFBUTTON )
200 nWinBits |= WB_DEFBUTTON;
201 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::READONLY )
202 nWinBits |= WB_READONLY;
203 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::CLIPCHILDREN )
204 nWinBits |= WB_CLIPCHILDREN;
205 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::GROUP )
206 nWinBits |= WB_GROUP;
207 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::NOLABEL ) //added for issue79712
208 nWinBits |= WB_NOLABEL;
210 // These bits are not uniqe
211 if ( bMessBox )
213 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::OK )
214 nWinBits |= WB_OK;
215 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::OK_CANCEL )
216 nWinBits |= WB_OK_CANCEL;
217 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO )
218 nWinBits |= WB_YES_NO;
219 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO_CANCEL )
220 nWinBits |= WB_YES_NO_CANCEL;
221 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::RETRY_CANCEL )
222 nWinBits |= WB_RETRY_CANCEL;
223 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_OK )
224 nWinBits |= WB_DEF_OK;
225 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_CANCEL )
226 nWinBits |= WB_DEF_CANCEL;
227 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_RETRY )
228 nWinBits |= WB_DEF_RETRY;
229 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_YES )
230 nWinBits |= WB_DEF_YES;
231 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_NO )
232 nWinBits |= WB_DEF_NO;
234 if ( nCompType == WINDOW_MULTILINEEDIT || nCompType == WINDOW_DIALOG || WINDOW_GROUPBOX )
236 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::AUTOHSCROLL )
237 nWinBits |= WB_AUTOHSCROLL;
238 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::AUTOVSCROLL )
239 nWinBits |= WB_AUTOVSCROLL;
243 if ( bDecoratedWindow )
245 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::NODECORATION )
247 // No decoration removes several window attributes and must
248 // set WB_NOBORDER!
249 nWinBits &= ~WB_BORDER;
250 nWinBits &= ~WB_SIZEABLE;
251 nWinBits &= ~WB_MOVEABLE;
252 nWinBits &= ~WB_CLOSEABLE;
253 nWinBits |= WB_NOBORDER;
257 return nWinBits;
260 struct ComponentInfo
262 const char* pName;
263 WindowType nWinType;
266 static ComponentInfo aComponentInfos [] =
268 { "buttondialog", WINDOW_BUTTONDIALOG },
269 { "cancelbutton", WINDOW_CANCELBUTTON },
270 { "checkbox", WINDOW_CHECKBOX },
271 { "combobox", WINDOW_COMBOBOX },
272 { "control", WINDOW_CONTROL },
273 { "currencybox", WINDOW_CURRENCYBOX },
274 { "currencyfield", WINDOW_CURRENCYFIELD },
275 { "datebox", WINDOW_DATEBOX },
276 { "datefield", WINDOW_DATEFIELD },
277 { "dialog", WINDOW_DIALOG },
278 { "dockingarea", WINDOW_DOCKINGAREA },
279 { "dockingwindow", WINDOW_DOCKINGWINDOW },
280 { "edit", WINDOW_EDIT },
281 { "errorbox", WINDOW_ERRORBOX },
282 { "fixedbitmap", WINDOW_FIXEDBITMAP },
283 { "fixedimage", WINDOW_FIXEDIMAGE },
284 { "fixedline", WINDOW_FIXEDLINE },
285 { "fixedtext", WINDOW_FIXEDTEXT },
286 { "floatingwindow", WINDOW_FLOATINGWINDOW },
287 { "framewindow", VCLWINDOW_FRAMEWINDOW },
288 { "groupbox", WINDOW_GROUPBOX },
289 { "frame", WINDOW_GROUPBOX },
290 { "helpbutton", WINDOW_HELPBUTTON },
291 { "imagebutton", WINDOW_IMAGEBUTTON },
292 { "imageradiobutton", WINDOW_IMAGERADIOBUTTON },
293 { "infobox", WINDOW_INFOBOX },
294 { "listbox", WINDOW_LISTBOX },
295 { "longcurrencybox", WINDOW_LONGCURRENCYBOX },
296 { "longcurrencyfield", WINDOW_LONGCURRENCYFIELD },
297 { "menubutton", WINDOW_MENUBUTTON },
298 { "messbox", WINDOW_MESSBOX },
299 { "metricbox", WINDOW_METRICBOX },
300 { "metricfield", WINDOW_METRICFIELD },
301 { "modaldialog", WINDOW_MODALDIALOG },
302 { "modelessdialog", WINDOW_MODELESSDIALOG },
303 { "morebutton", WINDOW_MOREBUTTON },
304 { "multilineedit", WINDOW_MULTILINEEDIT },
305 { "multilistbox", WINDOW_MULTILISTBOX },
306 { "numericbox", WINDOW_NUMERICBOX },
307 { "numericfield", WINDOW_NUMERICFIELD },
308 { "okbutton", WINDOW_OKBUTTON },
309 { "patternbox", WINDOW_PATTERNBOX },
310 { "patternfield", WINDOW_PATTERNFIELD },
311 { "pushbutton", WINDOW_PUSHBUTTON },
312 { "querybox", WINDOW_QUERYBOX },
313 { "radiobutton", WINDOW_RADIOBUTTON },
314 { "scrollbar", WINDOW_SCROLLBAR },
315 { "scrollbarbox", WINDOW_SCROLLBARBOX },
316 { "simpleanimation", WINDOW_CONTROL },
317 { "animatedimages", WINDOW_CONTROL },
318 { "spinbutton", WINDOW_SPINBUTTON },
319 { "spinfield", WINDOW_SPINFIELD },
320 { "throbber", WINDOW_CONTROL },
321 { "splitter", WINDOW_SPLITTER },
322 { "splitwindow", WINDOW_SPLITWINDOW },
323 { "statusbar", WINDOW_STATUSBAR },
324 { "systemchildwindow", VCLWINDOW_SYSTEMCHILDWINDOW },
325 { "tabcontrol", WINDOW_TABCONTROL },
326 { "tabdialog", WINDOW_TABDIALOG },
327 { "tabpage", WINDOW_TABPAGE },
328 { "timebox", WINDOW_TIMEBOX },
329 { "timefield", WINDOW_TIMEFIELD },
330 { "toolbox", WINDOW_TOOLBOX },
331 { "tristatebox", WINDOW_TRISTATEBOX },
332 { "warningbox", WINDOW_WARNINGBOX },
333 { "window", WINDOW_WINDOW },
334 { "workwindow", WINDOW_WORKWINDOW },
335 { "tabpagecontainer", WINDOW_CONTROL },
336 { "tabpagemodel", WINDOW_TABPAGE }
339 extern "C"
341 static int SAL_CALL ComponentInfoCompare( const void* pFirst, const void* pSecond)
343 return( strcmp( ((ComponentInfo*)pFirst)->pName,
344 ((ComponentInfo*)pSecond)->pName ) );
348 sal_uInt16 ImplGetComponentType( const String& rServiceName )
350 static sal_Bool bSorted = sal_False;
351 if( !bSorted )
353 qsort( (void*) aComponentInfos,
354 sizeof( aComponentInfos ) / sizeof( ComponentInfo ),
355 sizeof( ComponentInfo ),
356 ComponentInfoCompare );
357 bSorted = sal_True;
361 ComponentInfo aSearch;
362 rtl::OString aServiceName(rtl::OUStringToOString(rServiceName, osl_getThreadTextEncoding()).toAsciiLowerCase());
363 if ( !aServiceName.isEmpty() )
364 aSearch.pName = aServiceName.getStr();
365 else
366 aSearch.pName = "window";
368 ComponentInfo* pInf = (ComponentInfo*) bsearch( &aSearch,
369 (void*) aComponentInfos,
370 sizeof( aComponentInfos ) / sizeof( ComponentInfo ),
371 sizeof( ComponentInfo ),
372 ComponentInfoCompare );
374 return pInf ? pInf->nWinType : 0;
378 // ----------------------------------------------------
379 // class VCLXToolkit
380 // ----------------------------------------------------
382 static sal_Int32 nVCLToolkitInstanceCount = 0;
383 static sal_Bool bInitedByVCLToolkit = sal_False;
385 static osl::Mutex & getInitMutex()
387 static osl::Mutex * pM;
388 if( !pM )
390 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
391 if( !pM )
393 static osl::Mutex aMutex;
394 pM = &aMutex;
397 return *pM;
400 static osl::Condition & getInitCondition()
402 static osl::Condition * pC = 0;
403 if( !pC )
405 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
406 if( !pC )
408 static osl::Condition aCondition;
409 pC = &aCondition;
412 return *pC;
415 extern "C"
417 static void SAL_CALL ToolkitWorkerFunction( void* pArgs )
419 VCLXToolkit * pTk = (VCLXToolkit *)pArgs;
420 bInitedByVCLToolkit = InitVCL();
421 if( bInitedByVCLToolkit )
423 UnoWrapper* pUnoWrapper = new UnoWrapper( pTk );
424 Application::SetUnoWrapper( pUnoWrapper );
426 getInitCondition().set();
427 if( bInitedByVCLToolkit )
430 SolarMutexGuard aGuard;
431 Application::Execute();
435 pTk->dispose();
437 catch( com::sun::star::uno::Exception & )
440 DeInitVCL();
442 else
444 JoinMainLoopThread();
449 // contructor, which might initialize VCL
450 VCLXToolkit::VCLXToolkit():
451 cppu::WeakComponentImplHelper2<
452 ::com::sun::star::awt::XToolkitExperimental,
453 ::com::sun::star::lang::XServiceInfo>( GetMutex() ),
454 m_aTopWindowListeners(rBHelper.rMutex),
455 m_aKeyHandlers(rBHelper.rMutex),
456 m_aFocusListeners(rBHelper.rMutex),
457 m_aEventListenerLink(LINK(this, VCLXToolkit, eventListenerHandler)),
458 m_aKeyListenerLink(LINK(this, VCLXToolkit, keyListenerHandler)),
459 m_bEventListener(false),
460 m_bKeyListener(false)
462 hSvToolsLib = NULL;
463 fnSvtCreateWindow = NULL;
465 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
466 nVCLToolkitInstanceCount++;
467 if( ( nVCLToolkitInstanceCount == 1 ) && ( !Application::IsInMain() ) )
469 // setup execute thread
470 CreateMainLoopThread( ToolkitWorkerFunction, this );
471 getInitCondition().wait();
475 VCLXToolkit::~VCLXToolkit()
480 void SAL_CALL VCLXToolkit::disposing()
482 #ifndef DISABLE_DYNLOADING
483 if ( hSvToolsLib )
485 osl_unloadModule( hSvToolsLib );
486 hSvToolsLib = NULL;
487 fnSvtCreateWindow = NULL;
489 #endif
492 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
493 if( --nVCLToolkitInstanceCount == 0 )
495 if( bInitedByVCLToolkit )
497 Application::Quit();
498 JoinMainLoopThread();
499 bInitedByVCLToolkit = sal_False;
504 if (m_bEventListener)
506 ::Application::RemoveEventListener(m_aEventListenerLink);
507 m_bEventListener = false;
509 if (m_bKeyListener)
511 ::Application::RemoveKeyListener(m_aKeyListenerLink);
512 m_bKeyListener = false;
514 ::css::lang::EventObject aEvent(
515 static_cast< ::cppu::OWeakObject * >(this));
516 m_aTopWindowListeners.disposeAndClear(aEvent);
517 m_aKeyHandlers.disposeAndClear(aEvent);
518 m_aFocusListeners.disposeAndClear(aEvent);
522 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::getDesktopWindow( ) throw(::com::sun::star::uno::RuntimeException)
524 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef;
525 // 07/00: AppWindow doesn't exist anymore...
526 return xRef;
529 ::com::sun::star::awt::Rectangle VCLXToolkit::getWorkArea( ) throw(::com::sun::star::uno::RuntimeException)
531 ::com::sun::star::awt::Rectangle aRect;
532 // 07/00: AppWindow doesn't exist anymore...
533 return aRect;
536 ::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)
538 return ImplCreateWindow( rDescriptor, WinBits(0) );
541 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) throw(::com::sun::star::uno::RuntimeException)
543 return createScreenCompatibleDeviceUsingBuffer( Width, Height, 1, 1, 0, 0, 0 );
546 ::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)
548 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
550 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > xRef;
551 VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
553 SolarMutexGuard aSolarGuard;
555 VirtualDevice* pV = new VirtualDevice;
556 if ( addressOfMemoryBufferForSharedArrayWrapper != 0 ) {
557 #if defined(ANDROID)
558 ByteBufferWrapper *bbw = (ByteBufferWrapper *) (intptr_t) addressOfMemoryBufferForSharedArrayWrapper;
559 pV->SetOutputSizePixelScaleOffsetAndBuffer( Size( Width, Height ), Fraction(ScaleNumerator, ScaleDenominator), Point( XOffset, YOffset), basebmp::RawMemorySharedArray( bbw->pointer(), *bbw ));
560 #else
561 (void) ScaleNumerator;
562 (void) ScaleDenominator;
563 (void) XOffset;
564 (void) YOffset;
565 OSL_FAIL( "rendering to a pre-allocated buffer not done yet for this OS" );
566 pV->SetOutputSizePixel( Size( Width, Height ) );
567 #endif
568 } else {
569 pV->SetOutputSizePixel( Size( Width, Height ) );
571 pVDev->SetVirtualDevice( pV );
573 xRef = pVDev;
574 return xRef;
577 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion > VCLXToolkit::createRegion( ) throw(::com::sun::star::uno::RuntimeException)
579 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
581 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion > xRef = new VCLXRegion;
582 return xRef;
585 Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp,
586 const ::com::sun::star::awt::WindowDescriptor& rDescriptor,
587 Window* pParent, WinBits nWinBits )
589 String aServiceName( rDescriptor.WindowServiceName );
590 aServiceName.ToLowerAscii();
592 Window* pNewWindow = NULL;
593 sal_uInt16 nType = ImplGetComponentType( aServiceName );
594 bool bFrameControl = false;
595 if ( aServiceName == String( RTL_CONSTASCII_USTRINGPARAM("frame") ) )
596 bFrameControl = true;
597 if ( aServiceName == String( RTL_CONSTASCII_USTRINGPARAM("tabcontrolnotabs") ) )
599 nWinBits |= WB_NOBORDER;
600 nType = ImplGetComponentType( String( RTL_CONSTASCII_USTRINGPARAM("tabcontrol") ) );
602 if ( !pParent )
604 // Wenn die Component einen Parent braucht, dann NULL zurueckgeben,
605 // spaeter mal ::com::sun::star::uno::Exception...
606 sal_Bool bException = sal_True;
607 if ( ( nType == WINDOW_DIALOG )
608 || ( nType == WINDOW_MODALDIALOG )
609 || ( nType == WINDOW_MODELESSDIALOG )
610 || ( nType == WINDOW_MESSBOX )
611 || ( nType == WINDOW_INFOBOX )
612 || ( nType == WINDOW_WARNINGBOX )
613 || ( nType == WINDOW_ERRORBOX )
614 || ( nType == WINDOW_QUERYBOX )
616 bException = sal_False;
617 else if ( ( nType == WINDOW_WINDOW ) ||
618 ( nType == WINDOW_WORKWINDOW ) ||
619 ( nType == VCLWINDOW_FRAMEWINDOW ) )
621 if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP )
622 bException = sal_False;
625 if ( bException )
627 *ppNewComp = NULL;
628 return NULL;
632 if ( nType )
634 SolarMutexGuard aVclGuard;
635 switch ( (WindowType)nType )
637 case WINDOW_CANCELBUTTON:
638 pNewWindow = new CancelButton( pParent, nWinBits );
639 *ppNewComp = new VCLXButton;
640 break;
641 case WINDOW_CHECKBOX:
642 pNewWindow = new CheckBox( pParent, nWinBits );
643 *ppNewComp = new VCLXCheckBox;
644 break;
645 case WINDOW_COMBOBOX:
646 pNewWindow = new ComboBox( pParent, nWinBits|WB_AUTOHSCROLL );
647 ((ComboBox*)pNewWindow)->EnableAutoSize( sal_False );
648 *ppNewComp = new VCLXComboBox;
649 break;
650 case WINDOW_CURRENCYBOX:
651 pNewWindow = new CurrencyBox( pParent, nWinBits );
652 break;
653 case WINDOW_CURRENCYFIELD:
654 pNewWindow = new CurrencyField( pParent, nWinBits );
655 static_cast<CurrencyField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
656 *ppNewComp = new VCLXNumericField;
657 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(CurrencyField*)pNewWindow );
658 break;
659 case WINDOW_DATEBOX:
660 pNewWindow = new DateBox( pParent, nWinBits );
661 break;
662 case WINDOW_DATEFIELD:
663 pNewWindow = new DateField( pParent, nWinBits );
664 static_cast<DateField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
665 *ppNewComp = new VCLXDateField;
666 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(DateField*)pNewWindow );
667 break;
668 case WINDOW_DOCKINGAREA:
669 pNewWindow = new DockingAreaWindow( pParent );
670 break;
671 case WINDOW_MULTILINEEDIT:
672 case WINDOW_EDIT:
673 pNewWindow = new Edit( pParent, nWinBits );
674 *ppNewComp = new VCLXEdit;
675 break;
676 case WINDOW_ERRORBOX:
677 pNewWindow = new ErrorBox( pParent, nWinBits, String() );
678 *ppNewComp = new VCLXMessageBox;
679 break;
680 case WINDOW_FIXEDBITMAP:
681 pNewWindow = new FixedBitmap( pParent, nWinBits );
682 break;
683 case WINDOW_FIXEDIMAGE:
684 pNewWindow = new ImageControl( pParent, nWinBits );
685 *ppNewComp = new VCLXImageControl;
686 break;
687 case WINDOW_FIXEDLINE:
688 pNewWindow = new FixedLine( pParent, nWinBits );
689 break;
690 case WINDOW_FIXEDTEXT:
691 pNewWindow = new FixedText( pParent, nWinBits );
692 *ppNewComp = new VCLXFixedText;
693 break;
694 case WINDOW_FLOATINGWINDOW:
695 pNewWindow = new FloatingWindow( pParent, nWinBits );
696 break;
697 case WINDOW_GROUPBOX:
699 #if SCROLLABLEFRAME
700 if ( bFrameControl )
702 pNewWindow = new toolkit::ScrollableWrapper< GroupBox >( pParent, nWinBits | WB_VSCROLL );
704 else
705 #endif
706 pNewWindow = new GroupBox( pParent, nWinBits );
707 if ( bFrameControl )
709 GroupBox* pGroupBox = static_cast< GroupBox* >( pNewWindow );
710 *ppNewComp = new VCLXFrame;
711 // Frame control needs to recieve
712 // Mouse events
713 pGroupBox->SetMouseTransparent( sal_False );
716 break;
717 case WINDOW_HELPBUTTON:
718 pNewWindow = new HelpButton( pParent, nWinBits );
719 *ppNewComp = new VCLXButton;
720 break;
721 case WINDOW_IMAGEBUTTON:
722 pNewWindow = new ImageButton( pParent, nWinBits );
723 *ppNewComp = new VCLXButton;
724 break;
725 case WINDOW_IMAGERADIOBUTTON:
726 pNewWindow = new ImageRadioButton( pParent, nWinBits );
727 *ppNewComp = new VCLXButton;
728 break;
729 case WINDOW_INFOBOX:
730 pNewWindow = new InfoBox( pParent, String() );
731 *ppNewComp = new VCLXMessageBox;
732 break;
733 case WINDOW_LISTBOX:
734 pNewWindow = new ListBox( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL );
735 ((ListBox*)pNewWindow)->EnableAutoSize( sal_False );
736 *ppNewComp = new VCLXListBox;
737 break;
738 case WINDOW_LONGCURRENCYBOX:
739 pNewWindow = new LongCurrencyBox( pParent, nWinBits );
740 break;
741 case WINDOW_LONGCURRENCYFIELD:
742 pNewWindow = new LongCurrencyField( pParent, nWinBits );
743 *ppNewComp = new VCLXCurrencyField;
744 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(LongCurrencyField*)pNewWindow );
745 break;
746 case WINDOW_MENUBUTTON:
747 pNewWindow = new MenuButton( pParent, nWinBits );
748 *ppNewComp = new VCLXButton;
749 break;
750 case WINDOW_MESSBOX:
751 pNewWindow = new MessBox( pParent, nWinBits, String(), String() );
752 *ppNewComp = new VCLXMessageBox;
753 break;
754 case WINDOW_METRICBOX:
755 pNewWindow = new MetricBox( pParent, nWinBits );
756 break;
757 case WINDOW_METRICFIELD:
758 pNewWindow = new MetricField( pParent, nWinBits );
759 *ppNewComp = new VCLXMetricField;
760 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(MetricField*)pNewWindow );
761 break;
762 case WINDOW_DIALOG:
763 case WINDOW_MODALDIALOG:
764 case WINDOW_MODELESSDIALOG:
766 // Modal/Modeless nur durch Show/Execute
767 if ( (pParent == NULL ) && ( rDescriptor.ParentIndex == -1 ) )
768 pParent = DIALOG_NO_PARENT;
769 pNewWindow = new toolkit::ScrollableWrapper<Dialog>( pParent, nWinBits );
770 // #i70217# Don't always create a new component object. It's possible that VCL has called
771 // GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() )
772 // which creates a component object.
773 css::uno::Reference< css::awt::XWindowPeer > xWinPeer = pNewWindow->GetComponentInterface( sal_False );
774 if ( xWinPeer.is() )
775 *ppNewComp = dynamic_cast< VCLXDialog* >( xWinPeer.get() );
776 else
777 *ppNewComp = new VCLXDialog;
779 break;
780 case WINDOW_MOREBUTTON:
781 pNewWindow = new MoreButton( pParent, nWinBits );
782 *ppNewComp = new VCLXButton;
783 break;
784 case WINDOW_MULTILISTBOX:
785 pNewWindow = new MultiListBox( pParent, nWinBits );
786 *ppNewComp = new VCLXListBox;
787 break;
788 case WINDOW_NUMERICBOX:
789 pNewWindow = new NumericBox( pParent, nWinBits );
790 break;
791 case WINDOW_NUMERICFIELD:
792 pNewWindow = new NumericField( pParent, nWinBits );
793 static_cast<NumericField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
794 *ppNewComp = new VCLXNumericField;
795 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(NumericField*)pNewWindow );
796 break;
797 case WINDOW_OKBUTTON:
798 pNewWindow = new OKButton( pParent, nWinBits );
799 *ppNewComp = new VCLXButton;
800 break;
801 case WINDOW_PATTERNBOX:
802 pNewWindow = new PatternBox( pParent, nWinBits );
803 break;
804 case WINDOW_PATTERNFIELD:
805 pNewWindow = new PatternField( pParent, nWinBits );
806 *ppNewComp = new VCLXPatternField;
807 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(PatternField*)pNewWindow );
808 break;
809 case WINDOW_PUSHBUTTON:
810 pNewWindow = new PushButton( pParent, nWinBits );
811 *ppNewComp = new VCLXButton;
812 break;
813 case WINDOW_QUERYBOX:
814 pNewWindow = new QueryBox( pParent, nWinBits, String() );
815 *ppNewComp = new VCLXMessageBox;
816 break;
817 case WINDOW_RADIOBUTTON:
818 pNewWindow = new RadioButton( pParent, nWinBits );
819 *ppNewComp = new VCLXRadioButton;
821 // by default, disable RadioCheck
822 // Since the VCLXRadioButton really cares for it's RadioCheck settings, this is important:
823 // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState
824 // This leads to a strange behaviour if the control is newly created: when settings the initial
825 // state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck
826 // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls
827 // is not really valid: the controls are grouped after they have been created, but we're still in
828 // the creation process, so the RadioButton::Check relies on invalid grouping information.
829 // 07.08.2001 - #87254# - frank.schoenheit@sun.com
830 static_cast<RadioButton*>(pNewWindow)->EnableRadioCheck( sal_False );
831 break;
832 case WINDOW_SCROLLBAR:
833 pNewWindow = new ScrollBar( pParent, nWinBits );
834 *ppNewComp = new VCLXScrollBar;
835 break;
836 case WINDOW_SCROLLBARBOX:
837 pNewWindow = new ScrollBarBox( pParent, nWinBits );
838 break;
839 case WINDOW_SPINBUTTON:
840 pNewWindow = new SpinButton( pParent, nWinBits );
841 *ppNewComp = new ::toolkit::VCLXSpinButton;
842 break;
843 case WINDOW_SPINFIELD:
844 pNewWindow = new SpinField( pParent, nWinBits );
845 *ppNewComp = new VCLXNumericField;
846 break;
847 case WINDOW_SPLITTER:
848 pNewWindow = new Splitter( pParent, nWinBits );
849 break;
850 case WINDOW_SPLITWINDOW:
851 pNewWindow = new SplitWindow( pParent, nWinBits );
852 break;
853 case WINDOW_STATUSBAR:
854 pNewWindow = new StatusBar( pParent, nWinBits );
855 break;
856 case VCLWINDOW_SYSTEMCHILDWINDOW:
857 pNewWindow = new SystemChildWindow( pParent, nWinBits );
858 *ppNewComp = new VCLXSystemDependentWindow();
859 break;
860 case WINDOW_TABCONTROL:
861 pNewWindow = new TabControl( pParent, nWinBits );
862 *ppNewComp = new VCLXMultiPage;
863 break;
864 case WINDOW_TABDIALOG:
865 pNewWindow = new TabDialog( pParent, nWinBits );
866 break;
867 case WINDOW_TABPAGE:
869 pNewWindow = new TabPage( pParent, nWinBits );
870 *ppNewComp = new VCLXTabPage;
872 break;
873 case WINDOW_TIMEBOX:
874 pNewWindow = new TimeBox( pParent, nWinBits );
875 break;
876 case WINDOW_TIMEFIELD:
877 pNewWindow = new TimeField( pParent, nWinBits );
878 static_cast<TimeField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
879 *ppNewComp = new VCLXTimeField;
880 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(TimeField*)pNewWindow );
881 break;
882 case WINDOW_TOOLBOX:
883 pNewWindow = new ToolBox( pParent, nWinBits );
884 *ppNewComp = new VCLXToolBox;
885 break;
886 case WINDOW_TRISTATEBOX:
887 pNewWindow = new TriStateBox( pParent, nWinBits );
888 break;
889 case WINDOW_WARNINGBOX:
890 pNewWindow = new WarningBox( pParent, nWinBits, String() );
891 *ppNewComp = new VCLXMessageBox;
892 break;
893 case WINDOW_WORKWINDOW:
894 case WINDOW_WINDOW:
895 case VCLWINDOW_FRAMEWINDOW:
896 case WINDOW_DOCKINGWINDOW:
897 if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP )
899 if (nType == WINDOW_DOCKINGWINDOW )
900 pNewWindow = new DockingWindow( pParent, nWinBits );
901 else
903 if ((pParent == NULL) && rDescriptor.Parent.is())
905 // try to get a system dependent window handle
906 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, ::com::sun::star::uno::UNO_QUERY);
908 if (xSystemDepParent.is())
910 sal_Int8 processID[16];
912 rtl_getGlobalProcessId( (sal_uInt8*)processID );
914 ::com::sun::star::uno::Sequence<sal_Int8> processIdSeq(processID, 16);
916 ::com::sun::star::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPE);
918 // use sal_Int64 here to accomodate all int types
919 // uno::Any shift operator whill upcast if necessary
920 sal_Int64 nWindowHandle = 0;
921 sal_Bool bXEmbed = sal_False;
923 bool bUseParentData = true;
924 if( ! (anyHandle >>= nWindowHandle) )
926 css::uno::Sequence< css::beans::NamedValue > aProps;
927 if( anyHandle >>= aProps )
929 const int nProps = aProps.getLength();
930 const css::beans::NamedValue* pProps = aProps.getConstArray();
931 for( int i = 0; i < nProps; i++ )
933 if ( pProps[i].Name == "WINDOW" )
934 pProps[i].Value >>= nWindowHandle;
935 else if ( pProps[i].Name == "XEMBED" )
936 pProps[i].Value >>= bXEmbed;
939 else
940 bUseParentData = false;
943 if( bUseParentData )
945 SystemParentData aParentData;
946 aParentData.nSize = sizeof( aParentData );
947 #if defined QUARTZ
948 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
949 #elif defined IOS
950 aParentData.pView = reinterpret_cast<UIView*>(nWindowHandle);
951 #elif defined UNX
952 aParentData.aWindow = nWindowHandle;
953 aParentData.bXEmbedSupport = bXEmbed;
954 #elif defined WNT
955 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
956 #endif
957 pNewWindow = new WorkWindow( &aParentData );
962 if (!pNewWindow)
963 pNewWindow = new WorkWindow( pParent, nWinBits );
966 *ppNewComp = new VCLXTopWindow( pNewWindow->GetType() == WINDOW_WORKWINDOW );
968 else if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_CONTAINER )
970 if (nType == WINDOW_DOCKINGWINDOW )
971 pNewWindow = new DockingWindow( pParent, nWinBits );
972 else
973 pNewWindow = new Window( pParent, nWinBits );
974 *ppNewComp = new VCLXContainer;
976 else
978 if (nType == WINDOW_DOCKINGWINDOW )
979 pNewWindow = new DockingWindow( pParent, nWinBits );
980 else
981 pNewWindow = new Window( pParent, nWinBits );
982 *ppNewComp = new VCLXWindow;
984 break;
985 case WINDOW_CONTROL:
986 if ( aServiceName.EqualsAscii( "simpleanimation" ) )
988 pNewWindow = new Throbber( pParent, nWinBits, Throbber::IMAGES_NONE );
989 ((Throbber*)pNewWindow)->SetScaleMode( css::awt::ImageScaleMode::Anisotropic );
990 // (compatibility)
991 *ppNewComp = new ::toolkit::XSimpleAnimation;
993 else if ( aServiceName.EqualsAscii( "throbber" ) )
995 pNewWindow = new Throbber( pParent, nWinBits, Throbber::IMAGES_NONE );
996 ((Throbber*)pNewWindow)->SetScaleMode( css::awt::ImageScaleMode::Anisotropic );
997 // (compatibility)
998 *ppNewComp = new ::toolkit::XThrobber;
1000 else if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCaseAsciiL(
1001 RTL_CONSTASCII_STRINGPARAM("tabpagecontainer") ) )
1003 pNewWindow = new TabControl( pParent, nWinBits );
1004 *ppNewComp = new VCLXTabPageContainer;
1006 else if ( aServiceName.EqualsAscii( "animatedimages" ) )
1008 pNewWindow = new Throbber( pParent, nWinBits );
1009 *ppNewComp = new ::toolkit::AnimatedImagesPeer;
1011 break;
1012 default:
1013 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" );
1014 break;
1018 return pNewWindow;
1021 #ifndef DISABLE_DYNLOADING
1023 extern "C" { static void SAL_CALL thisModule() {} }
1025 #else
1027 extern "C" Window* SAL_CALL CreateWindow( VCLXWindow** ppNewComp, const ::com::sun::star::awt::WindowDescriptor* pDescriptor, Window* pParent, WinBits nWinBits );
1029 #endif
1031 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow(
1032 const css::awt::WindowDescriptor& rDescriptor,
1033 WinBits nForceWinBits )
1035 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1037 SolarMutexGuard aSolarGuard;
1039 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef;
1041 Window* pParent = NULL;
1042 if ( rDescriptor.Parent.is() )
1044 VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( rDescriptor.Parent );
1046 // #103939# Don't throw assertion, may be it's a system dependend window, used in ImplCreateWindow.
1047 // DBG_ASSERT( pParentComponent, "ParentComponent not valid" );
1049 if ( pParentComponent )
1050 pParent = pParentComponent->GetWindow();
1052 WinBits nWinBits = ImplGetWinBits( rDescriptor.WindowAttributes,
1053 ImplGetComponentType( rDescriptor.WindowServiceName ) );
1054 nWinBits |= nForceWinBits;
1056 VCLXWindow* pNewComp = NULL;
1058 Window* pNewWindow = NULL;
1059 // Try to create the window with SvTools
1060 // (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way,
1061 // and we need to stay compatible)
1062 // try to load the lib
1063 if ( !fnSvtCreateWindow
1064 #ifndef DISABLE_DYNLOADING
1065 && !hSvToolsLib
1066 #endif
1069 #ifndef DISABLE_DYNLOADING
1070 ::rtl::OUString aLibName = ::vcl::unohelper::CreateLibraryName(
1071 #ifdef LIBO_MERGELIBS
1072 "merged",
1073 #else
1074 "svt",
1075 #endif
1076 sal_True );
1077 hSvToolsLib = osl_loadModuleRelative(
1078 &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT );
1079 if ( hSvToolsLib )
1081 ::rtl::OUString aFunctionName( "CreateWindow" );
1082 fnSvtCreateWindow = (FN_SvtCreateWindow)osl_getFunctionSymbol( hSvToolsLib, aFunctionName.pData );
1084 #else
1085 fnSvtCreateWindow = CreateWindow;
1086 #endif
1088 // ask the SvTool creation function
1089 if ( fnSvtCreateWindow )
1090 pNewWindow = fnSvtCreateWindow( &pNewComp, &rDescriptor, pParent, nWinBits );
1092 // if SvTools could not provide a window, create it ourself
1093 if ( !pNewWindow )
1094 pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits );
1096 DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" );
1097 DBG_ASSERTWARNING( pNewComp, "createWindow: No special Interface!" );
1099 if ( pNewWindow )
1101 pNewWindow->SetCreatedWithToolkit( sal_True );
1102 //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead
1104 if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::MINSIZE )
1106 pNewWindow->SetSizePixel( Size() );
1108 else if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::FULLSIZE )
1110 if ( pParent )
1111 pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() );
1113 else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) )
1115 Rectangle aRect = VCLRectangle( rDescriptor.Bounds );
1116 pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
1119 if ( !pNewComp )
1121 // Default-Interface
1122 xRef = pNewWindow->GetComponentInterface( sal_True );
1124 else
1126 pNewComp->SetCreatedWithToolkit( sal_True );
1127 xRef = pNewComp;
1128 pNewWindow->SetComponentInterface( xRef );
1130 DBG_ASSERT( pNewWindow->GetComponentInterface( sal_False ) == xRef,
1131 "VCLXToolkit::createWindow: did #133706# resurge?" );
1133 if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::SHOW )
1134 pNewWindow->Show();
1137 return xRef;
1140 ::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)
1142 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1144 sal_uInt32 nComponents = rDescriptors.getLength();
1145 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > > aSeq( nComponents );
1146 for ( sal_uInt32 n = 0; n < nComponents; n++ )
1148 ::com::sun::star::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n];
1150 if ( aDescr.ParentIndex == (-1) )
1151 aDescr.Parent = NULL;
1152 else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < (short)n ) )
1153 aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex];
1154 aSeq.getArray()[n] = createWindow( aDescr );
1156 return aSeq;
1159 // ::com::sun::star::awt::XSystemChildFactory
1160 ::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)
1162 Window* pChildWindow = NULL;
1163 if ( nSystemType == SYSTEM_DEPENDENT_TYPE )
1165 // use sal_Int64 here to accomodate all int types
1166 // uno::Any shift operator whill upcast if necessary
1167 sal_Int64 nWindowHandle = 0;
1168 sal_Bool bXEmbed = sal_False;
1170 bool bUseParentData = true;
1171 if( ! (Parent >>= nWindowHandle) )
1173 css::uno::Sequence< css::beans::NamedValue > aProps;
1174 if( Parent >>= aProps )
1176 const int nProps = aProps.getLength();
1177 const css::beans::NamedValue* pProps = aProps.getConstArray();
1178 for( int i = 0; i < nProps; i++ )
1180 if ( pProps[i].Name == "WINDOW" )
1181 pProps[i].Value >>= nWindowHandle;
1182 else if ( pProps[i].Name == "XEMBED" )
1183 pProps[i].Value >>= bXEmbed;
1186 else
1187 bUseParentData = false;
1190 if( bUseParentData )
1192 SystemParentData aParentData;
1193 aParentData.nSize = sizeof( aParentData );
1194 #if defined QUARTZ
1195 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
1196 #elif defined IOS
1197 aParentData.pView = reinterpret_cast<UIView*>(nWindowHandle);
1198 #elif defined UNX
1199 aParentData.aWindow = nWindowHandle;
1200 aParentData.bXEmbedSupport = bXEmbed;
1201 #elif defined WNT
1202 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1203 #endif
1204 SolarMutexGuard aGuard;
1207 pChildWindow = new WorkWindow( &aParentData );
1209 catch ( const ::com::sun::star::uno::RuntimeException & rEx )
1211 // system child window could not be created
1212 OSL_TRACE(
1213 "VCLXToolkit::createSystemChild: caught %s\n",
1214 ::rtl::OUStringToOString(
1215 rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1216 pChildWindow = NULL;
1220 else if (nSystemType == com::sun::star::lang::SystemDependent::SYSTEM_JAVA)
1222 SolarMutexGuard aGuard;
1223 pChildWindow = new WorkWindow(0, Parent);
1226 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xPeer;
1227 if ( pChildWindow )
1229 VCLXTopWindow* pPeer = new VCLXTopWindow(true);
1230 SolarMutexGuard aGuard;
1231 pPeer->SetWindow( pChildWindow );
1232 xPeer = pPeer;
1235 return xPeer;
1238 // ::com::sun::star::awt::XMessageBoxFactory
1239 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox(
1240 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& aParent,
1241 const ::com::sun::star::awt::Rectangle& aPosSize,
1242 const ::rtl::OUString& aType,
1243 ::sal_Int32 aButtons,
1244 const ::rtl::OUString& aTitle,
1245 const ::rtl::OUString& aMessage ) throw (::com::sun::star::uno::RuntimeException)
1247 ::com::sun::star::awt::WindowDescriptor aDescriptor;
1249 sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE;
1251 // Map button definitions to window attributes
1252 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK )
1253 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK;
1254 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL )
1255 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL;
1256 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO )
1257 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO;
1258 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL )
1259 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL;
1260 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL )
1261 nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL;
1263 // Map default button definitions to window attributes
1264 if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK )
1265 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK;
1266 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL )
1267 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL;
1268 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES )
1269 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES;
1270 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO )
1271 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO;
1272 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY )
1273 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY;
1275 // No more bits for VclWindowPeerAttribute possible. Mapping must be
1276 // done explicitly using VCL methods
1277 WinBits nAddWinBits( 0 );
1278 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY )
1279 nAddWinBits |= WB_ABORT_RETRY_IGNORE;
1280 if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE )
1281 nAddWinBits |= WB_DEF_IGNORE;
1283 aDescriptor.Type = css::awt::WindowClass_MODALTOP;
1284 aDescriptor.WindowServiceName = aType;
1285 aDescriptor.ParentIndex = -1;
1286 aDescriptor.Parent = aParent;
1287 aDescriptor.Bounds = aPosSize;
1288 aDescriptor.WindowAttributes = nWindowAttributes;
1289 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > xMsgBox(
1290 ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY );
1291 css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY );
1292 if ( xMsgBox.is() && xWindow.is() )
1294 Window * pWindow = VCLUnoHelper::GetWindow( xWindow );
1295 if ( pWindow )
1297 SolarMutexGuard aGuard;
1298 xMsgBox->setCaptionText( aTitle );
1299 xMsgBox->setMessageText( aMessage );
1303 return xMsgBox;
1306 ::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)
1308 Window * pWindow = VCLUnoHelper::GetWindow( window );
1310 if( pWindow )
1311 return pWindow->GetDragGestureRecognizer();
1313 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer >();
1316 ::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)
1318 Window * pWindow = VCLUnoHelper::GetWindow( window );
1320 if( pWindow )
1321 return pWindow->GetDragSource();
1323 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource >();
1326 ::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)
1328 Window * pWindow = VCLUnoHelper::GetWindow( window );
1330 if( pWindow )
1331 return pWindow->GetDropTarget();
1333 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTarget >();
1336 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > SAL_CALL VCLXToolkit::getClipboard( const ::rtl::OUString& clipboardName ) throw(::com::sun::star::uno::RuntimeException)
1338 if( clipboardName.isEmpty() )
1340 if( !mxClipboard.is() )
1342 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
1343 if ( xFactory.is() )
1345 // remember clipboard here
1346 mxClipboard = ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > (
1347 xFactory->createInstance( ::rtl::OUString("com.sun.star.datatransfer.clipboard.SystemClipboard") ), ::com::sun::star::uno::UNO_QUERY );
1351 return mxClipboard;
1354 else if( clipboardName == "Selection" )
1356 return mxSelection;
1359 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >();
1362 // XServiceInfo
1363 ::rtl::OUString VCLXToolkit::getImplementationName() throw(::com::sun::star::uno::RuntimeException)
1365 return rtl::OUString("stardiv.Toolkit.VCLXToolkit");
1368 sal_Bool VCLXToolkit::supportsService( const ::rtl::OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException)
1370 ::osl::MutexGuard aGuard( GetMutex() );
1372 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
1373 const ::rtl::OUString* pArray = aSNL.getConstArray();
1374 const ::rtl::OUString* pArrayEnd = aSNL.getConstArray();
1375 for (; pArray != pArrayEnd; ++pArray )
1376 if( *pArray == rServiceName )
1377 break;
1379 return pArray != pArrayEnd;
1382 ::com::sun::star::uno::Sequence< ::rtl::OUString > VCLXToolkit::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException)
1384 ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( szServiceName2_Toolkit ) );
1385 return ::com::sun::star::uno::Sequence< ::rtl::OUString >( &aServiceName, 1);
1388 // css::awt::XExtendedToolkit:
1390 // virtual
1391 ::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount()
1392 throw (::css::uno::RuntimeException)
1394 return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount());
1395 // XXX numeric overflow
1398 // virtual
1399 ::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL
1400 VCLXToolkit::getTopWindow(::sal_Int32 nIndex)
1401 throw (::css::uno::RuntimeException)
1403 ::Window * p = ::Application::GetTopWindow(static_cast< long >(nIndex));
1404 // XXX numeric overflow
1405 return ::css::uno::Reference< ::css::awt::XTopWindow >(
1406 p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()),
1407 ::css::uno::UNO_QUERY);
1410 // virtual
1411 ::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL
1412 VCLXToolkit::getActiveTopWindow() throw (::css::uno::RuntimeException)
1414 ::Window * p = ::Application::GetActiveTopWindow();
1415 return ::css::uno::Reference< ::css::awt::XTopWindow >(
1416 p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()),
1417 ::css::uno::UNO_QUERY);
1420 // virtual
1421 void SAL_CALL VCLXToolkit::addTopWindowListener(
1422 ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener)
1423 throw (::css::uno::RuntimeException)
1425 OSL_ENSURE(rListener.is(), "Null rListener");
1426 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1427 if (rBHelper.bDisposed || rBHelper.bInDispose)
1429 aGuard.clear();
1430 rListener->disposing(
1431 ::css::lang::EventObject(
1432 static_cast< ::cppu::OWeakObject * >(this)));
1434 else if (m_aTopWindowListeners.addInterface(rListener) == 1
1435 && !m_bEventListener)
1437 m_bEventListener = true;
1438 ::Application::AddEventListener(m_aEventListenerLink);
1442 // virtual
1443 void SAL_CALL VCLXToolkit::removeTopWindowListener(
1444 ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener)
1445 throw (::css::uno::RuntimeException)
1447 ::osl::MutexGuard aGuard(rBHelper.rMutex);
1448 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1449 && m_aTopWindowListeners.removeInterface(rListener) == 0
1450 && m_aFocusListeners.getLength() == 0 && m_bEventListener)
1452 ::Application::RemoveEventListener(m_aEventListenerLink);
1453 m_bEventListener = false;
1457 // virtual
1458 void SAL_CALL VCLXToolkit::addKeyHandler(
1459 ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler)
1460 throw (::css::uno::RuntimeException)
1462 OSL_ENSURE(rHandler.is(), "Null rHandler");
1463 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1464 if (rBHelper.bDisposed || rBHelper.bInDispose)
1466 aGuard.clear();
1467 rHandler->disposing(
1468 ::css::lang::EventObject(
1469 static_cast< ::cppu::OWeakObject * >(this)));
1471 else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener)
1473 m_bKeyListener = true;
1474 ::Application::AddKeyListener(m_aKeyListenerLink);
1478 // virtual
1479 void SAL_CALL VCLXToolkit::removeKeyHandler(
1480 ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler)
1481 throw (::css::uno::RuntimeException)
1483 ::osl::MutexGuard aGuard(rBHelper.rMutex);
1484 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1485 && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener)
1487 ::Application::RemoveKeyListener(m_aKeyListenerLink);
1488 m_bKeyListener = false;
1492 // virtual
1493 void SAL_CALL VCLXToolkit::addFocusListener(
1494 ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener)
1495 throw (::css::uno::RuntimeException)
1497 OSL_ENSURE(rListener.is(), "Null rListener");
1498 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1499 if (rBHelper.bDisposed || rBHelper.bInDispose)
1501 aGuard.clear();
1502 rListener->disposing(
1503 ::css::lang::EventObject(
1504 static_cast< ::cppu::OWeakObject * >(this)));
1506 else if (m_aFocusListeners.addInterface(rListener) == 1
1507 && !m_bEventListener)
1509 m_bEventListener = true;
1510 ::Application::AddEventListener(m_aEventListenerLink);
1514 // virtual
1515 void SAL_CALL VCLXToolkit::removeFocusListener(
1516 ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener)
1517 throw (::css::uno::RuntimeException)
1519 ::osl::MutexGuard aGuard(rBHelper.rMutex);
1520 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1521 && m_aFocusListeners.removeInterface(rListener) == 0
1522 && m_aTopWindowListeners.getLength() == 0 && m_bEventListener)
1524 ::Application::RemoveEventListener(m_aEventListenerLink);
1525 m_bEventListener = false;
1529 // virtual
1530 void SAL_CALL VCLXToolkit::fireFocusGained(
1531 ::com::sun::star::uno::Reference<
1532 ::com::sun::star::uno::XInterface > const &)
1533 throw (::com::sun::star::uno::RuntimeException)
1537 // virtual
1538 void SAL_CALL VCLXToolkit::fireFocusLost(
1539 ::com::sun::star::uno::Reference<
1540 ::com::sun::star::uno::XInterface > const &)
1541 throw (::com::sun::star::uno::RuntimeException)
1546 IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent const *, pEvent)
1548 switch (pEvent->GetId())
1550 case VCLEVENT_WINDOW_SHOW:
1551 callTopWindowListeners(
1552 pEvent, &::css::awt::XTopWindowListener::windowOpened);
1553 break;
1554 case VCLEVENT_WINDOW_HIDE:
1555 callTopWindowListeners(
1556 pEvent, &::css::awt::XTopWindowListener::windowClosed);
1557 break;
1558 case VCLEVENT_WINDOW_ACTIVATE:
1559 callTopWindowListeners(
1560 pEvent, &::css::awt::XTopWindowListener::windowActivated);
1561 break;
1562 case VCLEVENT_WINDOW_DEACTIVATE:
1563 callTopWindowListeners(
1564 pEvent, &::css::awt::XTopWindowListener::windowDeactivated);
1565 break;
1566 case VCLEVENT_WINDOW_CLOSE:
1567 callTopWindowListeners(
1568 pEvent, &::css::awt::XTopWindowListener::windowClosing);
1569 break;
1570 case VCLEVENT_WINDOW_GETFOCUS:
1571 callFocusListeners(pEvent, true);
1572 break;
1573 case VCLEVENT_WINDOW_LOSEFOCUS:
1574 callFocusListeners(pEvent, false);
1575 break;
1576 case VCLEVENT_WINDOW_MINIMIZE:
1577 callTopWindowListeners(
1578 pEvent, &::css::awt::XTopWindowListener::windowMinimized);
1579 break;
1580 case VCLEVENT_WINDOW_NORMALIZE:
1581 callTopWindowListeners(
1582 pEvent, &::css::awt::XTopWindowListener::windowNormalized);
1583 break;
1585 return 0;
1588 IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclSimpleEvent const *, pEvent)
1590 switch (pEvent->GetId())
1592 case VCLEVENT_WINDOW_KEYINPUT:
1593 return callKeyHandlers(pEvent, true);
1594 case VCLEVENT_WINDOW_KEYUP:
1595 return callKeyHandlers(pEvent, false);
1597 return 0;
1600 void VCLXToolkit::callTopWindowListeners(
1601 ::VclSimpleEvent const * pEvent,
1602 void (SAL_CALL ::css::awt::XTopWindowListener::* pFn)(
1603 ::css::lang::EventObject const &))
1605 ::Window * pWindow
1606 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1607 if (pWindow->IsTopWindow())
1609 ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
1610 aListeners(m_aTopWindowListeners.getElements());
1611 if (aListeners.hasElements())
1613 ::css::lang::EventObject aAwtEvent(
1614 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()));
1615 for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i)
1617 ::css::uno::Reference< ::css::awt::XTopWindowListener >
1618 xListener(aListeners[i], ::css::uno::UNO_QUERY);
1621 (xListener.get()->*pFn)(aAwtEvent);
1623 catch (const ::css::uno::RuntimeException & rEx)
1625 OSL_TRACE(
1626 "VCLXToolkit::callTopWindowListeners: caught %s\n",
1627 ::rtl::OUStringToOString(
1628 rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1635 long VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent,
1636 bool bPressed)
1638 ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
1639 aHandlers(m_aKeyHandlers.getElements());
1641 if (aHandlers.hasElements())
1643 ::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1645 // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event
1646 ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >(
1647 static_cast< ::VclWindowEvent const * >(pEvent)->GetData());
1648 ::css::awt::KeyEvent aAwtEvent(
1649 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()),
1650 (pKeyEvent->GetKeyCode().IsShift()
1651 ? ::css::awt::KeyModifier::SHIFT : 0)
1652 | (pKeyEvent->GetKeyCode().IsMod1()
1653 ? ::css::awt::KeyModifier::MOD1 : 0)
1654 | (pKeyEvent->GetKeyCode().IsMod2()
1655 ? ::css::awt::KeyModifier::MOD2 : 0)
1656 | (pKeyEvent->GetKeyCode().IsMod3()
1657 ? ::css::awt::KeyModifier::MOD3 : 0),
1658 pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(),
1659 sal::static_int_cast< sal_Int16 >(
1660 pKeyEvent->GetKeyCode().GetFunction()));
1661 for (::sal_Int32 i = 0; i < aHandlers.getLength(); ++i)
1663 ::css::uno::Reference< ::css::awt::XKeyHandler > xHandler(
1664 aHandlers[i], ::css::uno::UNO_QUERY);
1667 if ((bPressed ? xHandler->keyPressed(aAwtEvent)
1668 : xHandler->keyReleased(aAwtEvent)))
1669 return 1;
1671 catch (const ::css::uno::RuntimeException & rEx)
1673 OSL_TRACE(
1674 "VCLXToolkit::callKeyHandlers: caught %s\n",
1675 ::rtl::OUStringToOString(
1676 rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1680 return 0;
1683 void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent,
1684 bool bGained)
1686 ::Window * pWindow
1687 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1688 if (pWindow->IsTopWindow())
1690 ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
1691 aListeners(m_aFocusListeners.getElements());
1692 if (aListeners.hasElements())
1694 // Ignore the interior of compound controls when determining the
1695 // window that gets the focus next (see implementation in
1696 // vclxwindow.cxx for mapping between VCL and UNO AWT event):
1697 ::css::uno::Reference< css::uno::XInterface > xNext;
1698 ::Window * pFocus = ::Application::GetFocusWindow();
1699 for (::Window * p = pFocus; p != 0; p = p->GetParent())
1700 if (!p->IsCompoundControl())
1702 pFocus = p;
1703 break;
1705 if (pFocus != 0)
1706 xNext = pFocus->GetComponentInterface(true);
1707 ::css::awt::FocusEvent aAwtEvent(
1708 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()),
1709 pWindow->GetGetFocusFlags(), xNext, false);
1710 for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i)
1712 ::css::uno::Reference< ::css::awt::XFocusListener > xListener(
1713 aListeners[i], ::css::uno::UNO_QUERY);
1716 bGained ? xListener->focusGained(aAwtEvent)
1717 : xListener->focusLost(aAwtEvent);
1719 catch (const ::css::uno::RuntimeException & rEx)
1721 OSL_TRACE(
1722 "VCLXToolkit::callFocusListeners: caught %s\n",
1723 ::rtl::OUStringToOString(
1724 rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1731 // css::awt::XReschedule:
1733 void SAL_CALL VCLXToolkit::reschedule()
1734 throw (::com::sun::star::uno::RuntimeException)
1736 Application::Reschedule(true);
1739 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */