xref: /trunk/main/toolkit/source/awt/vclxtoolkit.cxx (revision a8f4084d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_toolkit.hxx"
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 
28 #ifndef _SVWIN_HXX
29 #include <tools/svwin.h>
30 #endif
31 #include <stdio.h>
32 #include <com/sun/star/awt/ImageScaleMode.hpp>
33 #include <com/sun/star/awt/WindowAttribute.hpp>
34 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
35 #include <com/sun/star/awt/WindowClass.hpp>
36 #include <com/sun/star/awt/MessageBoxButtons.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/lang/SystemDependent.hpp>
39 #include <com/sun/star/awt/FocusEvent.hpp>
40 #include <com/sun/star/awt/KeyEvent.hpp>
41 #include <com/sun/star/awt/KeyModifier.hpp>
42 #include <com/sun/star/lang/EventObject.hpp>
43 #include <com/sun/star/uno/Reference.hxx>
44 #include <com/sun/star/uno/Sequence.hxx>
45 #include <com/sun/star/uno/XInterface.hpp>
46 #include <com/sun/star/beans/NamedValue.hpp>
47 #include <cppuhelper/typeprovider.hxx>
48 #include <osl/conditn.hxx>
49 #include <rtl/memory.h>
50 #include <rtl/uuid.h>
51 #include <rtl/process.h>
52 
53 #ifdef WNT
54 #include <tools/prewin.h>
55 #include <windows.h>
56 #include <tools/postwin.h>
57 #elif defined ( OS2 )
58 #include <svpm.h>
59 #elif (defined QUARTZ)
60 #include "premac.h"
61 #include <Cocoa/Cocoa.h>
62 #include "postmac.h"
63 #endif
64 #include <vcl/sysdata.hxx>
65 
66 #include <toolkit/awt/vclxwindows.hxx>
67 #include <toolkit/awt/vclxsystemdependentwindow.hxx>
68 #include <toolkit/awt/vclxregion.hxx>
69 #include <toolkit/awt/vclxtoolkit.hxx>
70 #include <toolkit/awt/vclxtabpagecontainer.hxx>
71 #include <toolkit/awt/vclxtabpagemodel.hxx>
72 
73 #include <toolkit/awt/animatedimagespeer.hxx>
74 #include <toolkit/awt/vclxtopwindow.hxx>
75 #include <toolkit/awt/vclxwindow.hxx>
76 #include <toolkit/helper/vclunohelper.hxx>
77 #include <toolkit/helper/unowrapper.hxx>
78 #include <toolkit/helper/servicenames.hxx>
79 
80 
81 #include <toolkit/helper/macros.hxx>
82 #include <toolkit/helper/convert.hxx>
83 #include <vcl/unohelp.hxx>
84 #include <vcl/btndlg.hxx>
85 #ifndef _SV_BUTTON_HXX
86 #include <vcl/button.hxx>
87 #endif
88 #include <vcl/combobox.hxx>
89 #include <vcl/ctrl.hxx>
90 #include <vcl/dialog.hxx>
91 #include <vcl/dockingarea.hxx>
92 #include <vcl/dockwin.hxx>
93 #include <vcl/edit.hxx>
94 #include <vcl/field.hxx>
95 #include <vcl/fixed.hxx>
96 #include <vcl/floatwin.hxx>
97 #include <vcl/group.hxx>
98 #include <vcl/imgctrl.hxx>
99 #include <vcl/longcurr.hxx>
100 #include <vcl/lstbox.hxx>
101 #include <vcl/menubtn.hxx>
102 #include <vcl/morebtn.hxx>
103 #include <vcl/msgbox.hxx>
104 #include <vcl/scrbar.hxx>
105 #include <vcl/spin.hxx>
106 #include <vcl/split.hxx>
107 #include <vcl/splitwin.hxx>
108 #include <vcl/status.hxx>
109 #include <vcl/svapp.hxx>
110 #include <vcl/syschild.hxx>
111 #include <vcl/tabctrl.hxx>
112 #include <vcl/tabdlg.hxx>
113 #include <vcl/tabpage.hxx>
114 #include <vcl/toolbox.hxx>
115 #include <vcl/virdev.hxx>
116 #include <vcl/window.hxx>
117 #include <vcl/wrkwin.hxx>
118 #include <vcl/throbber.hxx>
119 #include "toolkit/awt/vclxspinbutton.hxx"
120 
121 #include <tools/debug.hxx>
122 #include <comphelper/processfactory.hxx>
123 
124 namespace css = ::com::sun::star;
125 
126 #define VCLWINDOW_FRAMEWINDOW				0x1000
127 #define VCLWINDOW_SYSTEMCHILDWINDOW			0x1001
128 
129 #if (defined WNT)
130 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32
131 #elif (defined OS2)
132 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_OS2
133 #elif (defined QUARTZ)
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
138 
139 TOOLKIT_DLLPUBLIC WinBits ImplGetWinBits( sal_uInt32 nComponentAttribs, sal_uInt16 nCompType )
140 {
141 	WinBits nWinBits = 0;
142 
143 	sal_Bool bMessBox = sal_False;
144 	if ( ( nCompType == WINDOW_INFOBOX ) ||
145 		 ( nCompType == WINDOW_MESSBOX ) ||
146 		 ( nCompType == WINDOW_QUERYBOX ) ||
147 		 ( nCompType == WINDOW_WARNINGBOX ) ||
148 		 ( nCompType == WINDOW_ERRORBOX ) )
149 	{
150 		bMessBox = sal_True;
151 	}
152 
153     bool bDecoratedWindow = false;
154     if  (   bMessBox
155         ||  ( nCompType == WINDOW_DIALOG )
156         ||  ( nCompType == WINDOW_MODELESSDIALOG )
157         ||  ( nCompType == WINDOW_MODALDIALOG )
158         ||  ( nCompType == WINDOW_SYSTEMDIALOG )
159         ||  ( nCompType == WINDOW_PATHDIALOG )
160         ||  ( nCompType == WINDOW_FILEDIALOG )
161         ||  ( nCompType == WINDOW_PRINTERSETUPDIALOG )
162         ||  ( nCompType == WINDOW_PRINTDIALOG )
163         ||  ( nCompType == WINDOW_COLORDIALOG )
164         ||  ( nCompType == WINDOW_FONTDIALOG )
165         ||  ( nCompType == WINDOW_DOCKINGWINDOW )
166         ||  ( nCompType == WINDOW_TABDIALOG )
167         ||  ( nCompType == WINDOW_BUTTONDIALOG )
168         ||  ( nCompType == WINDOW_SYSTEMCHILDWINDOW )
169         )
170     {
171         bDecoratedWindow = true;
172     }
173 
174     if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::BORDER )
175 		nWinBits |= WB_BORDER;
176 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::NOBORDER )
177 		nWinBits |= WB_NOBORDER;
178 	if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::SIZEABLE )
179 		nWinBits |= WB_SIZEABLE;
180 	if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::MOVEABLE )
181 		nWinBits |= WB_MOVEABLE;
182 	if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::CLOSEABLE )
183 		nWinBits |= WB_CLOSEABLE;
184 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::HSCROLL )
185 		nWinBits |= WB_HSCROLL;
186 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL )
187 		nWinBits |= WB_VSCROLL;
188 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::LEFT )
189 		nWinBits |= WB_LEFT;
190 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::CENTER )
191 		nWinBits |= WB_CENTER;
192 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::RIGHT )
193 		nWinBits |= WB_RIGHT;
194 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::SPIN )
195 		nWinBits |= WB_SPIN;
196 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::SORT )
197 		nWinBits |= WB_SORT;
198 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DROPDOWN )
199 		nWinBits |= WB_DROPDOWN;
200 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEFBUTTON )
201 		nWinBits |= WB_DEFBUTTON;
202 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::READONLY )
203 		nWinBits |= WB_READONLY;
204 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::CLIPCHILDREN )
205 		nWinBits |= WB_CLIPCHILDREN;
206 	if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::GROUP )
207 		nWinBits |= WB_GROUP;
208     if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::NOLABEL ) //added for issue79712
209 		nWinBits |= WB_NOLABEL;
210 
211 	// These bits are not uniqe
212 	if ( bMessBox )
213 	{
214 		if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::OK )
215 			nWinBits |= WB_OK;
216 		if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::OK_CANCEL )
217 			nWinBits |= WB_OK_CANCEL;
218 		if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO )
219 			nWinBits |= WB_YES_NO;
220 		if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO_CANCEL )
221 			nWinBits |= WB_YES_NO_CANCEL;
222 		if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::RETRY_CANCEL )
223 			nWinBits |= WB_RETRY_CANCEL;
224 		if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_OK )
225 			nWinBits |= WB_DEF_OK;
226 		if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_CANCEL )
227 			nWinBits |= WB_DEF_CANCEL;
228 		if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_RETRY )
229 			nWinBits |= WB_DEF_RETRY;
230 		if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_YES )
231 			nWinBits |= WB_DEF_YES;
232 		if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_NO )
233 			nWinBits |= WB_DEF_NO;
234 	}
235     if ( nCompType == WINDOW_MULTILINEEDIT )
236     {
237         if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::AUTOHSCROLL )
238             nWinBits |= WB_AUTOHSCROLL;
239         if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::AUTOVSCROLL )
240             nWinBits |= WB_AUTOVSCROLL;
241     }
242 
243 
244     if ( bDecoratedWindow )
245     {
246         if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::NODECORATION )
247         {
248             // No decoration removes several window attributes and must
249             // set WB_NOBORDER!
250             nWinBits &= ~WB_BORDER;
251 	        nWinBits &= ~WB_SIZEABLE;
252 	        nWinBits &= ~WB_MOVEABLE;
253 	        nWinBits &= ~WB_CLOSEABLE;
254             nWinBits |= WB_NOBORDER;
255         }
256     }
257 
258 	return nWinBits;
259 }
260 
261 struct ComponentInfo
262 {
263 	const char*		pName;
264 	WindowType		nWinType;
265 };
266 
267 static ComponentInfo __FAR_DATA aComponentInfos [] =
268 {
269 	{ "buttondialog", 		WINDOW_BUTTONDIALOG },
270 	{ "cancelbutton",		WINDOW_CANCELBUTTON },
271 	{ "checkbox",			WINDOW_CHECKBOX },
272 	{ "combobox",			WINDOW_COMBOBOX },
273 	{ "control",			WINDOW_CONTROL },
274 	{ "currencybox",		WINDOW_CURRENCYBOX },
275 	{ "currencyfield",		WINDOW_CURRENCYFIELD },
276 	{ "datebox",			WINDOW_DATEBOX },
277 	{ "datefield",			WINDOW_DATEFIELD },
278 	{ "dialog",				WINDOW_DIALOG },
279 	{ "dockingarea",		WINDOW_DOCKINGAREA },
280 	{ "dockingwindow",		WINDOW_DOCKINGWINDOW },
281 	{ "edit",				WINDOW_EDIT },
282 	{ "errorbox",			WINDOW_ERRORBOX },
283 	{ "fixedbitmap",		WINDOW_FIXEDBITMAP },
284 	{ "fixedimage",			WINDOW_FIXEDIMAGE },
285 	{ "fixedline",			WINDOW_FIXEDLINE },
286 	{ "fixedtext",			WINDOW_FIXEDTEXT },
287 	{ "floatingwindow",		WINDOW_FLOATINGWINDOW },
288 	{ "framewindow",		VCLWINDOW_FRAMEWINDOW },
289 	{ "groupbox",			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     { "animatedimages",     WINDOW_CONTROL },
317 	{ "spinbutton",			WINDOW_SPINBUTTON },
318 	{ "spinfield",			WINDOW_SPINFIELD },
319 	{ "splitter",			WINDOW_SPLITTER },
320 	{ "splitwindow",		WINDOW_SPLITWINDOW },
321 	{ "statusbar",			WINDOW_STATUSBAR },
322 	{ "systemchildwindow",	VCLWINDOW_SYSTEMCHILDWINDOW },
323 	{ "tabcontrol",			WINDOW_TABCONTROL },
324 	{ "tabdialog",			WINDOW_TABDIALOG },
325 	{ "tabpage",			WINDOW_TABPAGE },
326 	{ "timebox",			WINDOW_TIMEBOX },
327 	{ "timefield",			WINDOW_TIMEFIELD },
328 	{ "toolbox",			WINDOW_TOOLBOX },
329 	{ "tristatebox",		WINDOW_TRISTATEBOX },
330 	{ "warningbox",			WINDOW_WARNINGBOX },
331 	{ "window",				WINDOW_WINDOW },
332 	{ "workwindow",			WINDOW_WORKWINDOW },
333 	{ "tabpagecontainer",	WINDOW_CONTROL },
334 	{ "tabpagemodel",		WINDOW_TABPAGE }
335 };
336 
337 extern "C"
338 {
339 static int
340 #if defined( WNT )
341  __cdecl
342 #endif
343 #if defined( ICC ) && defined( OS2 )
344 _Optlink
345 #endif
346  	ComponentInfoCompare( const void* pFirst, const void* pSecond)
347 {
348 	return( strcmp( ((ComponentInfo*)pFirst)->pName,
349 		    		((ComponentInfo*)pSecond)->pName ) );
350 }
351 }
352 
353 sal_uInt16 ImplGetComponentType( const String& rServiceName )
354 {
355 	static sal_Bool bSorted = sal_False;
356 	if( !bSorted )
357 	{
358 		qsort( 	(void*) aComponentInfos,
359 				sizeof( aComponentInfos ) / sizeof( ComponentInfo ),
360 				sizeof( ComponentInfo ),
361 				ComponentInfoCompare );
362 		bSorted = sal_True;
363 	}
364 
365 
366 	ComponentInfo aSearch;
367 	ByteString aServiceName( rServiceName, gsl_getSystemTextEncoding() );
368 	aServiceName.ToLowerAscii();
369 	if ( aServiceName.Len() )
370 		aSearch.pName = aServiceName.GetBuffer();
371 	else
372 		aSearch.pName = "window";
373 
374 	ComponentInfo* pInf = (ComponentInfo*) bsearch( &aSearch,
375 						(void*) aComponentInfos,
376 						sizeof( aComponentInfos ) / sizeof( ComponentInfo ),
377 						sizeof( ComponentInfo ),
378 						ComponentInfoCompare );
379 
380 	return pInf ? pInf->nWinType : 0;
381 }
382 
383 
384 namespace
385 {
386     struct MessageBoxTypeInfo
387     {
388         css::awt::MessageBoxType eType;
389         const sal_Char          *pName;
390         sal_Int32                nLen;
391     };
392 
393     static MessageBoxTypeInfo aMessageBoxTypeInfo[] =
394     {
395         { css::awt::MessageBoxType_MESSAGEBOX,      RTL_CONSTASCII_STRINGPARAM("messbox") },
396         { css::awt::MessageBoxType_INFOBOX,         RTL_CONSTASCII_STRINGPARAM("infobox") },
397         { css::awt::MessageBoxType_WARNINGBOX,      RTL_CONSTASCII_STRINGPARAM("warningbox") },
398         { css::awt::MessageBoxType_ERRORBOX,        RTL_CONSTASCII_STRINGPARAM("errorbox") },
399         { css::awt::MessageBoxType_QUERYBOX,        RTL_CONSTASCII_STRINGPARAM("querybox") },
400         { css::awt::MessageBoxType_MAKE_FIXED_SIZE, 0, 0 }
401     };
402 
403     static bool lcl_convertMessageBoxType(
404         rtl::OUString &sType,
405         css::awt::MessageBoxType eType )
406     {
407         const MessageBoxTypeInfo *pMap = aMessageBoxTypeInfo;
408         css::awt::MessageBoxType eVal = css::awt::MessageBoxType_MAKE_FIXED_SIZE;
409 
410         while ( pMap->pName )
411         {
412             if ( pMap->eType == eType )
413             {
414                 eVal = eType;
415                 sType = rtl::OUString( pMap->pName, pMap->nLen, RTL_TEXTENCODING_ASCII_US );
416                 break;
417             }
418             pMap++;
419         }
420 
421         return ( eVal != css::awt::MessageBoxType_MAKE_FIXED_SIZE );
422     }
423 }
424 
425 //	----------------------------------------------------
426 //	class VCLXToolkit
427 //	----------------------------------------------------
428 
429 static sal_Int32							nVCLToolkitInstanceCount = 0;
430 static sal_Bool									bInitedByVCLToolkit = sal_False;
431 //static cppu::OInterfaceContainerHelper *	pToolkits = 0;
432 
433 static osl::Mutex & getInitMutex()
434 {
435 	static osl::Mutex * pM;
436 	if( !pM )
437 	{
438 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
439 		if( !pM )
440 		{
441 			static osl::Mutex aMutex;
442 			pM = &aMutex;
443 		}
444 	}
445 	return *pM;
446 }
447 
448 static osl::Condition & getInitCondition()
449 {
450 	static osl::Condition * pC = 0;
451 	if( !pC )
452 	{
453 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
454 		if( !pC )
455 		{
456 			static osl::Condition aCondition;
457 			pC = &aCondition;
458 		}
459 	}
460 	return *pC;
461 }
462 
463 struct ToolkitThreadData
464 {
465 	VCLXToolkit * pTk;
466 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr;
467 
468 	ToolkitThreadData( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr, VCLXToolkit * pTk_ )
469 		: pTk( pTk_ )
470 		, xSMgr( rSMgr )
471 	{
472 	}
473 };
474 
475 extern "C"
476 {
477 static void SAL_CALL ToolkitWorkerFunction( void* pArgs )
478 {
479 	ToolkitThreadData * pTTD = (ToolkitThreadData *)pArgs;
480 	bInitedByVCLToolkit = InitVCL( pTTD->xSMgr );
481 	if( bInitedByVCLToolkit )
482 	{
483 		UnoWrapper* pUnoWrapper = new UnoWrapper( pTTD->pTk );
484 		Application::SetUnoWrapper( pUnoWrapper );
485 	}
486 	getInitCondition().set();
487 	if( bInitedByVCLToolkit )
488 	{
489 		{
490 		osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() );
491 		Application::Execute();
492 		}
493 		try
494 		{
495 			pTTD->pTk->dispose();
496 		}
497 		catch( com::sun::star::uno::Exception & )
498 		{
499 		}
500 		/*
501 		if( pToolkits )
502 		{
503 			cppu::OInterfaceIteratorHelper aIt( *pToolkits );
504 			::com::sun::star::uno::XInterface *	pI;
505 			while( pI = aIt.next() )
506 				((::com::sun::star::lang::XComponent *)pI)->dispose();
507 
508 			// delete toolkit container
509 			osl::Guard< osl::Mutex > aGuard( getInitMutex() );
510 			delete pToolkits;
511 			pToolkits = 0;
512 		}
513 		*/
514 		DeInitVCL();
515 	}
516     else
517     {
518         JoinMainLoopThread();
519     }
520 	delete pTTD;
521 }
522 }
523 
524 // constructor, which might initialize VCL
525 VCLXToolkit::VCLXToolkit( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ):
526     cppu::WeakComponentImplHelper7<
527     ::com::sun::star::awt::XToolkit,
528     ::com::sun::star::lang::XServiceInfo,
529     ::com::sun::star::awt::XSystemChildFactory,
530     ::com::sun::star::awt::XMessageBoxFactory,
531     ::com::sun::star::awt::XDataTransferProviderAccess,
532     ::com::sun::star::awt::XExtendedToolkit,
533     ::com::sun::star::awt::XReschedule>( GetMutex() ),
534     m_aTopWindowListeners(rBHelper.rMutex),
535     m_aKeyHandlers(rBHelper.rMutex),
536     m_aFocusListeners(rBHelper.rMutex),
537     m_aEventListenerLink(LINK(this, VCLXToolkit, eventListenerHandler)),
538     m_aKeyListenerLink(LINK(this, VCLXToolkit, keyListenerHandler)),
539     m_bEventListener(false),
540     m_bKeyListener(false)
541 {
542 	hSvToolsLib = NULL;
543 	fnSvtCreateWindow = NULL;
544 
545 	osl::Guard< osl::Mutex > aGuard( getInitMutex() );
546     nVCLToolkitInstanceCount++;
547     if( ( nVCLToolkitInstanceCount == 1 ) && ( !Application::IsInMain() ) )
548 	{
549 		// setup execute thread
550 		CreateMainLoopThread( ToolkitWorkerFunction, new ToolkitThreadData( rSMgr, this ) );
551 		getInitCondition().wait();
552 		/*
553 		if( bInitedByVCLToolkit )
554 		{
555 			// insert in disposing list
556 			if( !pToolkits )
557 				pToolkits = new cppu::OInterfaceContainerHelper( getInitMutex() );
558 			pToolkits->addInterface( (::com::sun::star::lang::XComponent *)this );
559 		}
560 		*/
561 	}
562 }
563 
564 VCLXToolkit::~VCLXToolkit()
565 {
566 }
567 
568 
569 void SAL_CALL VCLXToolkit::disposing()
570 {
571 	if ( hSvToolsLib )
572 	{
573 		osl_unloadModule( hSvToolsLib );
574 		hSvToolsLib = NULL;
575 		fnSvtCreateWindow = NULL;
576 	}
577 
578     {
579         osl::Guard< osl::Mutex > aGuard( getInitMutex() );
580         if( --nVCLToolkitInstanceCount == 0 )
581         {
582             if( bInitedByVCLToolkit )
583             {
584                 Application::Quit();
585                 JoinMainLoopThread();
586                 bInitedByVCLToolkit = sal_False;
587             }
588         }
589     }
590 
591     if (m_bEventListener)
592     {
593         ::Application::RemoveEventListener(m_aEventListenerLink);
594         m_bEventListener = false;
595     }
596     if (m_bKeyListener)
597     {
598         ::Application::RemoveKeyListener(m_aKeyListenerLink);
599         m_bKeyListener = false;
600     }
601     ::css::lang::EventObject aEvent(
602         static_cast< ::cppu::OWeakObject * >(this));
603     m_aTopWindowListeners.disposeAndClear(aEvent);
604     m_aKeyHandlers.disposeAndClear(aEvent);
605     m_aFocusListeners.disposeAndClear(aEvent);
606 
607 /*
608 	osl::Guard< osl::Mutex > aGuard( getInitMutex() );
609 	// insert in disposing list
610 	if( pToolkits )
611 	{
612 		// remove from the disposing list
613 		pToolkits->removeInterface( (::com::sun::star::lang::XComponent *)this );
614 	}
615 */
616 }
617 
618 
619 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::getDesktopWindow(  ) throw(::com::sun::star::uno::RuntimeException)
620 {
621 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef;
622 	// 07/00: AppWindow doesn't exist anymore...
623 	return xRef;
624 }
625 
626 ::com::sun::star::awt::Rectangle VCLXToolkit::getWorkArea(  ) throw(::com::sun::star::uno::RuntimeException)
627 {
628 	::com::sun::star::awt::Rectangle aRect;
629 	// 07/00: AppWindow doesn't exist anymore...
630 	return aRect;
631 }
632 
633 ::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)
634 {
635 #ifdef WNT
636 	CEnableAccessInterface e;
637 #endif
638     return ImplCreateWindow( rDescriptor, WinBits(0) );
639 }
640 
641 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) throw(::com::sun::star::uno::RuntimeException)
642 {
643 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
644 
645 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > xRef;
646 	VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
647 
648 	osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() );
649 
650 	VirtualDevice* pV = new VirtualDevice;
651 	pV->SetOutputSizePixel( Size( Width, Height ) );
652 	pVDev->SetVirtualDevice( pV );
653 
654 	xRef = pVDev;
655 	return xRef;
656 }
657 
658 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion > VCLXToolkit::createRegion(  ) throw(::com::sun::star::uno::RuntimeException)
659 {
660 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
661 
662 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >  xRef = new VCLXRegion;
663 	return xRef;
664 }
665 
666 Window*	VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp,
667 	const ::com::sun::star::awt::WindowDescriptor& rDescriptor,
668     Window* pParent, WinBits nWinBits )
669 {
670 	String aServiceName( rDescriptor.WindowServiceName );
671 	aServiceName.ToLowerAscii();
672 
673 	Window* pNewWindow = NULL;
674 	sal_uInt16 nType = ImplGetComponentType( aServiceName );
675 
676 	if ( !pParent )
677 	{
678 		// Wenn die Component einen Parent braucht, dann NULL zurueckgeben,
679 		// spaeter mal ::com::sun::star::uno::Exception...
680 		sal_Bool bException = sal_True;
681 		if  (   ( nType == WINDOW_DIALOG )
682             ||  ( nType == WINDOW_MODALDIALOG )
683             ||  ( nType == WINDOW_MODELESSDIALOG )
684             ||  ( nType == WINDOW_MESSBOX )
685             ||  ( nType == WINDOW_INFOBOX )
686             ||  ( nType == WINDOW_WARNINGBOX )
687             ||  ( nType == WINDOW_ERRORBOX )
688             ||  ( nType == WINDOW_QUERYBOX )
689             )
690 			bException = sal_False;
691 		else if ( ( nType == WINDOW_WINDOW ) ||
692 				  ( nType == WINDOW_WORKWINDOW ) ||
693 				  ( nType == VCLWINDOW_FRAMEWINDOW ) )
694 		{
695 			if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP )
696 				bException = sal_False;
697 		}
698 
699 		if ( bException )
700 		{
701 			*ppNewComp = NULL;
702 			return NULL;
703 		}
704 	}
705 
706 	if ( nType )
707 	{
708 		vos::OGuard aVclGuard( Application::GetSolarMutex()  );
709 		switch ( (WindowType)nType )
710 		{
711 			case WINDOW_CANCELBUTTON:
712 				pNewWindow = new CancelButton( pParent, nWinBits );
713 				*ppNewComp = new VCLXButton;
714 			break;
715 			case WINDOW_CHECKBOX:
716 		 		pNewWindow = new CheckBox( pParent, nWinBits );
717 				*ppNewComp = new VCLXCheckBox;
718 			break;
719 			case WINDOW_COMBOBOX:
720 				pNewWindow = new ComboBox( pParent, nWinBits|WB_AUTOHSCROLL );
721 				((ComboBox*)pNewWindow)->EnableAutoSize( sal_False );
722 				*ppNewComp = new VCLXComboBox;
723 			break;
724 			case WINDOW_CURRENCYBOX:
725 				pNewWindow = new CurrencyBox( pParent, nWinBits );
726 			break;
727 			case WINDOW_CURRENCYFIELD:
728 				pNewWindow = new CurrencyField( pParent, nWinBits );
729 				static_cast<CurrencyField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
730 				*ppNewComp = new VCLXNumericField;
731 				((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(CurrencyField*)pNewWindow );
732 			break;
733 			case WINDOW_DATEBOX:
734 				pNewWindow = new DateBox( pParent, nWinBits );
735 			break;
736 			case WINDOW_DATEFIELD:
737 				pNewWindow = new DateField( pParent, nWinBits );
738 				static_cast<DateField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
739 				*ppNewComp = new VCLXDateField;
740 				((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(DateField*)pNewWindow );
741 			break;
742 			case WINDOW_DOCKINGAREA:
743 				pNewWindow = new DockingAreaWindow( pParent );
744 			break;
745 			case WINDOW_MULTILINEEDIT:
746 			case WINDOW_EDIT:
747 				pNewWindow = new Edit( pParent, nWinBits );
748 				*ppNewComp = new VCLXEdit;
749 			break;
750 			case WINDOW_ERRORBOX:
751 				pNewWindow = new ErrorBox( pParent, nWinBits, String() );
752 				*ppNewComp = new VCLXMessageBox;
753 			break;
754 			case WINDOW_FIXEDBITMAP:
755 				pNewWindow = new FixedBitmap( pParent, nWinBits );
756 			break;
757 			case WINDOW_FIXEDIMAGE:
758 				pNewWindow = new ImageControl( pParent, nWinBits );
759 				*ppNewComp = new VCLXImageControl;
760 			break;
761 			case WINDOW_FIXEDLINE:
762 				pNewWindow = new FixedLine( pParent, nWinBits );
763 			break;
764 			case WINDOW_FIXEDTEXT:
765 				pNewWindow = new FixedText( pParent, nWinBits );
766 				*ppNewComp = new VCLXFixedText;
767 			break;
768 			case WINDOW_FLOATINGWINDOW:
769 				pNewWindow = new FloatingWindow( pParent, nWinBits );
770 			break;
771 			case WINDOW_GROUPBOX:
772 				pNewWindow = new GroupBox( pParent, nWinBits );
773 			break;
774 			case WINDOW_HELPBUTTON:
775 				pNewWindow = new HelpButton( pParent, nWinBits );
776 				*ppNewComp = new VCLXButton;
777 			break;
778 			case WINDOW_IMAGEBUTTON:
779  				pNewWindow = new ImageButton( pParent, nWinBits );
780 				*ppNewComp = new VCLXButton;
781 			break;
782 			case WINDOW_IMAGERADIOBUTTON:
783 				pNewWindow = new ImageRadioButton( pParent, nWinBits );
784 				*ppNewComp = new VCLXButton;
785 			break;
786 			case WINDOW_INFOBOX:
787 				pNewWindow = new InfoBox( pParent, String() );
788 				*ppNewComp = new VCLXMessageBox;
789 			break;
790 			case WINDOW_LISTBOX:
791 				pNewWindow = new ListBox( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL );
792 				((ListBox*)pNewWindow)->EnableAutoSize( sal_False );
793 				*ppNewComp = new VCLXListBox;
794 			break;
795 			case WINDOW_LONGCURRENCYBOX:
796 				pNewWindow = new LongCurrencyBox( pParent, nWinBits );
797 			break;
798 			case WINDOW_LONGCURRENCYFIELD:
799 				pNewWindow = new LongCurrencyField( pParent, nWinBits );
800 				*ppNewComp = new VCLXCurrencyField;
801 				((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(LongCurrencyField*)pNewWindow );
802 			break;
803 			case WINDOW_MENUBUTTON:
804 				pNewWindow = new MenuButton( pParent, nWinBits );
805 				*ppNewComp = new VCLXButton;
806 			break;
807 			case WINDOW_MESSBOX:
808 				pNewWindow = new MessBox( pParent, nWinBits, String(), String() );
809 				*ppNewComp = new VCLXMessageBox;
810 			break;
811 			case WINDOW_METRICBOX:
812 				pNewWindow = new MetricBox( pParent, nWinBits );
813 			break;
814 			case WINDOW_METRICFIELD:
815 				pNewWindow = new MetricField( pParent, nWinBits );
816 				*ppNewComp = new VCLXMetricField;
817 				((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(MetricField*)pNewWindow );
818 			break;
819 			case WINDOW_DIALOG:
820 			case WINDOW_MODALDIALOG:
821 			case WINDOW_MODELESSDIALOG:
822             {
823 				// Modal/Modeless nur durch Show/Execute
824 				if ( (pParent == NULL ) && ( rDescriptor.ParentIndex == -1 ) )
825 					pParent = DIALOG_NO_PARENT;
826 				pNewWindow = new Dialog( pParent, nWinBits );
827 				// #i70217# Don't always create a new component object. It's possible that VCL has called
828 				// GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() )
829 				// which creates a component object.
830 				css::uno::Reference< css::awt::XWindowPeer > xWinPeer = pNewWindow->GetComponentInterface( sal_False );
831 				if ( xWinPeer.is() )
832 					*ppNewComp = dynamic_cast< VCLXDialog* >( xWinPeer.get() );
833 				else
834 				    *ppNewComp = new VCLXDialog;
835             }
836 			break;
837 			case WINDOW_MOREBUTTON:
838 				pNewWindow = new MoreButton( pParent, nWinBits );
839 				*ppNewComp = new VCLXButton;
840 			break;
841 			case WINDOW_MULTILISTBOX:
842 				pNewWindow = new MultiListBox( pParent, nWinBits );
843 				*ppNewComp = new VCLXListBox;
844 			break;
845 			case WINDOW_NUMERICBOX:
846 				pNewWindow = new NumericBox( pParent, nWinBits );
847 			break;
848 			case WINDOW_NUMERICFIELD:
849 				pNewWindow = new NumericField( pParent, nWinBits );
850 				static_cast<NumericField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
851 				*ppNewComp = new VCLXNumericField;
852 				((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(NumericField*)pNewWindow );
853 			break;
854 			case WINDOW_OKBUTTON:
855 				pNewWindow = new OKButton( pParent, nWinBits );
856 				*ppNewComp = new VCLXButton;
857 			break;
858 			case WINDOW_PATTERNBOX:
859 				pNewWindow = new PatternBox( pParent, nWinBits );
860 			break;
861 			case WINDOW_PATTERNFIELD:
862 				pNewWindow = new PatternField( pParent, nWinBits );
863 				*ppNewComp = new VCLXPatternField;
864 				((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(PatternField*)pNewWindow );
865 			break;
866 			case WINDOW_PUSHBUTTON:
867 				pNewWindow = new PushButton( pParent, nWinBits );
868 				*ppNewComp = new VCLXButton;
869 			break;
870 			case WINDOW_QUERYBOX:
871 				pNewWindow = new QueryBox( pParent, nWinBits, String() );
872 				*ppNewComp = new VCLXMessageBox;
873 			break;
874 			case WINDOW_RADIOBUTTON:
875 				pNewWindow = new RadioButton( pParent, nWinBits );
876 				*ppNewComp = new VCLXRadioButton;
877 
878 				// by default, disable RadioCheck
879 				// Since the VCLXRadioButton really cares for it's RadioCheck settings, this is important:
880 				// if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState
881 				// This leads to a strange behaviour if the control is newly created: when settings the initial
882 				// state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck
883 				// _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls
884 				// is not really valid: the controls are grouped after they have been created, but we're still in
885 				// the creation process, so the RadioButton::Check relies on invalid grouping information.
886 				// 07.08.2001 - #87254# - frank.schoenheit@sun.com
887 				static_cast<RadioButton*>(pNewWindow)->EnableRadioCheck( sal_False );
888 			break;
889 			case WINDOW_SCROLLBAR:
890 				pNewWindow = new ScrollBar( pParent, nWinBits );
891 				*ppNewComp = new VCLXScrollBar;
892 			break;
893 			case WINDOW_SCROLLBARBOX:
894 				pNewWindow = new ScrollBarBox( pParent, nWinBits );
895 			break;
896 			case WINDOW_SPINBUTTON:
897 				pNewWindow = new SpinButton( pParent, nWinBits );
898                 *ppNewComp = new ::toolkit::VCLXSpinButton;
899 			break;
900 			case WINDOW_SPINFIELD:
901 				pNewWindow = new SpinField( pParent, nWinBits );
902 				*ppNewComp = new VCLXNumericField;
903 			break;
904 			case WINDOW_SPLITTER:
905 				pNewWindow = new Splitter( pParent, nWinBits );
906 			break;
907 			case WINDOW_SPLITWINDOW:
908 				pNewWindow = new SplitWindow( pParent, nWinBits );
909 			break;
910 			case WINDOW_STATUSBAR:
911 				pNewWindow = new StatusBar( pParent, nWinBits );
912 			break;
913 			case VCLWINDOW_SYSTEMCHILDWINDOW:
914 				pNewWindow = new SystemChildWindow( pParent, nWinBits );
915 				*ppNewComp = new VCLXSystemDependentWindow();
916 			break;
917 			case WINDOW_TABCONTROL:
918 				pNewWindow = new TabControl( pParent, nWinBits );
919                 *ppNewComp = new VCLXTabPageContainer;
920 			break;
921 			case WINDOW_TABDIALOG:
922 				pNewWindow = new TabDialog( pParent, nWinBits );
923 			break;
924 			case WINDOW_TABPAGE:
925                 /*
926 				if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase(
927                         ::rtl::OUString::createFromAscii("tabpagemodel") ) )
928                 {
929                     pNewWindow = new TabControl( pParent, nWinBits );
930                     *ppNewComp = new VCLXTabPageContainer;
931                 }
932 				else
933                 */
934 				{
935 					pNewWindow = new TabPage( pParent, nWinBits );
936 					*ppNewComp = new VCLXTabPage;
937 				}
938 			break;
939 			case WINDOW_TIMEBOX:
940 				pNewWindow = new TimeBox( pParent, nWinBits );
941 			break;
942 			case WINDOW_TIMEFIELD:
943 				pNewWindow = new TimeField( pParent, nWinBits );
944 				static_cast<TimeField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
945 				*ppNewComp = new VCLXTimeField;
946 				((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(TimeField*)pNewWindow );
947 			break;
948 			case WINDOW_TOOLBOX:
949 				pNewWindow = new ToolBox( pParent, nWinBits );
950 				*ppNewComp = new VCLXToolBox;
951 			break;
952 			case WINDOW_TRISTATEBOX:
953 				pNewWindow = new TriStateBox( pParent, nWinBits );
954 			break;
955 			case WINDOW_WARNINGBOX:
956 				pNewWindow = new WarningBox( pParent, nWinBits, String() );
957 				*ppNewComp = new VCLXMessageBox;
958 			break;
959 			case WINDOW_WORKWINDOW:
960 			case WINDOW_WINDOW:
961 			case VCLWINDOW_FRAMEWINDOW:
962 			case WINDOW_DOCKINGWINDOW:
963 				if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP )
964 				{
965 					if (nType == WINDOW_DOCKINGWINDOW )
966 						pNewWindow = new DockingWindow( pParent, nWinBits );
967 					else
968 					{
969 						if ((pParent == NULL) && rDescriptor.Parent.is())
970 						{
971 							// try to get a system dependent window handle
972 							::com::sun::star::uno::Reference< ::com::sun::star::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, ::com::sun::star::uno::UNO_QUERY);
973 
974 							if (xSystemDepParent.is())
975 							{
976 								sal_Int8 processID[16];
977 
978 								rtl_getGlobalProcessId( (sal_uInt8*)processID );
979 
980 								::com::sun::star::uno::Sequence<sal_Int8> processIdSeq(processID, 16);
981 
982 								::com::sun::star::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPE);
983 
984                                 // use sal_Int64 here to accommodate all int types
985                                 // uno::Any shift operator whill upcast if necessary
986                                 sal_Int64 nWindowHandle = 0;
987                                 sal_Bool bXEmbed = sal_False;
988 
989                                 bool bUseParentData = true;
990                                 if( ! (anyHandle >>= nWindowHandle) )
991                                 {
992                                     css::uno::Sequence< css::beans::NamedValue > aProps;
993                                     if( anyHandle >>= aProps )
994                                     {
995                                         const int nProps = aProps.getLength();
996                                         const css::beans::NamedValue* pProps = aProps.getConstArray();
997                                         for( int i = 0; i < nProps; i++ )
998                                         {
999                                             if( pProps[i].Name.equalsAscii( "WINDOW" ) )
1000                                                 pProps[i].Value >>= nWindowHandle;
1001                                             else if( pProps[i].Name.equalsAscii( "XEMBED" ) )
1002                                                 pProps[i].Value >>= bXEmbed;
1003                                         }
1004                                     }
1005                                     else
1006                                         bUseParentData = false;
1007                                 }
1008 
1009                                 if( bUseParentData )
1010                                 {
1011                                     SystemParentData aParentData;
1012                                     aParentData.nSize	= sizeof( aParentData );
1013                                     #if defined QUARTZ
1014                                     aParentData.pView	= reinterpret_cast<NSView*>(nWindowHandle);
1015                                     #elif defined UNX
1016                                     aParentData.aWindow = nWindowHandle;
1017                                     aParentData.bXEmbedSupport = bXEmbed;
1018                                     #elif defined WNT
1019                                     aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1020                                     #elif defined OS2
1021                                     aParentData.hWnd = (HWND)nWindowHandle;
1022                                     #endif
1023                                     pNewWindow = new WorkWindow( &aParentData );
1024                                 }
1025 							}
1026 						}
1027 
1028 						if (!pNewWindow)
1029 							pNewWindow = new WorkWindow( pParent, nWinBits );
1030 					}
1031 
1032                     *ppNewComp = new VCLXTopWindow( pNewWindow->GetType() == WINDOW_WORKWINDOW );
1033 				}
1034 				else if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_CONTAINER )
1035 				{
1036 					if (nType == WINDOW_DOCKINGWINDOW )
1037 						pNewWindow = new DockingWindow( pParent, nWinBits );
1038 					else
1039 						pNewWindow = new Window( pParent, nWinBits );
1040 					*ppNewComp = new VCLXContainer;
1041 				}
1042 				else
1043 				{
1044 					if (nType == WINDOW_DOCKINGWINDOW )
1045 						pNewWindow = new DockingWindow( pParent, nWinBits );
1046 					else
1047 						pNewWindow = new Window( pParent, nWinBits );
1048 					*ppNewComp = new VCLXWindow;
1049 				}
1050 			break;
1051 			case WINDOW_CONTROL:
1052                 if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase(
1053                         ::rtl::OUString::createFromAscii("tabpagecontainer") ) )
1054                 {
1055                     pNewWindow = new TabControl( pParent, nWinBits );
1056                     *ppNewComp = new VCLXTabPageContainer;
1057                 }
1058                 else if ( aServiceName.EqualsAscii( "animatedimages" ) )
1059                 {
1060                     pNewWindow = new Throbber( pParent, nWinBits );
1061                     *ppNewComp = new ::toolkit::AnimatedImagesPeer;
1062                 }
1063 			break;
1064             default:
1065                 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" );
1066                 break;
1067 		}
1068 	}
1069 
1070 	return pNewWindow;
1071 }
1072 
1073 extern "C" { static void SAL_CALL thisModule() {} }
1074 
1075 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow(
1076     const css::awt::WindowDescriptor& rDescriptor,
1077     WinBits nForceWinBits )
1078 {
1079 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1080 
1081 	osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() );
1082 
1083 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef;
1084 
1085 	Window* pParent = NULL;
1086 	if ( rDescriptor.Parent.is() )
1087 	{
1088 		VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( rDescriptor.Parent );
1089 
1090         // #103939# Don't through assertion, may be it's a system dependend window, used in ImplCreateWindow.
1091         // DBG_ASSERT( pParentComponent, "ParentComponent not valid" );
1092 
1093 		if ( pParentComponent )
1094 			pParent = pParentComponent->GetWindow();
1095 	}
1096 
1097 	WinBits nWinBits = ImplGetWinBits( rDescriptor.WindowAttributes,
1098 		ImplGetComponentType( rDescriptor.WindowServiceName ) );
1099     nWinBits |= nForceWinBits;
1100 
1101 	VCLXWindow* pNewComp = NULL;
1102 
1103 	Window* pNewWindow = NULL;
1104 	// Try to create the window with SvTools
1105 	// (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way,
1106 	// and we need to stay compatible)
1107 	// try to load the lib
1108 	if ( !fnSvtCreateWindow && !hSvToolsLib )
1109 	{
1110 		::rtl::OUString aLibName = ::vcl::unohelper::CreateLibraryName( "svt", sal_True );
1111         hSvToolsLib = osl_loadModuleRelative(
1112             &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT );
1113 		if ( hSvToolsLib )
1114 		{
1115 			::rtl::OUString aFunctionName( RTL_CONSTASCII_USTRINGPARAM( "CreateWindow" ) );
1116 			fnSvtCreateWindow = (FN_SvtCreateWindow)osl_getFunctionSymbol( hSvToolsLib, aFunctionName.pData );
1117 		}
1118 	}
1119 	// ask the SvTool creation function
1120 	if ( fnSvtCreateWindow )
1121 		pNewWindow = fnSvtCreateWindow( &pNewComp, &rDescriptor, pParent, nWinBits );
1122 
1123 	// if SvTools could not provide a window, create it ourself
1124 	if ( !pNewWindow )
1125 		pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits );
1126 
1127 	DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" );
1128 	DBG_ASSERTWARNING( pNewComp, "createWindow: No special Interface!" );
1129 
1130 	if ( pNewWindow )
1131 	{
1132 		pNewWindow->SetCreatedWithToolkit( sal_True );
1133 		//pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead
1134 
1135         if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::MINSIZE )
1136 		{
1137 			pNewWindow->SetSizePixel( Size() );
1138 		}
1139 		else if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::FULLSIZE )
1140 		{
1141 			if ( pParent )
1142 				pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() );
1143 		}
1144 		else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) )
1145 		{
1146 			Rectangle aRect = VCLRectangle( rDescriptor.Bounds );
1147 			pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
1148 		}
1149 
1150 		if ( !pNewComp )
1151 		{
1152 			// Default-Interface
1153 			xRef = pNewWindow->GetComponentInterface( sal_True );
1154 		}
1155 		else
1156 		{
1157 			pNewComp->SetCreatedWithToolkit( sal_True );
1158 			xRef = pNewComp;
1159 			pNewWindow->SetComponentInterface( xRef );
1160 		}
1161         DBG_ASSERT( pNewWindow->GetComponentInterface( sal_False ) == xRef,
1162             "VCLXToolkit::createWindow: did #133706# resurge?" );
1163 
1164 		if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::SHOW )
1165 			pNewWindow->Show();
1166 	}
1167 
1168 	return xRef;
1169 }
1170 
1171 ::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)
1172 {
1173 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1174 
1175 	sal_uInt32 nComponents = rDescriptors.getLength();
1176 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > > aSeq( nComponents );
1177 	for ( sal_uInt32 n = 0; n < nComponents; n++ )
1178 	{
1179 		::com::sun::star::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n];
1180 
1181 		if ( aDescr.ParentIndex == (-1) )
1182 			aDescr.Parent = NULL;
1183 		else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < (short)n ) )
1184 			aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex];
1185 		aSeq.getArray()[n] = createWindow( aDescr );
1186 	}
1187 	return aSeq;
1188 }
1189 
1190 // ::com::sun::star::awt::XSystemChildFactory
1191 ::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)
1192 {
1193 	Window* pChildWindow = NULL;
1194 	if ( nSystemType == SYSTEM_DEPENDENT_TYPE )
1195 	{
1196         // use sal_Int64 here to accommodate all int types
1197         // uno::Any shift operator whill upcast if necessary
1198         sal_Int64 nWindowHandle = 0;
1199         sal_Bool bXEmbed = sal_False;
1200 
1201         bool bUseParentData = true;
1202         if( ! (Parent >>= nWindowHandle) )
1203         {
1204             css::uno::Sequence< css::beans::NamedValue > aProps;
1205             if( Parent >>= aProps )
1206             {
1207                 const int nProps = aProps.getLength();
1208                 const css::beans::NamedValue* pProps = aProps.getConstArray();
1209                 for( int i = 0; i < nProps; i++ )
1210                 {
1211                     if( pProps[i].Name.equalsAscii( "WINDOW" ) )
1212                         pProps[i].Value >>= nWindowHandle;
1213                     else if( pProps[i].Name.equalsAscii( "XEMBED" ) )
1214                         pProps[i].Value >>= bXEmbed;
1215                 }
1216             }
1217             else
1218                 bUseParentData = false;
1219         }
1220 
1221         if( bUseParentData )
1222         {
1223             SystemParentData aParentData;
1224             aParentData.nSize	= sizeof( aParentData );
1225             #if defined QUARTZ
1226             aParentData.pView	= reinterpret_cast<NSView*>(nWindowHandle);
1227             #elif defined UNX
1228             aParentData.aWindow = nWindowHandle;
1229             aParentData.bXEmbedSupport = bXEmbed;
1230             #elif defined WNT
1231             aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1232             #elif defined OS2
1233             aParentData.hWnd = (HWND)nWindowHandle;
1234             #endif
1235             osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() );
1236             try
1237             {
1238                 pChildWindow = new WorkWindow( &aParentData );
1239             }
1240             catch ( ::com::sun::star::uno::RuntimeException & rEx )
1241             {
1242                 // system child window could not be created
1243                 OSL_TRACE(
1244                     "VCLXToolkit::createSystemChild: caught %s\n",
1245                     ::rtl::OUStringToOString(
1246                         rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1247                 pChildWindow = NULL;
1248             }
1249         }
1250 	}
1251     else if (nSystemType == com::sun::star::lang::SystemDependent::SYSTEM_JAVA)
1252     {
1253         osl::Guard< vos::IMutex > aGuard(Application::GetSolarMutex());
1254         pChildWindow = new WorkWindow(0, Parent);
1255     }
1256 
1257 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xPeer;
1258 	if ( pChildWindow )
1259 	{
1260         VCLXTopWindow* pPeer = new VCLXTopWindow(true);
1261         osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() );
1262 		pPeer->SetWindow( pChildWindow );
1263 		xPeer = pPeer;
1264 	}
1265 
1266 	return xPeer;
1267 }
1268 
1269 // ::com::sun::star::awt::XMessageBoxFactory
1270 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox(
1271     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& aParent,
1272     ::com::sun::star::awt::MessageBoxType eType,
1273     ::sal_Int32 aButtons,
1274     const ::rtl::OUString& aTitle,
1275     const ::rtl::OUString& aMessage ) throw (::com::sun::star::uno::RuntimeException)
1276 {
1277     ::com::sun::star::awt::WindowDescriptor aDescriptor;
1278 
1279     sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE;
1280 
1281     // Map button definitions to window attributes
1282     if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK )
1283         nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK;
1284     else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL )
1285         nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL;
1286     else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO )
1287         nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO;
1288     else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL )
1289         nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL;
1290     else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL )
1291         nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL;
1292 
1293     // Map default button definitions to window attributes
1294     if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK )
1295         nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK;
1296     else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL )
1297         nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL;
1298     else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES )
1299         nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES;
1300     else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO )
1301         nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO;
1302     else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY )
1303         nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY;
1304 
1305     // No more bits for VclWindowPeerAttribute possible. Mapping must be
1306     // done explicitly using VCL methods
1307     WinBits nAddWinBits( 0 );
1308     if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY )
1309         nAddWinBits |= WB_ABORT_RETRY_IGNORE;
1310     if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE )
1311         nAddWinBits |= WB_DEF_IGNORE;
1312 
1313     rtl::OUString aType;
1314     lcl_convertMessageBoxType( aType, eType );
1315 
1316     aDescriptor.Type              = css::awt::WindowClass_MODALTOP;
1317     aDescriptor.WindowServiceName = aType;
1318     aDescriptor.ParentIndex       = -1;
1319     aDescriptor.Parent            = aParent;
1320     aDescriptor.WindowAttributes  = nWindowAttributes;
1321     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > xMsgBox(
1322         ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY );
1323     css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY );
1324     if ( xMsgBox.is() && xWindow.is() )
1325     {
1326 	    Window * pWindow = VCLUnoHelper::GetWindow( xWindow );
1327         if ( pWindow )
1328         {
1329             osl::Guard< vos::IMutex > aGuard(Application::GetSolarMutex());
1330             xMsgBox->setCaptionText( aTitle );
1331             xMsgBox->setMessageText( aMessage );
1332         }
1333     }
1334 
1335     return xMsgBox;
1336 }
1337 
1338 ::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)
1339 {
1340 	Window * pWindow = VCLUnoHelper::GetWindow( window );
1341 
1342 	if( pWindow )
1343 		return pWindow->GetDragGestureRecognizer();
1344 
1345 	return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer >();
1346 }
1347 
1348 ::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)
1349 {
1350 	Window * pWindow = VCLUnoHelper::GetWindow( window );
1351 
1352 	if( pWindow )
1353 		return pWindow->GetDragSource();
1354 
1355 	return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource >();
1356 }
1357 
1358 ::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)
1359 {
1360 	Window * pWindow = VCLUnoHelper::GetWindow( window );
1361 
1362 	if( pWindow )
1363 		return pWindow->GetDropTarget();
1364 
1365 	return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTarget >();
1366 }
1367 
1368 ::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)
1369 {
1370 	if( clipboardName.getLength() == 0 )
1371 	{
1372 		if( !mxClipboard.is() )
1373 		{
1374 			::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
1375 			if ( xFactory.is() )
1376 			{
1377 				// remember clipboard here
1378 				mxClipboard = ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > (
1379 					xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.SystemClipboard" ) ), ::com::sun::star::uno::UNO_QUERY );
1380 			}
1381 		}
1382 
1383 		return mxClipboard;
1384 	}
1385 
1386 	else if( clipboardName.equals( ::rtl::OUString::createFromAscii("Selection") ) )
1387 	{
1388 		return mxSelection;
1389 	}
1390 
1391 	return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >();
1392 }
1393 
1394 // XServiceInfo
1395 ::rtl::OUString VCLXToolkit::getImplementationName() throw(::com::sun::star::uno::RuntimeException)
1396 {
1397 	return rtl::OUString::createFromAscii( "stardiv.Toolkit.VCLXToolkit" );
1398 }
1399 
1400 sal_Bool VCLXToolkit::supportsService( const ::rtl::OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException)
1401 {
1402 	::osl::MutexGuard aGuard( GetMutex() );
1403 
1404     ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
1405 	const ::rtl::OUString* pArray = aSNL.getConstArray();
1406 	const ::rtl::OUString* pArrayEnd = aSNL.getConstArray();
1407 	for (; pArray != pArrayEnd; ++pArray )
1408 		if( *pArray == rServiceName )
1409 			break;
1410 
1411 	return pArray != pArrayEnd;
1412 }
1413 
1414 ::com::sun::star::uno::Sequence< ::rtl::OUString > VCLXToolkit::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException)
1415 {
1416     ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( szServiceName2_Toolkit ) );
1417     return ::com::sun::star::uno::Sequence< ::rtl::OUString >( &aServiceName, 1);
1418 }
1419 
1420 // css::awt::XExtendedToolkit:
1421 
1422 // virtual
1423 ::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount()
1424     throw (::css::uno::RuntimeException)
1425 {
1426     return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount());
1427         // XXX  numeric overflow
1428 }
1429 
1430 // virtual
1431 ::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL
1432 VCLXToolkit::getTopWindow(::sal_Int32 nIndex)
1433     throw (::css::uno::RuntimeException)
1434 {
1435     ::Window * p = ::Application::GetTopWindow(static_cast< long >(nIndex));
1436         // XXX  numeric overflow
1437     return ::css::uno::Reference< ::css::awt::XTopWindow >(
1438         p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()),
1439         ::css::uno::UNO_QUERY);
1440 }
1441 
1442 // virtual
1443 ::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL
1444 VCLXToolkit::getActiveTopWindow() throw (::css::uno::RuntimeException)
1445 {
1446     ::Window * p = ::Application::GetActiveTopWindow();
1447     return ::css::uno::Reference< ::css::awt::XTopWindow >(
1448         p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()),
1449         ::css::uno::UNO_QUERY);
1450 }
1451 
1452 // virtual
1453 void SAL_CALL VCLXToolkit::addTopWindowListener(
1454     ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener)
1455     throw (::css::uno::RuntimeException)
1456 {
1457     OSL_ENSURE(rListener.is(), "Null rListener");
1458     ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1459     if (rBHelper.bDisposed || rBHelper.bInDispose)
1460     {
1461         aGuard.clear();
1462         rListener->disposing(
1463             ::css::lang::EventObject(
1464                 static_cast< ::cppu::OWeakObject * >(this)));
1465     }
1466     else if (m_aTopWindowListeners.addInterface(rListener) == 1
1467              && !m_bEventListener)
1468     {
1469         m_bEventListener = true;
1470         ::Application::AddEventListener(m_aEventListenerLink);
1471     }
1472 }
1473 
1474 // virtual
1475 void SAL_CALL VCLXToolkit::removeTopWindowListener(
1476     ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener)
1477     throw (::css::uno::RuntimeException)
1478 {
1479     ::osl::MutexGuard aGuard(rBHelper.rMutex);
1480     if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1481         && m_aTopWindowListeners.removeInterface(rListener) == 0
1482         && m_aFocusListeners.getLength() == 0 && m_bEventListener)
1483     {
1484         ::Application::RemoveEventListener(m_aEventListenerLink);
1485         m_bEventListener = false;
1486     }
1487 }
1488 
1489 // virtual
1490 void SAL_CALL VCLXToolkit::addKeyHandler(
1491     ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler)
1492     throw (::css::uno::RuntimeException)
1493 {
1494     OSL_ENSURE(rHandler.is(), "Null rHandler");
1495     ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1496     if (rBHelper.bDisposed || rBHelper.bInDispose)
1497     {
1498         aGuard.clear();
1499         rHandler->disposing(
1500             ::css::lang::EventObject(
1501                 static_cast< ::cppu::OWeakObject * >(this)));
1502     }
1503     else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener)
1504     {
1505         m_bKeyListener = true;
1506         ::Application::AddKeyListener(m_aKeyListenerLink);
1507     }
1508 }
1509 
1510 // virtual
1511 void SAL_CALL VCLXToolkit::removeKeyHandler(
1512     ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler)
1513     throw (::css::uno::RuntimeException)
1514 {
1515     ::osl::MutexGuard aGuard(rBHelper.rMutex);
1516     if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1517         && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener)
1518     {
1519         ::Application::RemoveKeyListener(m_aKeyListenerLink);
1520         m_bKeyListener = false;
1521     }
1522 }
1523 
1524 // virtual
1525 void SAL_CALL VCLXToolkit::addFocusListener(
1526     ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener)
1527     throw (::css::uno::RuntimeException)
1528 {
1529     OSL_ENSURE(rListener.is(), "Null rListener");
1530     ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1531     if (rBHelper.bDisposed || rBHelper.bInDispose)
1532     {
1533         aGuard.clear();
1534         rListener->disposing(
1535             ::css::lang::EventObject(
1536                 static_cast< ::cppu::OWeakObject * >(this)));
1537     }
1538     else if (m_aFocusListeners.addInterface(rListener) == 1
1539              && !m_bEventListener)
1540     {
1541         m_bEventListener = true;
1542         ::Application::AddEventListener(m_aEventListenerLink);
1543     }
1544 }
1545 
1546 // virtual
1547 void SAL_CALL VCLXToolkit::removeFocusListener(
1548     ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener)
1549     throw (::css::uno::RuntimeException)
1550 {
1551     ::osl::MutexGuard aGuard(rBHelper.rMutex);
1552     if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1553         && m_aFocusListeners.removeInterface(rListener) == 0
1554         && m_aTopWindowListeners.getLength() == 0 && m_bEventListener)
1555     {
1556         ::Application::RemoveEventListener(m_aEventListenerLink);
1557         m_bEventListener = false;
1558     }
1559 }
1560 
1561 // virtual
1562 void SAL_CALL VCLXToolkit::fireFocusGained(
1563     ::com::sun::star::uno::Reference<
1564     ::com::sun::star::uno::XInterface > const &)
1565     throw (::com::sun::star::uno::RuntimeException)
1566 {
1567 }
1568 
1569 // virtual
1570 void SAL_CALL VCLXToolkit::fireFocusLost(
1571     ::com::sun::star::uno::Reference<
1572     ::com::sun::star::uno::XInterface > const &)
1573     throw (::com::sun::star::uno::RuntimeException)
1574 {
1575 }
1576 
1577 
1578 IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent const *, pEvent)
1579 {
1580     switch (pEvent->GetId())
1581     {
1582     case VCLEVENT_WINDOW_SHOW:
1583         callTopWindowListeners(
1584             pEvent, &::css::awt::XTopWindowListener::windowOpened);
1585         break;
1586     case VCLEVENT_WINDOW_HIDE:
1587         callTopWindowListeners(
1588             pEvent, &::css::awt::XTopWindowListener::windowClosed);
1589         break;
1590     case VCLEVENT_WINDOW_ACTIVATE:
1591         callTopWindowListeners(
1592             pEvent, &::css::awt::XTopWindowListener::windowActivated);
1593         break;
1594     case VCLEVENT_WINDOW_DEACTIVATE:
1595         callTopWindowListeners(
1596             pEvent, &::css::awt::XTopWindowListener::windowDeactivated);
1597         break;
1598     case VCLEVENT_WINDOW_CLOSE:
1599         callTopWindowListeners(
1600             pEvent, &::css::awt::XTopWindowListener::windowClosing);
1601         break;
1602     case VCLEVENT_WINDOW_GETFOCUS:
1603         callFocusListeners(pEvent, true);
1604         break;
1605     case VCLEVENT_WINDOW_LOSEFOCUS:
1606         callFocusListeners(pEvent, false);
1607         break;
1608     case VCLEVENT_WINDOW_MINIMIZE:
1609         callTopWindowListeners(
1610             pEvent, &::css::awt::XTopWindowListener::windowMinimized);
1611         break;
1612     case VCLEVENT_WINDOW_NORMALIZE:
1613         callTopWindowListeners(
1614             pEvent, &::css::awt::XTopWindowListener::windowNormalized);
1615         break;
1616     }
1617     return 0;
1618 }
1619 
1620 IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclSimpleEvent const *, pEvent)
1621 {
1622     switch (pEvent->GetId())
1623     {
1624     case VCLEVENT_WINDOW_KEYINPUT:
1625         return callKeyHandlers(pEvent, true);
1626     case VCLEVENT_WINDOW_KEYUP:
1627         return callKeyHandlers(pEvent, false);
1628     }
1629     return 0;
1630 }
1631 
1632 void VCLXToolkit::callTopWindowListeners(
1633     ::VclSimpleEvent const * pEvent,
1634     void (SAL_CALL ::css::awt::XTopWindowListener::* pFn)(
1635         ::css::lang::EventObject const &))
1636 {
1637     ::Window * pWindow
1638           = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1639     if (pWindow->IsTopWindow())
1640     {
1641         ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
1642               aListeners(m_aTopWindowListeners.getElements());
1643         if (aListeners.hasElements())
1644         {
1645             ::css::lang::EventObject aAwtEvent(
1646                 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()));
1647             for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i)
1648             {
1649                 ::css::uno::Reference< ::css::awt::XTopWindowListener >
1650                       xListener(aListeners[i], ::css::uno::UNO_QUERY);
1651                 try
1652                 {
1653                     (xListener.get()->*pFn)(aAwtEvent);
1654                 }
1655                 catch (::css::uno::RuntimeException & rEx)
1656                 {
1657                     OSL_TRACE(
1658                         "VCLXToolkit::callTopWindowListeners: caught %s\n",
1659                         ::rtl::OUStringToOString(
1660                             rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1661                 }
1662             }
1663         }
1664     }
1665 }
1666 
1667 long VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent,
1668                                   bool bPressed)
1669 {
1670     ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
1671           aHandlers(m_aKeyHandlers.getElements());
1672 
1673     if (aHandlers.hasElements())
1674     {
1675         ::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1676 
1677         // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event
1678         ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >(
1679             static_cast< ::VclWindowEvent const * >(pEvent)->GetData());
1680         ::css::awt::KeyEvent aAwtEvent(
1681             static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()),
1682             (pKeyEvent->GetKeyCode().IsShift()
1683              ? ::css::awt::KeyModifier::SHIFT : 0)
1684             | (pKeyEvent->GetKeyCode().IsMod1()
1685                ? ::css::awt::KeyModifier::MOD1 : 0)
1686             | (pKeyEvent->GetKeyCode().IsMod2()
1687                ? ::css::awt::KeyModifier::MOD2 : 0)
1688             | (pKeyEvent->GetKeyCode().IsMod3()
1689                ? ::css::awt::KeyModifier::MOD3 : 0),
1690             pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(),
1691             sal::static_int_cast< sal_Int16 >(
1692                 pKeyEvent->GetKeyCode().GetFunction()));
1693         for (::sal_Int32 i = 0; i < aHandlers.getLength(); ++i)
1694         {
1695             ::css::uno::Reference< ::css::awt::XKeyHandler > xHandler(
1696                 aHandlers[i], ::css::uno::UNO_QUERY);
1697             try
1698             {
1699                 if ((bPressed ? xHandler->keyPressed(aAwtEvent)
1700                       : xHandler->keyReleased(aAwtEvent)))
1701                     return 1;
1702             }
1703             catch (::css::uno::RuntimeException & rEx)
1704             {
1705                 OSL_TRACE(
1706                     "VCLXToolkit::callKeyHandlers: caught %s\n",
1707                     ::rtl::OUStringToOString(
1708                        rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1709             }
1710         }
1711     }
1712     return 0;
1713 }
1714 
1715 void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent,
1716                                      bool bGained)
1717 {
1718     ::Window * pWindow
1719           = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1720     if (pWindow->IsTopWindow())
1721     {
1722         ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
1723               aListeners(m_aFocusListeners.getElements());
1724         if (aListeners.hasElements())
1725         {
1726             // Ignore the interior of compound controls when determining the
1727             // window that gets the focus next (see implementation in
1728             // vclxwindow.cxx for mapping between VCL and UNO AWT event):
1729             ::css::uno::Reference< css::uno::XInterface > xNext;
1730             ::Window * pFocus = ::Application::GetFocusWindow();
1731             for (::Window * p = pFocus; p != 0; p = p->GetParent())
1732                 if (!p->IsCompoundControl())
1733                 {
1734                     pFocus = p;
1735                     break;
1736                 }
1737             if (pFocus != 0)
1738                 xNext = pFocus->GetComponentInterface(true);
1739             ::css::awt::FocusEvent aAwtEvent(
1740                 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()),
1741                 pWindow->GetGetFocusFlags(), xNext, false);
1742             for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i)
1743             {
1744                 ::css::uno::Reference< ::css::awt::XFocusListener > xListener(
1745                     aListeners[i], ::css::uno::UNO_QUERY);
1746                 try
1747                 {
1748                     bGained ? xListener->focusGained(aAwtEvent)
1749                         : xListener->focusLost(aAwtEvent);
1750                 }
1751                 catch (::css::uno::RuntimeException & rEx)
1752                 {
1753                     OSL_TRACE(
1754                         "VCLXToolkit::callFocusListeners: caught %s\n",
1755                         ::rtl::OUStringToOString(
1756                             rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1757                 }
1758             }
1759         }
1760     }
1761 }
1762 
1763 // css::awt::XReschedule:
1764 
1765 void SAL_CALL VCLXToolkit::reschedule()
1766     throw (::com::sun::star::uno::RuntimeException)
1767 {
1768     Application::Reschedule(true);
1769 }
1770 
1771