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