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