xref: /trunk/main/toolkit/source/awt/vclxtoolkit.cxx (revision ffad8df045fe8db79e3e50f731c1fa6ab6501c83)
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 // contructor, 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 //IAccessibility2 Implementation 2009-----
636 #ifdef WNT
637     CEnableAccessInterface e;
638 #endif
639 //-----IAccessibility2 Implementation 2009
640     return ImplCreateWindow( rDescriptor, WinBits(0) );
641 }
642 
643 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) throw(::com::sun::star::uno::RuntimeException)
644 {
645     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
646 
647     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > xRef;
648     VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
649 
650     osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() );
651 
652     VirtualDevice* pV = new VirtualDevice;
653     pV->SetOutputSizePixel( Size( Width, Height ) );
654     pVDev->SetVirtualDevice( pV );
655 
656     xRef = pVDev;
657     return xRef;
658 }
659 
660 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion > VCLXToolkit::createRegion(  ) throw(::com::sun::star::uno::RuntimeException)
661 {
662     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
663 
664     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >  xRef = new VCLXRegion;
665     return xRef;
666 }
667 
668 Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp,
669     const ::com::sun::star::awt::WindowDescriptor& rDescriptor,
670     Window* pParent, WinBits nWinBits )
671 {
672     String aServiceName( rDescriptor.WindowServiceName );
673     aServiceName.ToLowerAscii();
674 
675     Window* pNewWindow = NULL;
676     sal_uInt16 nType = ImplGetComponentType( aServiceName );
677 
678     if ( !pParent )
679     {
680         // Wenn die Component einen Parent braucht, dann NULL zurueckgeben,
681         // spaeter mal ::com::sun::star::uno::Exception...
682         sal_Bool bException = sal_True;
683         if  (   ( nType == WINDOW_DIALOG )
684             ||  ( nType == WINDOW_MODALDIALOG )
685             ||  ( nType == WINDOW_MODELESSDIALOG )
686             ||  ( nType == WINDOW_MESSBOX )
687             ||  ( nType == WINDOW_INFOBOX )
688             ||  ( nType == WINDOW_WARNINGBOX )
689             ||  ( nType == WINDOW_ERRORBOX )
690             ||  ( nType == WINDOW_QUERYBOX )
691             )
692             bException = sal_False;
693         else if ( ( nType == WINDOW_WINDOW ) ||
694                   ( nType == WINDOW_WORKWINDOW ) ||
695                   ( nType == VCLWINDOW_FRAMEWINDOW ) )
696         {
697             if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP )
698                 bException = sal_False;
699         }
700 
701         if ( bException )
702         {
703             *ppNewComp = NULL;
704             return NULL;
705         }
706     }
707 
708     if ( nType )
709     {
710         vos::OGuard aVclGuard( Application::GetSolarMutex()  );
711         switch ( (WindowType)nType )
712         {
713             case WINDOW_CANCELBUTTON:
714                 pNewWindow = new CancelButton( pParent, nWinBits );
715                 *ppNewComp = new VCLXButton;
716             break;
717             case WINDOW_CHECKBOX:
718                 pNewWindow = new CheckBox( pParent, nWinBits );
719                 *ppNewComp = new VCLXCheckBox;
720             break;
721             case WINDOW_COMBOBOX:
722                 pNewWindow = new ComboBox( pParent, nWinBits|WB_AUTOHSCROLL );
723                 ((ComboBox*)pNewWindow)->EnableAutoSize( sal_False );
724                 *ppNewComp = new VCLXComboBox;
725             break;
726             case WINDOW_CURRENCYBOX:
727                 pNewWindow = new CurrencyBox( pParent, nWinBits );
728             break;
729             case WINDOW_CURRENCYFIELD:
730                 pNewWindow = new CurrencyField( pParent, nWinBits );
731                 static_cast<CurrencyField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
732                 *ppNewComp = new VCLXNumericField;
733                 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(CurrencyField*)pNewWindow );
734             break;
735             case WINDOW_DATEBOX:
736                 pNewWindow = new DateBox( pParent, nWinBits );
737             break;
738             case WINDOW_DATEFIELD:
739                 pNewWindow = new DateField( pParent, nWinBits );
740                 static_cast<DateField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
741                 *ppNewComp = new VCLXDateField;
742                 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(DateField*)pNewWindow );
743             break;
744             case WINDOW_DOCKINGAREA:
745                 pNewWindow = new DockingAreaWindow( pParent );
746             break;
747             case WINDOW_MULTILINEEDIT:
748             case WINDOW_EDIT:
749                 pNewWindow = new Edit( pParent, nWinBits );
750                 *ppNewComp = new VCLXEdit;
751             break;
752             case WINDOW_ERRORBOX:
753                 pNewWindow = new ErrorBox( pParent, nWinBits, String() );
754                 *ppNewComp = new VCLXMessageBox;
755             break;
756             case WINDOW_FIXEDBITMAP:
757                 pNewWindow = new FixedBitmap( pParent, nWinBits );
758             break;
759             case WINDOW_FIXEDIMAGE:
760                 pNewWindow = new ImageControl( pParent, nWinBits );
761                 *ppNewComp = new VCLXImageControl;
762             break;
763             case WINDOW_FIXEDLINE:
764                 pNewWindow = new FixedLine( pParent, nWinBits );
765             break;
766             case WINDOW_FIXEDTEXT:
767                 pNewWindow = new FixedText( pParent, nWinBits );
768                 *ppNewComp = new VCLXFixedText;
769             break;
770             case WINDOW_FLOATINGWINDOW:
771                 pNewWindow = new FloatingWindow( pParent, nWinBits );
772             break;
773             case WINDOW_GROUPBOX:
774                 pNewWindow = new GroupBox( pParent, nWinBits );
775             break;
776             case WINDOW_HELPBUTTON:
777                 pNewWindow = new HelpButton( pParent, nWinBits );
778                 *ppNewComp = new VCLXButton;
779             break;
780             case WINDOW_IMAGEBUTTON:
781                 pNewWindow = new ImageButton( pParent, nWinBits );
782                 *ppNewComp = new VCLXButton;
783             break;
784             case WINDOW_IMAGERADIOBUTTON:
785                 pNewWindow = new ImageRadioButton( pParent, nWinBits );
786                 *ppNewComp = new VCLXButton;
787             break;
788             case WINDOW_INFOBOX:
789                 pNewWindow = new InfoBox( pParent, String() );
790                 *ppNewComp = new VCLXMessageBox;
791             break;
792             case WINDOW_LISTBOX:
793                 pNewWindow = new ListBox( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL );
794                 ((ListBox*)pNewWindow)->EnableAutoSize( sal_False );
795                 *ppNewComp = new VCLXListBox;
796             break;
797             case WINDOW_LONGCURRENCYBOX:
798                 pNewWindow = new LongCurrencyBox( pParent, nWinBits );
799             break;
800             case WINDOW_LONGCURRENCYFIELD:
801                 pNewWindow = new LongCurrencyField( pParent, nWinBits );
802                 *ppNewComp = new VCLXCurrencyField;
803                 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(LongCurrencyField*)pNewWindow );
804             break;
805             case WINDOW_MENUBUTTON:
806                 pNewWindow = new MenuButton( pParent, nWinBits );
807                 *ppNewComp = new VCLXButton;
808             break;
809             case WINDOW_MESSBOX:
810                 pNewWindow = new MessBox( pParent, nWinBits, String(), String() );
811                 *ppNewComp = new VCLXMessageBox;
812             break;
813             case WINDOW_METRICBOX:
814                 pNewWindow = new MetricBox( pParent, nWinBits );
815             break;
816             case WINDOW_METRICFIELD:
817                 pNewWindow = new MetricField( pParent, nWinBits );
818                 *ppNewComp = new VCLXMetricField;
819                 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(MetricField*)pNewWindow );
820             break;
821             case WINDOW_DIALOG:
822             case WINDOW_MODALDIALOG:
823             case WINDOW_MODELESSDIALOG:
824             {
825                 // Modal/Modeless nur durch Show/Execute
826                 if ( (pParent == NULL ) && ( rDescriptor.ParentIndex == -1 ) )
827                     pParent = DIALOG_NO_PARENT;
828                 pNewWindow = new Dialog( pParent, nWinBits );
829                 // #i70217# Don't always create a new component object. It's possible that VCL has called
830                 // GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() )
831                 // which creates a component object.
832                 css::uno::Reference< css::awt::XWindowPeer > xWinPeer = pNewWindow->GetComponentInterface( sal_False );
833                 if ( xWinPeer.is() )
834                     *ppNewComp = dynamic_cast< VCLXDialog* >( xWinPeer.get() );
835                 else
836                     *ppNewComp = new VCLXDialog;
837             }
838             break;
839             case WINDOW_MOREBUTTON:
840                 pNewWindow = new MoreButton( pParent, nWinBits );
841                 *ppNewComp = new VCLXButton;
842             break;
843             case WINDOW_MULTILISTBOX:
844                 pNewWindow = new MultiListBox( pParent, nWinBits );
845                 *ppNewComp = new VCLXListBox;
846             break;
847             case WINDOW_NUMERICBOX:
848                 pNewWindow = new NumericBox( pParent, nWinBits );
849             break;
850             case WINDOW_NUMERICFIELD:
851                 pNewWindow = new NumericField( pParent, nWinBits );
852                 static_cast<NumericField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
853                 *ppNewComp = new VCLXNumericField;
854                 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(NumericField*)pNewWindow );
855             break;
856             case WINDOW_OKBUTTON:
857                 pNewWindow = new OKButton( pParent, nWinBits );
858                 *ppNewComp = new VCLXButton;
859             break;
860             case WINDOW_PATTERNBOX:
861                 pNewWindow = new PatternBox( pParent, nWinBits );
862             break;
863             case WINDOW_PATTERNFIELD:
864                 pNewWindow = new PatternField( pParent, nWinBits );
865                 *ppNewComp = new VCLXPatternField;
866                 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(PatternField*)pNewWindow );
867             break;
868             case WINDOW_PUSHBUTTON:
869                 pNewWindow = new PushButton( pParent, nWinBits );
870                 *ppNewComp = new VCLXButton;
871             break;
872             case WINDOW_QUERYBOX:
873                 pNewWindow = new QueryBox( pParent, nWinBits, String() );
874                 *ppNewComp = new VCLXMessageBox;
875             break;
876             case WINDOW_RADIOBUTTON:
877                 pNewWindow = new RadioButton( pParent, nWinBits );
878                 *ppNewComp = new VCLXRadioButton;
879 
880                 // by default, disable RadioCheck
881                 // Since the VCLXRadioButton really cares for it's RadioCheck settings, this is important:
882                 // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState
883                 // This leads to a strange behaviour if the control is newly created: when settings the initial
884                 // state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck
885                 // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls
886                 // is not really valid: the controls are grouped after they have been created, but we're still in
887                 // the creation process, so the RadioButton::Check relies on invalid grouping information.
888                 // 07.08.2001 - #87254# - frank.schoenheit@sun.com
889                 static_cast<RadioButton*>(pNewWindow)->EnableRadioCheck( sal_False );
890             break;
891             case WINDOW_SCROLLBAR:
892                 pNewWindow = new ScrollBar( pParent, nWinBits );
893                 *ppNewComp = new VCLXScrollBar;
894             break;
895             case WINDOW_SCROLLBARBOX:
896                 pNewWindow = new ScrollBarBox( pParent, nWinBits );
897             break;
898             case WINDOW_SPINBUTTON:
899                 pNewWindow = new SpinButton( pParent, nWinBits );
900                 *ppNewComp = new ::toolkit::VCLXSpinButton;
901             break;
902             case WINDOW_SPINFIELD:
903                 pNewWindow = new SpinField( pParent, nWinBits );
904                 *ppNewComp = new VCLXNumericField;
905             break;
906             case WINDOW_SPLITTER:
907                 pNewWindow = new Splitter( pParent, nWinBits );
908             break;
909             case WINDOW_SPLITWINDOW:
910                 pNewWindow = new SplitWindow( pParent, nWinBits );
911             break;
912             case WINDOW_STATUSBAR:
913                 pNewWindow = new StatusBar( pParent, nWinBits );
914             break;
915             case VCLWINDOW_SYSTEMCHILDWINDOW:
916                 pNewWindow = new SystemChildWindow( pParent, nWinBits );
917                 *ppNewComp = new VCLXSystemDependentWindow();
918             break;
919             case WINDOW_TABCONTROL:
920                 pNewWindow = new TabControl( pParent, nWinBits );
921                 *ppNewComp = new VCLXTabPageContainer;
922             break;
923             case WINDOW_TABDIALOG:
924                 pNewWindow = new TabDialog( pParent, nWinBits );
925             break;
926             case WINDOW_TABPAGE:
927                 /*
928                 if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase(
929                         ::rtl::OUString::createFromAscii("tabpagemodel") ) )
930                 {
931                     pNewWindow = new TabControl( pParent, nWinBits );
932                     *ppNewComp = new VCLXTabPageContainer;
933                 }
934                 else
935                 */
936                 {
937                     pNewWindow = new TabPage( pParent, nWinBits );
938                     *ppNewComp = new VCLXTabPage;
939                 }
940             break;
941             case WINDOW_TIMEBOX:
942                 pNewWindow = new TimeBox( pParent, nWinBits );
943             break;
944             case WINDOW_TIMEFIELD:
945                 pNewWindow = new TimeField( pParent, nWinBits );
946                 static_cast<TimeField*>(pNewWindow)->EnableEmptyFieldValue( sal_True );
947                 *ppNewComp = new VCLXTimeField;
948                 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(TimeField*)pNewWindow );
949             break;
950             case WINDOW_TOOLBOX:
951                 pNewWindow = new ToolBox( pParent, nWinBits );
952                 *ppNewComp = new VCLXToolBox;
953             break;
954             case WINDOW_TRISTATEBOX:
955                 pNewWindow = new TriStateBox( pParent, nWinBits );
956             break;
957             case WINDOW_WARNINGBOX:
958                 pNewWindow = new WarningBox( pParent, nWinBits, String() );
959                 *ppNewComp = new VCLXMessageBox;
960             break;
961             case WINDOW_WORKWINDOW:
962             case WINDOW_WINDOW:
963             case VCLWINDOW_FRAMEWINDOW:
964             case WINDOW_DOCKINGWINDOW:
965                 if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP )
966                 {
967                     if (nType == WINDOW_DOCKINGWINDOW )
968                         pNewWindow = new DockingWindow( pParent, nWinBits );
969                     else
970                     {
971                         if ((pParent == NULL) && rDescriptor.Parent.is())
972                         {
973                             // try to get a system dependent window handle
974                             ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, ::com::sun::star::uno::UNO_QUERY);
975 
976                             if (xSystemDepParent.is())
977                             {
978                                 sal_Int8 processID[16];
979 
980                                 rtl_getGlobalProcessId( (sal_uInt8*)processID );
981 
982                                 ::com::sun::star::uno::Sequence<sal_Int8> processIdSeq(processID, 16);
983 
984                                 ::com::sun::star::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPE);
985 
986                                 // use sal_Int64 here to accomodate all int types
987                                 // uno::Any shift operator whill upcast if necessary
988                                 sal_Int64 nWindowHandle = 0;
989                                 sal_Bool bXEmbed = sal_False;
990 
991                                 bool bUseParentData = true;
992                                 if( ! (anyHandle >>= nWindowHandle) )
993                                 {
994                                     css::uno::Sequence< css::beans::NamedValue > aProps;
995                                     if( anyHandle >>= aProps )
996                                     {
997                                         const int nProps = aProps.getLength();
998                                         const css::beans::NamedValue* pProps = aProps.getConstArray();
999                                         for( int i = 0; i < nProps; i++ )
1000                                         {
1001                                             if( pProps[i].Name.equalsAscii( "WINDOW" ) )
1002                                                 pProps[i].Value >>= nWindowHandle;
1003                                             else if( pProps[i].Name.equalsAscii( "XEMBED" ) )
1004                                                 pProps[i].Value >>= bXEmbed;
1005                                         }
1006                                     }
1007                                     else
1008                                         bUseParentData = false;
1009                                 }
1010 
1011                                 if( bUseParentData )
1012                                 {
1013                                     SystemParentData aParentData;
1014                                     aParentData.nSize   = sizeof( aParentData );
1015                                     #if defined QUARTZ
1016                                     aParentData.pView   = reinterpret_cast<NSView*>(nWindowHandle);
1017                                     #elif defined UNX
1018                                     aParentData.aWindow = nWindowHandle;
1019                                     aParentData.bXEmbedSupport = bXEmbed;
1020                                     #elif defined WNT
1021                                     aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1022                                     #elif defined OS2
1023                                     aParentData.hWnd = (HWND)nWindowHandle;
1024                                     #endif
1025                                     pNewWindow = new WorkWindow( &aParentData );
1026                                 }
1027                             }
1028                         }
1029 
1030                         if (!pNewWindow)
1031                             pNewWindow = new WorkWindow( pParent, nWinBits );
1032                     }
1033 
1034                     *ppNewComp = new VCLXTopWindow( pNewWindow->GetType() == WINDOW_WORKWINDOW );
1035                 }
1036                 else if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_CONTAINER )
1037                 {
1038                     if (nType == WINDOW_DOCKINGWINDOW )
1039                         pNewWindow = new DockingWindow( pParent, nWinBits );
1040                     else
1041                         pNewWindow = new Window( pParent, nWinBits );
1042                     *ppNewComp = new VCLXContainer;
1043                 }
1044                 else
1045                 {
1046                     if (nType == WINDOW_DOCKINGWINDOW )
1047                         pNewWindow = new DockingWindow( pParent, nWinBits );
1048                     else
1049                         pNewWindow = new Window( pParent, nWinBits );
1050                     *ppNewComp = new VCLXWindow;
1051                 }
1052             break;
1053             case WINDOW_CONTROL:
1054                 if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase(
1055                         ::rtl::OUString::createFromAscii("tabpagecontainer") ) )
1056                 {
1057                     pNewWindow = new TabControl( pParent, nWinBits );
1058                     *ppNewComp = new VCLXTabPageContainer;
1059                 }
1060                 else if ( aServiceName.EqualsAscii( "animatedimages" ) )
1061                 {
1062                     pNewWindow = new Throbber( pParent, nWinBits );
1063                     *ppNewComp = new ::toolkit::AnimatedImagesPeer;
1064                 }
1065             break;
1066             default:
1067                 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" );
1068                 break;
1069         }
1070     }
1071 
1072     return pNewWindow;
1073 }
1074 
1075 extern "C" { static void SAL_CALL thisModule() {} }
1076 
1077 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow(
1078     const css::awt::WindowDescriptor& rDescriptor,
1079     WinBits nForceWinBits )
1080 {
1081     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1082 
1083     osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() );
1084 
1085     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef;
1086 
1087     Window* pParent = NULL;
1088     if ( rDescriptor.Parent.is() )
1089     {
1090         VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( rDescriptor.Parent );
1091 
1092         // #103939# Don't through assertion, may be it's a system dependend window, used in ImplCreateWindow.
1093         // DBG_ASSERT( pParentComponent, "ParentComponent not valid" );
1094 
1095         if ( pParentComponent )
1096             pParent = pParentComponent->GetWindow();
1097     }
1098 
1099     WinBits nWinBits = ImplGetWinBits( rDescriptor.WindowAttributes,
1100         ImplGetComponentType( rDescriptor.WindowServiceName ) );
1101     nWinBits |= nForceWinBits;
1102 
1103     VCLXWindow* pNewComp = NULL;
1104 
1105     Window* pNewWindow = NULL;
1106     // Try to create the window with SvTools
1107     // (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way,
1108     // and we need to stay compatible)
1109     // try to load the lib
1110     if ( !fnSvtCreateWindow && !hSvToolsLib )
1111     {
1112         ::rtl::OUString aLibName = ::vcl::unohelper::CreateLibraryName( "svt", sal_True );
1113         hSvToolsLib = osl_loadModuleRelative(
1114             &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT );
1115         if ( hSvToolsLib )
1116         {
1117             ::rtl::OUString aFunctionName( RTL_CONSTASCII_USTRINGPARAM( "CreateWindow" ) );
1118             fnSvtCreateWindow = (FN_SvtCreateWindow)osl_getFunctionSymbol( hSvToolsLib, aFunctionName.pData );
1119         }
1120     }
1121     // ask the SvTool creation function
1122     if ( fnSvtCreateWindow )
1123         pNewWindow = fnSvtCreateWindow( &pNewComp, &rDescriptor, pParent, nWinBits );
1124 
1125     // if SvTools could not provide a window, create it ourself
1126     if ( !pNewWindow )
1127         pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits );
1128 
1129     DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" );
1130     DBG_ASSERTWARNING( pNewComp, "createWindow: No special Interface!" );
1131 
1132     if ( pNewWindow )
1133     {
1134         pNewWindow->SetCreatedWithToolkit( sal_True );
1135         //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead
1136 
1137         if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::MINSIZE )
1138         {
1139             pNewWindow->SetSizePixel( Size() );
1140         }
1141         else if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::FULLSIZE )
1142         {
1143             if ( pParent )
1144                 pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() );
1145         }
1146         else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) )
1147         {
1148             Rectangle aRect = VCLRectangle( rDescriptor.Bounds );
1149             pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
1150         }
1151 
1152         if ( !pNewComp )
1153         {
1154             // Default-Interface
1155             xRef = pNewWindow->GetComponentInterface( sal_True );
1156         }
1157         else
1158         {
1159             pNewComp->SetCreatedWithToolkit( sal_True );
1160             xRef = pNewComp;
1161             pNewWindow->SetComponentInterface( xRef );
1162         }
1163         DBG_ASSERT( pNewWindow->GetComponentInterface( sal_False ) == xRef,
1164             "VCLXToolkit::createWindow: did #133706# resurge?" );
1165 
1166         if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::SHOW )
1167             pNewWindow->Show();
1168     }
1169 
1170     return xRef;
1171 }
1172 
1173 ::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)
1174 {
1175     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1176 
1177     sal_uInt32 nComponents = rDescriptors.getLength();
1178     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > > aSeq( nComponents );
1179     for ( sal_uInt32 n = 0; n < nComponents; n++ )
1180     {
1181         ::com::sun::star::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n];
1182 
1183         if ( aDescr.ParentIndex == (-1) )
1184             aDescr.Parent = NULL;
1185         else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < (short)n ) )
1186             aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex];
1187         aSeq.getArray()[n] = createWindow( aDescr );
1188     }
1189     return aSeq;
1190 }
1191 
1192 // ::com::sun::star::awt::XSystemChildFactory
1193 ::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)
1194 {
1195     Window* pChildWindow = NULL;
1196     if ( nSystemType == SYSTEM_DEPENDENT_TYPE )
1197     {
1198         // use sal_Int64 here to accomodate all int types
1199         // uno::Any shift operator whill upcast if necessary
1200         sal_Int64 nWindowHandle = 0;
1201         sal_Bool bXEmbed = sal_False;
1202 
1203         bool bUseParentData = true;
1204         if( ! (Parent >>= nWindowHandle) )
1205         {
1206             css::uno::Sequence< css::beans::NamedValue > aProps;
1207             if( Parent >>= aProps )
1208             {
1209                 const int nProps = aProps.getLength();
1210                 const css::beans::NamedValue* pProps = aProps.getConstArray();
1211                 for( int i = 0; i < nProps; i++ )
1212                 {
1213                     if( pProps[i].Name.equalsAscii( "WINDOW" ) )
1214                         pProps[i].Value >>= nWindowHandle;
1215                     else if( pProps[i].Name.equalsAscii( "XEMBED" ) )
1216                         pProps[i].Value >>= bXEmbed;
1217                 }
1218             }
1219             else
1220                 bUseParentData = false;
1221         }
1222 
1223         if( bUseParentData )
1224         {
1225             SystemParentData aParentData;
1226             aParentData.nSize   = sizeof( aParentData );
1227             #if defined QUARTZ
1228             aParentData.pView   = reinterpret_cast<NSView*>(nWindowHandle);
1229             #elif defined UNX
1230             aParentData.aWindow = nWindowHandle;
1231             aParentData.bXEmbedSupport = bXEmbed;
1232             #elif defined WNT
1233             aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1234             #elif defined OS2
1235             aParentData.hWnd = (HWND)nWindowHandle;
1236             #endif
1237             osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() );
1238             try
1239             {
1240                 pChildWindow = new WorkWindow( &aParentData );
1241             }
1242             catch ( ::com::sun::star::uno::RuntimeException & rEx )
1243             {
1244                 // system child window could not be created
1245                 OSL_TRACE(
1246                     "VCLXToolkit::createSystemChild: caught %s\n",
1247                     ::rtl::OUStringToOString(
1248                         rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1249                 pChildWindow = NULL;
1250             }
1251         }
1252     }
1253     else if (nSystemType == com::sun::star::lang::SystemDependent::SYSTEM_JAVA)
1254     {
1255         osl::Guard< vos::IMutex > aGuard(Application::GetSolarMutex());
1256         pChildWindow = new WorkWindow(0, Parent);
1257     }
1258 
1259     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xPeer;
1260     if ( pChildWindow )
1261     {
1262         VCLXTopWindow* pPeer = new VCLXTopWindow(true);
1263         osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() );
1264         pPeer->SetWindow( pChildWindow );
1265         xPeer = pPeer;
1266     }
1267 
1268     return xPeer;
1269 }
1270 
1271 // ::com::sun::star::awt::XMessageBoxFactory
1272 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox(
1273     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& aParent,
1274     ::com::sun::star::awt::MessageBoxType eType,
1275     ::sal_Int32 aButtons,
1276     const ::rtl::OUString& aTitle,
1277     const ::rtl::OUString& aMessage ) throw (::com::sun::star::uno::RuntimeException)
1278 {
1279     ::com::sun::star::awt::WindowDescriptor aDescriptor;
1280 
1281     sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE;
1282 
1283     // Map button definitions to window attributes
1284     if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK )
1285         nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK;
1286     else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL )
1287         nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL;
1288     else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO )
1289         nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO;
1290     else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL )
1291         nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL;
1292     else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL )
1293         nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL;
1294 
1295     // Map default button definitions to window attributes
1296     if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK )
1297         nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK;
1298     else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL )
1299         nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL;
1300     else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES )
1301         nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES;
1302     else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO )
1303         nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO;
1304     else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY )
1305         nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY;
1306 
1307     // No more bits for VclWindowPeerAttribute possible. Mapping must be
1308     // done explicitly using VCL methods
1309     WinBits nAddWinBits( 0 );
1310     if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY )
1311         nAddWinBits |= WB_ABORT_RETRY_IGNORE;
1312     if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE )
1313         nAddWinBits |= WB_DEF_IGNORE;
1314 
1315     rtl::OUString aType;
1316     lcl_convertMessageBoxType( aType, eType );
1317 
1318     aDescriptor.Type              = css::awt::WindowClass_MODALTOP;
1319     aDescriptor.WindowServiceName = aType;
1320     aDescriptor.ParentIndex       = -1;
1321     aDescriptor.Parent            = aParent;
1322     aDescriptor.WindowAttributes  = nWindowAttributes;
1323     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > xMsgBox(
1324         ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY );
1325     css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY );
1326     if ( xMsgBox.is() && xWindow.is() )
1327     {
1328         Window * pWindow = VCLUnoHelper::GetWindow( xWindow );
1329         if ( pWindow )
1330         {
1331             osl::Guard< vos::IMutex > aGuard(Application::GetSolarMutex());
1332             xMsgBox->setCaptionText( aTitle );
1333             xMsgBox->setMessageText( aMessage );
1334         }
1335     }
1336 
1337     return xMsgBox;
1338 }
1339 
1340 ::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)
1341 {
1342     Window * pWindow = VCLUnoHelper::GetWindow( window );
1343 
1344     if( pWindow )
1345         return pWindow->GetDragGestureRecognizer();
1346 
1347     return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer >();
1348 }
1349 
1350 ::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)
1351 {
1352     Window * pWindow = VCLUnoHelper::GetWindow( window );
1353 
1354     if( pWindow )
1355         return pWindow->GetDragSource();
1356 
1357     return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource >();
1358 }
1359 
1360 ::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)
1361 {
1362     Window * pWindow = VCLUnoHelper::GetWindow( window );
1363 
1364     if( pWindow )
1365         return pWindow->GetDropTarget();
1366 
1367     return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTarget >();
1368 }
1369 
1370 ::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)
1371 {
1372     if( clipboardName.getLength() == 0 )
1373     {
1374         if( !mxClipboard.is() )
1375         {
1376             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
1377             if ( xFactory.is() )
1378             {
1379                 // remember clipboard here
1380                 mxClipboard = ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > (
1381                     xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.SystemClipboard" ) ), ::com::sun::star::uno::UNO_QUERY );
1382             }
1383         }
1384 
1385         return mxClipboard;
1386     }
1387 
1388     else if( clipboardName.equals( ::rtl::OUString::createFromAscii("Selection") ) )
1389     {
1390         return mxSelection;
1391     }
1392 
1393     return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >();
1394 }
1395 
1396 // XServiceInfo
1397 ::rtl::OUString VCLXToolkit::getImplementationName() throw(::com::sun::star::uno::RuntimeException)
1398 {
1399     return rtl::OUString::createFromAscii( "stardiv.Toolkit.VCLXToolkit" );
1400 }
1401 
1402 sal_Bool VCLXToolkit::supportsService( const ::rtl::OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException)
1403 {
1404     ::osl::MutexGuard aGuard( GetMutex() );
1405 
1406     ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
1407     const ::rtl::OUString* pArray = aSNL.getConstArray();
1408     const ::rtl::OUString* pArrayEnd = aSNL.getConstArray();
1409     for (; pArray != pArrayEnd; ++pArray )
1410         if( *pArray == rServiceName )
1411             break;
1412 
1413     return pArray != pArrayEnd;
1414 }
1415 
1416 ::com::sun::star::uno::Sequence< ::rtl::OUString > VCLXToolkit::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException)
1417 {
1418     ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( szServiceName2_Toolkit ) );
1419     return ::com::sun::star::uno::Sequence< ::rtl::OUString >( &aServiceName, 1);
1420 }
1421 
1422 // css::awt::XExtendedToolkit:
1423 
1424 // virtual
1425 ::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount()
1426     throw (::css::uno::RuntimeException)
1427 {
1428     return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount());
1429         // XXX  numeric overflow
1430 }
1431 
1432 // virtual
1433 ::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL
1434 VCLXToolkit::getTopWindow(::sal_Int32 nIndex)
1435     throw (::css::uno::RuntimeException)
1436 {
1437     ::Window * p = ::Application::GetTopWindow(static_cast< long >(nIndex));
1438         // XXX  numeric overflow
1439     return ::css::uno::Reference< ::css::awt::XTopWindow >(
1440         p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()),
1441         ::css::uno::UNO_QUERY);
1442 }
1443 
1444 // virtual
1445 ::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL
1446 VCLXToolkit::getActiveTopWindow() throw (::css::uno::RuntimeException)
1447 {
1448     ::Window * p = ::Application::GetActiveTopWindow();
1449     return ::css::uno::Reference< ::css::awt::XTopWindow >(
1450         p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()),
1451         ::css::uno::UNO_QUERY);
1452 }
1453 
1454 // virtual
1455 void SAL_CALL VCLXToolkit::addTopWindowListener(
1456     ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener)
1457     throw (::css::uno::RuntimeException)
1458 {
1459     OSL_ENSURE(rListener.is(), "Null rListener");
1460     ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1461     if (rBHelper.bDisposed || rBHelper.bInDispose)
1462     {
1463         aGuard.clear();
1464         rListener->disposing(
1465             ::css::lang::EventObject(
1466                 static_cast< ::cppu::OWeakObject * >(this)));
1467     }
1468     else if (m_aTopWindowListeners.addInterface(rListener) == 1
1469              && !m_bEventListener)
1470     {
1471         m_bEventListener = true;
1472         ::Application::AddEventListener(m_aEventListenerLink);
1473     }
1474 }
1475 
1476 // virtual
1477 void SAL_CALL VCLXToolkit::removeTopWindowListener(
1478     ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener)
1479     throw (::css::uno::RuntimeException)
1480 {
1481     ::osl::MutexGuard aGuard(rBHelper.rMutex);
1482     if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1483         && m_aTopWindowListeners.removeInterface(rListener) == 0
1484         && m_aFocusListeners.getLength() == 0 && m_bEventListener)
1485     {
1486         ::Application::RemoveEventListener(m_aEventListenerLink);
1487         m_bEventListener = false;
1488     }
1489 }
1490 
1491 // virtual
1492 void SAL_CALL VCLXToolkit::addKeyHandler(
1493     ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler)
1494     throw (::css::uno::RuntimeException)
1495 {
1496     OSL_ENSURE(rHandler.is(), "Null rHandler");
1497     ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1498     if (rBHelper.bDisposed || rBHelper.bInDispose)
1499     {
1500         aGuard.clear();
1501         rHandler->disposing(
1502             ::css::lang::EventObject(
1503                 static_cast< ::cppu::OWeakObject * >(this)));
1504     }
1505     else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener)
1506     {
1507         m_bKeyListener = true;
1508         ::Application::AddKeyListener(m_aKeyListenerLink);
1509     }
1510 }
1511 
1512 // virtual
1513 void SAL_CALL VCLXToolkit::removeKeyHandler(
1514     ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler)
1515     throw (::css::uno::RuntimeException)
1516 {
1517     ::osl::MutexGuard aGuard(rBHelper.rMutex);
1518     if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1519         && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener)
1520     {
1521         ::Application::RemoveKeyListener(m_aKeyListenerLink);
1522         m_bKeyListener = false;
1523     }
1524 }
1525 
1526 // virtual
1527 void SAL_CALL VCLXToolkit::addFocusListener(
1528     ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener)
1529     throw (::css::uno::RuntimeException)
1530 {
1531     OSL_ENSURE(rListener.is(), "Null rListener");
1532     ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1533     if (rBHelper.bDisposed || rBHelper.bInDispose)
1534     {
1535         aGuard.clear();
1536         rListener->disposing(
1537             ::css::lang::EventObject(
1538                 static_cast< ::cppu::OWeakObject * >(this)));
1539     }
1540     else if (m_aFocusListeners.addInterface(rListener) == 1
1541              && !m_bEventListener)
1542     {
1543         m_bEventListener = true;
1544         ::Application::AddEventListener(m_aEventListenerLink);
1545     }
1546 }
1547 
1548 // virtual
1549 void SAL_CALL VCLXToolkit::removeFocusListener(
1550     ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener)
1551     throw (::css::uno::RuntimeException)
1552 {
1553     ::osl::MutexGuard aGuard(rBHelper.rMutex);
1554     if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1555         && m_aFocusListeners.removeInterface(rListener) == 0
1556         && m_aTopWindowListeners.getLength() == 0 && m_bEventListener)
1557     {
1558         ::Application::RemoveEventListener(m_aEventListenerLink);
1559         m_bEventListener = false;
1560     }
1561 }
1562 
1563 // virtual
1564 void SAL_CALL VCLXToolkit::fireFocusGained(
1565     ::com::sun::star::uno::Reference<
1566     ::com::sun::star::uno::XInterface > const &)
1567     throw (::com::sun::star::uno::RuntimeException)
1568 {
1569 }
1570 
1571 // virtual
1572 void SAL_CALL VCLXToolkit::fireFocusLost(
1573     ::com::sun::star::uno::Reference<
1574     ::com::sun::star::uno::XInterface > const &)
1575     throw (::com::sun::star::uno::RuntimeException)
1576 {
1577 }
1578 
1579 
1580 IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent const *, pEvent)
1581 {
1582     switch (pEvent->GetId())
1583     {
1584     case VCLEVENT_WINDOW_SHOW:
1585         callTopWindowListeners(
1586             pEvent, &::css::awt::XTopWindowListener::windowOpened);
1587         break;
1588     case VCLEVENT_WINDOW_HIDE:
1589         callTopWindowListeners(
1590             pEvent, &::css::awt::XTopWindowListener::windowClosed);
1591         break;
1592     case VCLEVENT_WINDOW_ACTIVATE:
1593         callTopWindowListeners(
1594             pEvent, &::css::awt::XTopWindowListener::windowActivated);
1595         break;
1596     case VCLEVENT_WINDOW_DEACTIVATE:
1597         callTopWindowListeners(
1598             pEvent, &::css::awt::XTopWindowListener::windowDeactivated);
1599         break;
1600     case VCLEVENT_WINDOW_CLOSE:
1601         callTopWindowListeners(
1602             pEvent, &::css::awt::XTopWindowListener::windowClosing);
1603         break;
1604     case VCLEVENT_WINDOW_GETFOCUS:
1605         callFocusListeners(pEvent, true);
1606         break;
1607     case VCLEVENT_WINDOW_LOSEFOCUS:
1608         callFocusListeners(pEvent, false);
1609         break;
1610     case VCLEVENT_WINDOW_MINIMIZE:
1611         callTopWindowListeners(
1612             pEvent, &::css::awt::XTopWindowListener::windowMinimized);
1613         break;
1614     case VCLEVENT_WINDOW_NORMALIZE:
1615         callTopWindowListeners(
1616             pEvent, &::css::awt::XTopWindowListener::windowNormalized);
1617         break;
1618     }
1619     return 0;
1620 }
1621 
1622 IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclSimpleEvent const *, pEvent)
1623 {
1624     switch (pEvent->GetId())
1625     {
1626     case VCLEVENT_WINDOW_KEYINPUT:
1627         return callKeyHandlers(pEvent, true);
1628     case VCLEVENT_WINDOW_KEYUP:
1629         return callKeyHandlers(pEvent, false);
1630     }
1631     return 0;
1632 }
1633 
1634 void VCLXToolkit::callTopWindowListeners(
1635     ::VclSimpleEvent const * pEvent,
1636     void (SAL_CALL ::css::awt::XTopWindowListener::* pFn)(
1637         ::css::lang::EventObject const &))
1638 {
1639     ::Window * pWindow
1640           = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1641     if (pWindow->IsTopWindow())
1642     {
1643         ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
1644               aListeners(m_aTopWindowListeners.getElements());
1645         if (aListeners.hasElements())
1646         {
1647             ::css::lang::EventObject aAwtEvent(
1648                 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()));
1649             for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i)
1650             {
1651                 ::css::uno::Reference< ::css::awt::XTopWindowListener >
1652                       xListener(aListeners[i], ::css::uno::UNO_QUERY);
1653                 try
1654                 {
1655                     (xListener.get()->*pFn)(aAwtEvent);
1656                 }
1657                 catch (::css::uno::RuntimeException & rEx)
1658                 {
1659                     OSL_TRACE(
1660                         "VCLXToolkit::callTopWindowListeners: caught %s\n",
1661                         ::rtl::OUStringToOString(
1662                             rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1663                 }
1664             }
1665         }
1666     }
1667 }
1668 
1669 long VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent,
1670                                   bool bPressed)
1671 {
1672     ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
1673           aHandlers(m_aKeyHandlers.getElements());
1674 
1675     if (aHandlers.hasElements())
1676     {
1677         ::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1678 
1679         // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event
1680         ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >(
1681             static_cast< ::VclWindowEvent const * >(pEvent)->GetData());
1682         ::css::awt::KeyEvent aAwtEvent(
1683             static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()),
1684             (pKeyEvent->GetKeyCode().IsShift()
1685              ? ::css::awt::KeyModifier::SHIFT : 0)
1686             | (pKeyEvent->GetKeyCode().IsMod1()
1687                ? ::css::awt::KeyModifier::MOD1 : 0)
1688             | (pKeyEvent->GetKeyCode().IsMod2()
1689                ? ::css::awt::KeyModifier::MOD2 : 0)
1690             | (pKeyEvent->GetKeyCode().IsMod3()
1691                ? ::css::awt::KeyModifier::MOD3 : 0),
1692             pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(),
1693             sal::static_int_cast< sal_Int16 >(
1694                 pKeyEvent->GetKeyCode().GetFunction()));
1695         for (::sal_Int32 i = 0; i < aHandlers.getLength(); ++i)
1696         {
1697             ::css::uno::Reference< ::css::awt::XKeyHandler > xHandler(
1698                 aHandlers[i], ::css::uno::UNO_QUERY);
1699             try
1700             {
1701                 if ((bPressed ? xHandler->keyPressed(aAwtEvent)
1702                       : xHandler->keyReleased(aAwtEvent)))
1703                     return 1;
1704             }
1705             catch (::css::uno::RuntimeException & rEx)
1706             {
1707                 OSL_TRACE(
1708                     "VCLXToolkit::callKeyHandlers: caught %s\n",
1709                     ::rtl::OUStringToOString(
1710                        rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1711             }
1712         }
1713     }
1714     return 0;
1715 }
1716 
1717 void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent,
1718                                      bool bGained)
1719 {
1720     ::Window * pWindow
1721           = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
1722     if (pWindow->IsTopWindow())
1723     {
1724         ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
1725               aListeners(m_aFocusListeners.getElements());
1726         if (aListeners.hasElements())
1727         {
1728             // Ignore the interior of compound controls when determining the
1729             // window that gets the focus next (see implementation in
1730             // vclxwindow.cxx for mapping between VCL and UNO AWT event):
1731             ::css::uno::Reference< css::uno::XInterface > xNext;
1732             ::Window * pFocus = ::Application::GetFocusWindow();
1733             for (::Window * p = pFocus; p != 0; p = p->GetParent())
1734                 if (!p->IsCompoundControl())
1735                 {
1736                     pFocus = p;
1737                     break;
1738                 }
1739             if (pFocus != 0)
1740                 xNext = pFocus->GetComponentInterface(true);
1741             ::css::awt::FocusEvent aAwtEvent(
1742                 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()),
1743                 pWindow->GetGetFocusFlags(), xNext, false);
1744             for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i)
1745             {
1746                 ::css::uno::Reference< ::css::awt::XFocusListener > xListener(
1747                     aListeners[i], ::css::uno::UNO_QUERY);
1748                 try
1749                 {
1750                     bGained ? xListener->focusGained(aAwtEvent)
1751                         : xListener->focusLost(aAwtEvent);
1752                 }
1753                 catch (::css::uno::RuntimeException & rEx)
1754                 {
1755                     OSL_TRACE(
1756                         "VCLXToolkit::callFocusListeners: caught %s\n",
1757                         ::rtl::OUStringToOString(
1758                             rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
1759                 }
1760             }
1761         }
1762     }
1763 }
1764 
1765 // css::awt::XReschedule:
1766 
1767 void SAL_CALL VCLXToolkit::reschedule()
1768     throw (::com::sun::star::uno::RuntimeException)
1769 {
1770     Application::Reschedule(true);
1771 }
1772 
1773