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