1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <boost/ptr_container/ptr_vector.hpp>
27 #include <com/sun/star/awt/WindowAttribute.hpp>
28 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
29 #include <com/sun/star/awt/WindowClass.hpp>
30 #include <com/sun/star/awt/MessageBoxButtons.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/lang/SystemDependent.hpp>
33 #include <com/sun/star/awt/FocusEvent.hpp>
34 #include <com/sun/star/awt/KeyEvent.hpp>
35 #include <com/sun/star/awt/KeyModifier.hpp>
36 #include <com/sun/star/lang/EventObject.hpp>
37 #include <com/sun/star/uno/Reference.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
39 #include <com/sun/star/uno/XComponentContext.hpp>
40 #include <com/sun/star/uno/XInterface.hpp>
41 #include <com/sun/star/beans/NamedValue.hpp>
42 #include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <com/sun/star/awt/XToolkitExperimental.hpp>
45 #include <com/sun/star/awt/XMessageBoxFactory.hpp>
47 #include <cppuhelper/bootstrap.hxx>
48 #include <cppuhelper/compbase2.hxx>
49 #include <cppuhelper/interfacecontainer.hxx>
50 #include <cppuhelper/supportsservice.hxx>
51 #include <cppuhelper/typeprovider.hxx>
52 #include <osl/conditn.hxx>
53 #include <osl/module.h>
54 #include <osl/thread.h>
55 #include <osl/mutex.hxx>
57 #include <rtl/process.h>
58 #include <tools/link.hxx>
59 #include <tools/fract.hxx>
60 #include <tools/wintypes.hxx>
64 #include <Cocoa/Cocoa.h>
68 #include <vcl/sysdata.hxx>
70 #include <toolkit/awt/vclxwindows.hxx>
71 #include <toolkit/awt/vclxsystemdependentwindow.hxx>
72 #include <toolkit/awt/vclxregion.hxx>
73 #include <toolkit/awt/vclxtabpagecontainer.hxx>
75 #include <toolkit/awt/animatedimagespeer.hxx>
76 #include <toolkit/awt/vclxtopwindow.hxx>
77 #include <toolkit/awt/vclxwindow.hxx>
78 #include <toolkit/helper/vclunohelper.hxx>
79 #include <toolkit/helper/servicenames.hxx>
81 #include <toolkit/helper/macros.hxx>
82 #include <toolkit/helper/convert.hxx>
83 #include <vcl/unohelp.hxx>
84 #include <vcl/button.hxx>
85 #include <vcl/combobox.hxx>
86 #include <vcl/ctrl.hxx>
87 #include <vcl/dialog.hxx>
88 #include <vcl/dockingarea.hxx>
89 #include <vcl/dockwin.hxx>
90 #include <vcl/edit.hxx>
91 #include <vcl/field.hxx>
92 #include <vcl/fixed.hxx>
93 #include <vcl/floatwin.hxx>
94 #include <vcl/group.hxx>
95 #include <vcl/scheduler.hxx>
96 #include <vcl/imgctrl.hxx>
97 #include <vcl/longcurr.hxx>
98 #include <vcl/lstbox.hxx>
99 #include <vcl/menubtn.hxx>
100 #include <vcl/morebtn.hxx>
101 #include <vcl/msgbox.hxx>
102 #include <vcl/scrbar.hxx>
103 #include <vcl/spin.hxx>
104 #include <vcl/split.hxx>
105 #include <vcl/splitwin.hxx>
106 #include <vcl/status.hxx>
107 #include <vcl/svapp.hxx>
108 #include <vcl/syschild.hxx>
109 #include <vcl/tabctrl.hxx>
110 #include <vcl/tabdlg.hxx>
111 #include <vcl/tabpage.hxx>
112 #include <vcl/toolbox.hxx>
113 #include <vcl/virdev.hxx>
114 #include <vcl/window.hxx>
115 #include <vcl/wrkwin.hxx>
116 #include <vcl/throbber.hxx>
117 #include "toolkit/awt/vclxspinbutton.hxx"
118 #include <tools/debug.hxx>
119 #include <comphelper/processfactory.hxx>
120 #include <toolkit/awt/scrollabledialog.hxx>
122 #include "helper/unowrapper.hxx"
124 #define VCLWINDOW_FRAMEWINDOW 0x1000
125 #define VCLWINDOW_SYSTEMCHILDWINDOW 0x1001
128 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32
129 #elif (defined MACOSX)
130 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_MAC
132 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW
137 extern "C" typedef vcl::Window
* (SAL_CALL
*FN_SvtCreateWindow
)(
138 VCLXWindow
** ppNewComp
,
139 const css::awt::WindowDescriptor
* pDescriptor
,
140 vcl::Window
* pParent
,
143 class VCLXToolkit_Impl
146 ::osl::Mutex maMutex
;
149 class VCLXToolkit
: public VCLXToolkit_Impl
,
150 public cppu::WeakComponentImplHelper2
<
151 css::awt::XToolkitExperimental
,
152 css::lang::XServiceInfo
>
154 css::uno::Reference
< css::datatransfer::clipboard::XClipboard
> mxClipboard
;
155 css::uno::Reference
< css::datatransfer::clipboard::XClipboard
> mxSelection
;
157 oslModule hSvToolsLib
;
158 FN_SvtCreateWindow fnSvtCreateWindow
;
160 ::cppu::OInterfaceContainerHelper m_aTopWindowListeners
;
161 ::cppu::OInterfaceContainerHelper m_aKeyHandlers
;
162 ::cppu::OInterfaceContainerHelper m_aFocusListeners
;
163 ::Link
<> m_aEventListenerLink
;
164 ::Link
<> m_aKeyListenerLink
;
165 bool m_bEventListener
;
168 DECL_LINK(eventListenerHandler
, ::VclSimpleEvent
const *);
170 DECL_LINK(keyListenerHandler
, ::VclSimpleEvent
const *);
172 void callTopWindowListeners(
173 ::VclSimpleEvent
const * pEvent
,
174 void (SAL_CALL
css::awt::XTopWindowListener::* pFn
)(
175 css::lang::EventObject
const &));
177 long callKeyHandlers(::VclSimpleEvent
const * pEvent
, bool bPressed
);
179 void callFocusListeners(::VclSimpleEvent
const * pEvent
, bool bGained
);
182 ::osl::Mutex
& GetMutex() { return maMutex
; }
184 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
186 static vcl::Window
* ImplCreateWindow( VCLXWindow
** ppNewComp
, const css::awt::WindowDescriptor
& rDescriptor
, vcl::Window
* pParent
, WinBits nWinBits
);
187 css::uno::Reference
< css::awt::XWindowPeer
> ImplCreateWindow( const css::awt::WindowDescriptor
& Descriptor
, WinBits nWinBits
);
192 virtual ~VCLXToolkit();
194 // css::awt::XToolkitExperimental
195 virtual void SAL_CALL
processEventsToIdle()
196 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
198 // css::awt::XToolkit
199 css::uno::Reference
< css::awt::XWindowPeer
> SAL_CALL
getDesktopWindow( ) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
200 css::awt::Rectangle SAL_CALL
getWorkArea( ) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
201 css::uno::Reference
< css::awt::XWindowPeer
> SAL_CALL
createWindow( const css::awt::WindowDescriptor
& Descriptor
) throw(css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
202 css::uno::Sequence
< css::uno::Reference
< css::awt::XWindowPeer
> > SAL_CALL
createWindows( const css::uno::Sequence
< css::awt::WindowDescriptor
>& Descriptors
) throw(css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
203 css::uno::Reference
< css::awt::XDevice
> SAL_CALL
createScreenCompatibleDevice( sal_Int32 Width
, sal_Int32 Height
) throw
204 (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
205 css::uno::Reference
< css::awt::XRegion
> SAL_CALL
createRegion( ) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
207 // css::awt::XSystemChildFactory
208 css::uno::Reference
< css::awt::XWindowPeer
> SAL_CALL
createSystemChild( const css::uno::Any
& Parent
, const css::uno::Sequence
< sal_Int8
>& ProcessId
, sal_Int16 SystemType
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
210 // css::awt::XMessageBoxFactory
211 virtual css::uno::Reference
< css::awt::XMessageBox
> SAL_CALL
createMessageBox( const css::uno::Reference
< css::awt::XWindowPeer
>& aParent
, css::awt::MessageBoxType eType
, ::sal_Int32 aButtons
, const OUString
& aTitle
, const OUString
& aMessage
) throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
213 // css::awt::XDataTransfer
214 css::uno::Reference
< css::datatransfer::dnd::XDragGestureRecognizer
> SAL_CALL
getDragGestureRecognizer( const css::uno::Reference
< css::awt::XWindow
>& window
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
215 css::uno::Reference
< css::datatransfer::dnd::XDragSource
> SAL_CALL
getDragSource( const css::uno::Reference
< css::awt::XWindow
>& window
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
216 css::uno::Reference
< css::datatransfer::dnd::XDropTarget
> SAL_CALL
getDropTarget( const css::uno::Reference
< css::awt::XWindow
>& window
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
217 css::uno::Reference
< css::datatransfer::clipboard::XClipboard
> SAL_CALL
getClipboard( const OUString
& clipboardName
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
219 // css::lang::XServiceInfo
220 OUString SAL_CALL
getImplementationName( ) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
221 sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
222 css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
224 // css::awt::XExtendedToolkit:
226 virtual ::sal_Int32 SAL_CALL
getTopWindowCount()
227 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
229 virtual css::uno::Reference
< css::awt::XTopWindow
>
230 SAL_CALL
getTopWindow(::sal_Int32 nIndex
)
231 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
233 virtual css::uno::Reference
< css::awt::XTopWindow
>
234 SAL_CALL
getActiveTopWindow()
235 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
237 virtual void SAL_CALL
addTopWindowListener(
239 css::awt::XTopWindowListener
> const & rListener
)
240 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
242 virtual void SAL_CALL
removeTopWindowListener(
244 css::awt::XTopWindowListener
> const & rListener
)
245 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
247 virtual void SAL_CALL
addKeyHandler(
249 css::awt::XKeyHandler
> const & rHandler
)
250 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
252 virtual void SAL_CALL
removeKeyHandler(
254 css::awt::XKeyHandler
> const & rHandler
)
255 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
257 virtual void SAL_CALL
addFocusListener(
259 css::awt::XFocusListener
> const & rListener
)
260 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
262 virtual void SAL_CALL
removeFocusListener(
264 css::awt::XFocusListener
> const & rListener
)
265 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
267 virtual void SAL_CALL
fireFocusGained(
269 css::uno::XInterface
> const & source
)
270 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
272 virtual void SAL_CALL
fireFocusLost(
274 css::uno::XInterface
> const & source
)
275 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
277 // css::awt::XReschedule:
278 virtual void SAL_CALL
reschedule()
279 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
282 WinBits
ImplGetWinBits( sal_uInt32 nComponentAttribs
, sal_uInt16 nCompType
)
284 WinBits nWinBits
= 0;
286 bool bMessBox
= false;
287 if ( ( nCompType
== WINDOW_INFOBOX
) ||
288 ( nCompType
== WINDOW_MESSBOX
) ||
289 ( nCompType
== WINDOW_QUERYBOX
) ||
290 ( nCompType
== WINDOW_WARNINGBOX
) ||
291 ( nCompType
== WINDOW_ERRORBOX
) )
296 bool bDecoratedWindow
= false;
298 || ( nCompType
== WINDOW_DIALOG
)
299 || ( nCompType
== WINDOW_MODELESSDIALOG
)
300 || ( nCompType
== WINDOW_MODALDIALOG
)
301 || ( nCompType
== WINDOW_SYSTEMDIALOG
)
302 || ( nCompType
== WINDOW_PATHDIALOG
)
303 || ( nCompType
== WINDOW_FILEDIALOG
)
304 || ( nCompType
== WINDOW_PRINTERSETUPDIALOG
)
305 || ( nCompType
== WINDOW_PRINTDIALOG
)
306 || ( nCompType
== WINDOW_COLORDIALOG
)
307 || ( nCompType
== WINDOW_FONTDIALOG
)
308 || ( nCompType
== WINDOW_DOCKINGWINDOW
)
309 || ( nCompType
== WINDOW_TABDIALOG
)
310 || ( nCompType
== WINDOW_BUTTONDIALOG
)
311 || ( nCompType
== WINDOW_SYSTEMCHILDWINDOW
)
314 bDecoratedWindow
= true;
317 if( nComponentAttribs
& ::com::sun::star::awt::WindowAttribute::BORDER
)
318 nWinBits
|= WB_BORDER
;
319 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::NOBORDER
)
320 nWinBits
|= WB_NOBORDER
;
321 if( nComponentAttribs
& ::com::sun::star::awt::WindowAttribute::SIZEABLE
)
322 nWinBits
|= WB_SIZEABLE
;
323 if( nComponentAttribs
& ::com::sun::star::awt::WindowAttribute::MOVEABLE
)
324 nWinBits
|= WB_MOVEABLE
;
325 if( nComponentAttribs
& ::com::sun::star::awt::WindowAttribute::CLOSEABLE
)
326 nWinBits
|= WB_CLOSEABLE
;
327 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::HSCROLL
)
328 nWinBits
|= WB_HSCROLL
;
329 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL
)
330 nWinBits
|= WB_VSCROLL
;
331 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::LEFT
)
333 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::CENTER
)
334 nWinBits
|= WB_CENTER
;
335 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::RIGHT
)
336 nWinBits
|= WB_RIGHT
;
337 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::SPIN
)
339 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::SORT
)
341 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::DROPDOWN
)
342 nWinBits
|= WB_DROPDOWN
;
343 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::DEFBUTTON
)
344 nWinBits
|= WB_DEFBUTTON
;
345 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::READONLY
)
346 nWinBits
|= WB_READONLY
;
347 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::CLIPCHILDREN
)
348 nWinBits
|= WB_CLIPCHILDREN
;
349 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::GROUP
)
350 nWinBits
|= WB_GROUP
;
351 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::NOLABEL
) //added for issue79712
352 nWinBits
|= WB_NOLABEL
;
354 // These bits are not uniqe
357 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::OK
)
359 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::OK_CANCEL
)
360 nWinBits
|= WB_OK_CANCEL
;
361 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO
)
362 nWinBits
|= WB_YES_NO
;
363 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO_CANCEL
)
364 nWinBits
|= WB_YES_NO_CANCEL
;
365 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::RETRY_CANCEL
)
366 nWinBits
|= WB_RETRY_CANCEL
;
367 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::DEF_OK
)
368 nWinBits
|= WB_DEF_OK
;
369 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::DEF_CANCEL
)
370 nWinBits
|= WB_DEF_CANCEL
;
371 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::DEF_RETRY
)
372 nWinBits
|= WB_DEF_RETRY
;
373 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::DEF_YES
)
374 nWinBits
|= WB_DEF_YES
;
375 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::DEF_NO
)
376 nWinBits
|= WB_DEF_NO
;
378 if ( nCompType
== WINDOW_MULTILINEEDIT
|| nCompType
== WINDOW_DIALOG
|| nCompType
== WINDOW_GROUPBOX
)
380 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::AUTOHSCROLL
)
381 nWinBits
|= WB_AUTOHSCROLL
;
382 if( nComponentAttribs
& ::com::sun::star::awt::VclWindowPeerAttribute::AUTOVSCROLL
)
383 nWinBits
|= WB_AUTOVSCROLL
;
387 if ( bDecoratedWindow
)
389 if( nComponentAttribs
& ::com::sun::star::awt::WindowAttribute::NODECORATION
)
391 // No decoration removes several window attributes and must
393 nWinBits
&= ~WB_BORDER
;
394 nWinBits
&= ~WB_SIZEABLE
;
395 nWinBits
&= ~WB_MOVEABLE
;
396 nWinBits
&= ~WB_CLOSEABLE
;
397 nWinBits
|= WB_NOBORDER
;
410 static ComponentInfo aComponentInfos
[] =
412 { "buttondialog", WINDOW_BUTTONDIALOG
},
413 { "cancelbutton", WINDOW_CANCELBUTTON
},
414 { "checkbox", WINDOW_CHECKBOX
},
415 { "combobox", WINDOW_COMBOBOX
},
416 { "control", WINDOW_CONTROL
},
417 { "currencybox", WINDOW_CURRENCYBOX
},
418 { "currencyfield", WINDOW_CURRENCYFIELD
},
419 { "datebox", WINDOW_DATEBOX
},
420 { "datefield", WINDOW_DATEFIELD
},
421 { "dialog", WINDOW_DIALOG
},
422 { "dockingarea", WINDOW_DOCKINGAREA
},
423 { "dockingwindow", WINDOW_DOCKINGWINDOW
},
424 { "edit", WINDOW_EDIT
},
425 { "errorbox", WINDOW_ERRORBOX
},
426 { "fixedbitmap", WINDOW_FIXEDBITMAP
},
427 { "fixedimage", WINDOW_FIXEDIMAGE
},
428 { "fixedline", WINDOW_FIXEDLINE
},
429 { "fixedtext", WINDOW_FIXEDTEXT
},
430 { "floatingwindow", WINDOW_FLOATINGWINDOW
},
431 { "framewindow", VCLWINDOW_FRAMEWINDOW
},
432 { "groupbox", WINDOW_GROUPBOX
},
433 { "frame", WINDOW_GROUPBOX
},
434 { "helpbutton", WINDOW_HELPBUTTON
},
435 { "imagebutton", WINDOW_IMAGEBUTTON
},
436 { "infobox", WINDOW_INFOBOX
},
437 { "listbox", WINDOW_LISTBOX
},
438 { "longcurrencybox", WINDOW_LONGCURRENCYBOX
},
439 { "longcurrencyfield", WINDOW_LONGCURRENCYFIELD
},
440 { "menubutton", WINDOW_MENUBUTTON
},
441 { "messbox", WINDOW_MESSBOX
},
442 { "metricbox", WINDOW_METRICBOX
},
443 { "metricfield", WINDOW_METRICFIELD
},
444 { "modaldialog", WINDOW_MODALDIALOG
},
445 { "modelessdialog", WINDOW_MODELESSDIALOG
},
446 { "morebutton", WINDOW_MOREBUTTON
},
447 { "multilineedit", WINDOW_MULTILINEEDIT
},
448 { "multilistbox", WINDOW_MULTILISTBOX
},
449 { "numericbox", WINDOW_NUMERICBOX
},
450 { "numericfield", WINDOW_NUMERICFIELD
},
451 { "okbutton", WINDOW_OKBUTTON
},
452 { "patternbox", WINDOW_PATTERNBOX
},
453 { "patternfield", WINDOW_PATTERNFIELD
},
454 { "pushbutton", WINDOW_PUSHBUTTON
},
455 { "querybox", WINDOW_QUERYBOX
},
456 { "radiobutton", WINDOW_RADIOBUTTON
},
457 { "scrollbar", WINDOW_SCROLLBAR
},
458 { "scrollbarbox", WINDOW_SCROLLBARBOX
},
459 { "animatedimages", WINDOW_CONTROL
},
460 { "spinbutton", WINDOW_SPINBUTTON
},
461 { "spinfield", WINDOW_SPINFIELD
},
462 { "splitter", WINDOW_SPLITTER
},
463 { "splitwindow", WINDOW_SPLITWINDOW
},
464 { "statusbar", WINDOW_STATUSBAR
},
465 { "systemchildwindow", VCLWINDOW_SYSTEMCHILDWINDOW
},
466 { "tabcontrol", WINDOW_TABCONTROL
},
467 { "tabdialog", WINDOW_TABDIALOG
},
468 { "tabpage", WINDOW_TABPAGE
},
469 { "timebox", WINDOW_TIMEBOX
},
470 { "timefield", WINDOW_TIMEFIELD
},
471 { "toolbox", WINDOW_TOOLBOX
},
472 { "tristatebox", WINDOW_TRISTATEBOX
},
473 { "warningbox", WINDOW_WARNINGBOX
},
474 { "window", WINDOW_WINDOW
},
475 { "workwindow", WINDOW_WORKWINDOW
},
476 { "tabpagecontainer", WINDOW_CONTROL
},
477 { "tabpagemodel", WINDOW_TABPAGE
}
482 static int SAL_CALL
ComponentInfoCompare( const void* pFirst
, const void* pSecond
)
484 return( strcmp( static_cast<ComponentInfo
const *>(pFirst
)->pName
,
485 static_cast<ComponentInfo
const *>(pSecond
)->pName
) );
489 sal_uInt16
ImplGetComponentType( const OUString
& rServiceName
)
491 static bool bSorted
= false;
494 qsort( (void*) aComponentInfos
,
495 sizeof( aComponentInfos
) / sizeof( ComponentInfo
),
496 sizeof( ComponentInfo
),
497 ComponentInfoCompare
);
502 ComponentInfo aSearch
;
503 OString
aServiceName(OUStringToOString(rServiceName
, osl_getThreadTextEncoding()).toAsciiLowerCase());
504 if ( !aServiceName
.isEmpty() )
505 aSearch
.pName
= aServiceName
.getStr();
507 aSearch
.pName
= "window";
509 ComponentInfo
* pInf
= static_cast<ComponentInfo
*>(bsearch( &aSearch
,
510 (void*) aComponentInfos
,
511 sizeof( aComponentInfos
) / sizeof( ComponentInfo
),
512 sizeof( ComponentInfo
),
513 ComponentInfoCompare
));
515 return pInf
? pInf
->nWinType
: 0;
521 struct MessageBoxTypeInfo
523 css::awt::MessageBoxType eType
;
524 const sal_Char
*pName
;
528 static const MessageBoxTypeInfo aMessageBoxTypeInfo
[] =
530 { css::awt::MessageBoxType_MESSAGEBOX
, RTL_CONSTASCII_STRINGPARAM("messbox") },
531 { css::awt::MessageBoxType_INFOBOX
, RTL_CONSTASCII_STRINGPARAM("infobox") },
532 { css::awt::MessageBoxType_WARNINGBOX
, RTL_CONSTASCII_STRINGPARAM("warningbox") },
533 { css::awt::MessageBoxType_ERRORBOX
, RTL_CONSTASCII_STRINGPARAM("errorbox") },
534 { css::awt::MessageBoxType_QUERYBOX
, RTL_CONSTASCII_STRINGPARAM("querybox") },
535 { css::awt::MessageBoxType_MAKE_FIXED_SIZE
, 0, 0 }
538 static bool lcl_convertMessageBoxType(
539 rtl::OUString
&sType
,
540 css::awt::MessageBoxType eType
)
542 const MessageBoxTypeInfo
*pMap
= aMessageBoxTypeInfo
;
543 css::awt::MessageBoxType eVal
= css::awt::MessageBoxType_MAKE_FIXED_SIZE
;
545 while ( pMap
->pName
)
547 if ( pMap
->eType
== eType
)
550 sType
= rtl::OUString( pMap
->pName
, pMap
->nLen
, RTL_TEXTENCODING_ASCII_US
);
556 return ( eVal
!= css::awt::MessageBoxType_MAKE_FIXED_SIZE
);
560 static sal_Int32 nVCLToolkitInstanceCount
= 0;
561 static bool bInitedByVCLToolkit
= false;
563 static osl::Mutex
& getInitMutex()
565 static osl::Mutex
* pM
;
568 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
571 static osl::Mutex aMutex
;
578 static osl::Condition
& getInitCondition()
580 static osl::Condition
* pC
= 0;
583 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
586 static osl::Condition aCondition
;
595 static void SAL_CALL
ToolkitWorkerFunction( void* pArgs
)
597 osl_setThreadName("VCLXToolkit VCL main thread");
599 css::uno::Reference
<css::lang::XMultiServiceFactory
> xServiceManager
;
602 xServiceManager
= ::comphelper::getProcessServiceFactory();
604 catch (const css::uno::DeploymentException
&)
607 if (!xServiceManager
.is())
609 css::uno::Reference
<css::uno::XComponentContext
> xContext
=
610 ::cppu::defaultBootstrap_InitialComponentContext();
612 xServiceManager
= css::uno::Reference
<css::lang::XMultiServiceFactory
>(
613 xContext
->getServiceManager(), css::uno::UNO_QUERY_THROW
);
614 // set global process service factory used by unotools config helpers
615 ::comphelper::setProcessServiceFactory( xServiceManager
);
618 VCLXToolkit
* pTk
= static_cast<VCLXToolkit
*>(pArgs
);
619 bInitedByVCLToolkit
= InitVCL();
620 if( bInitedByVCLToolkit
)
622 UnoWrapper
* pUnoWrapper
= new UnoWrapper( pTk
);
623 Application::SetUnoWrapper( pUnoWrapper
);
625 getInitCondition().set();
626 if( bInitedByVCLToolkit
)
629 SolarMutexGuard aGuard
;
630 Application::Execute();
636 catch( com::sun::star::uno::Exception
& )
643 JoinMainLoopThread();
648 // constructor, which might initialize VCL
649 VCLXToolkit::VCLXToolkit():
650 cppu::WeakComponentImplHelper2
<
651 ::com::sun::star::awt::XToolkitExperimental
,
652 ::com::sun::star::lang::XServiceInfo
>( GetMutex() ),
653 m_aTopWindowListeners(rBHelper
.rMutex
),
654 m_aKeyHandlers(rBHelper
.rMutex
),
655 m_aFocusListeners(rBHelper
.rMutex
),
656 m_aEventListenerLink(LINK(this, VCLXToolkit
, eventListenerHandler
)),
657 m_aKeyListenerLink(LINK(this, VCLXToolkit
, keyListenerHandler
)),
658 m_bEventListener(false),
659 m_bKeyListener(false)
662 fnSvtCreateWindow
= NULL
;
664 osl::Guard
< osl::Mutex
> aGuard( getInitMutex() );
665 nVCLToolkitInstanceCount
++;
666 if( ( nVCLToolkitInstanceCount
== 1 ) && ( !Application::IsInMain() ) )
668 // setup execute thread
669 CreateMainLoopThread( ToolkitWorkerFunction
, this );
670 getInitCondition().wait();
674 VCLXToolkit::~VCLXToolkit()
679 void SAL_CALL
VCLXToolkit::disposing()
681 #ifndef DISABLE_DYNLOADING
684 osl_unloadModule( hSvToolsLib
);
686 fnSvtCreateWindow
= NULL
;
691 osl::Guard
< osl::Mutex
> aGuard( getInitMutex() );
692 if( --nVCLToolkitInstanceCount
== 0 )
694 if( bInitedByVCLToolkit
)
697 JoinMainLoopThread();
698 bInitedByVCLToolkit
= false;
703 if (m_bEventListener
)
705 ::Application::RemoveEventListener(m_aEventListenerLink
);
706 m_bEventListener
= false;
710 ::Application::RemoveKeyListener(m_aKeyListenerLink
);
711 m_bKeyListener
= false;
713 css::lang::EventObject
aEvent(
714 static_cast< ::cppu::OWeakObject
* >(this));
715 m_aTopWindowListeners
.disposeAndClear(aEvent
);
716 m_aKeyHandlers
.disposeAndClear(aEvent
);
717 m_aFocusListeners
.disposeAndClear(aEvent
);
721 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> VCLXToolkit::getDesktopWindow( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
723 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> xRef
;
724 // 07/00: AppWindow doesn't exist anymore...
728 ::com::sun::star::awt::Rectangle
VCLXToolkit::getWorkArea( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
730 sal_Int32 nDisplay
= Application::GetDisplayBuiltInScreen();
731 Rectangle aWorkRect
= Application::GetScreenPosSizePixel( nDisplay
);
732 com::sun::star::awt::Rectangle aNotherRect
;
733 aNotherRect
.X
= aWorkRect
.getX();
734 aNotherRect
.Y
= aWorkRect
.getY();
735 aNotherRect
.Width
= aWorkRect
.getWidth();
736 aNotherRect
.Height
= aWorkRect
.getHeight();
740 ::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
, std::exception
)
742 return ImplCreateWindow( rDescriptor
, WinBits(0) );
745 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDevice
> VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width
, sal_Int32 Height
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
747 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
749 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDevice
> xRef
;
750 VCLXVirtualDevice
* pVDev
= new VCLXVirtualDevice
;
752 SolarMutexGuard aSolarGuard
;
754 VclPtrInstance
<VirtualDevice
> pV
;
755 pV
->SetOutputSizePixel( Size( Width
, Height
) );
756 pVDev
->SetVirtualDevice( pV
);
762 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XRegion
> VCLXToolkit::createRegion( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
764 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
766 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XRegion
> xRef
= new VCLXRegion
;
770 vcl::Window
* VCLXToolkit::ImplCreateWindow( VCLXWindow
** ppNewComp
,
771 const ::com::sun::star::awt::WindowDescriptor
& rDescriptor
,
772 vcl::Window
* pParent
, WinBits nWinBits
)
774 OUString
aServiceName( rDescriptor
.WindowServiceName
);
775 aServiceName
= aServiceName
.toAsciiLowerCase();
777 vcl::Window
* pNewWindow
= NULL
;
778 sal_uInt16 nType
= ImplGetComponentType( aServiceName
);
779 bool bFrameControl
= false;
780 if ( aServiceName
== "frame" )
781 bFrameControl
= true;
782 if ( aServiceName
== "tabcontrolnotabs" )
784 nWinBits
|= WB_NOBORDER
;
785 nType
= ImplGetComponentType( OUString( "tabcontrol" ) );
789 // Wenn die Component einen Parent braucht, dann NULL zurueckgeben,
790 // spaeter mal ::com::sun::star::uno::Exception...
791 bool bException
= true;
792 if ( ( nType
== WINDOW_DIALOG
)
793 || ( nType
== WINDOW_MODALDIALOG
)
794 || ( nType
== WINDOW_MODELESSDIALOG
)
795 || ( nType
== WINDOW_MESSBOX
)
796 || ( nType
== WINDOW_INFOBOX
)
797 || ( nType
== WINDOW_WARNINGBOX
)
798 || ( nType
== WINDOW_ERRORBOX
)
799 || ( nType
== WINDOW_QUERYBOX
)
802 else if ( ( nType
== WINDOW_WINDOW
) ||
803 ( nType
== WINDOW_WORKWINDOW
) ||
804 ( nType
== VCLWINDOW_FRAMEWINDOW
) )
806 if ( rDescriptor
.Type
== ::com::sun::star::awt::WindowClass_TOP
)
819 SolarMutexGuard aVclGuard
;
820 switch ( (WindowType
)nType
)
822 case WINDOW_CANCELBUTTON
:
823 pNewWindow
= VclPtr
<CancelButton
>::Create( pParent
, nWinBits
);
824 *ppNewComp
= new VCLXButton
;
826 case WINDOW_CHECKBOX
:
827 pNewWindow
= VclPtr
<CheckBox
>::Create( pParent
, nWinBits
);
828 *ppNewComp
= new VCLXCheckBox
;
830 case WINDOW_COMBOBOX
:
831 pNewWindow
= VclPtr
<ComboBox
>::Create( pParent
, nWinBits
|WB_AUTOHSCROLL
);
832 static_cast<ComboBox
*>(pNewWindow
)->EnableAutoSize( false );
833 *ppNewComp
= new VCLXComboBox
;
835 case WINDOW_CURRENCYBOX
:
836 pNewWindow
= VclPtr
<CurrencyBox
>::Create( pParent
, nWinBits
);
838 case WINDOW_CURRENCYFIELD
:
839 pNewWindow
= VclPtr
<CurrencyField
>::Create( pParent
, nWinBits
);
840 static_cast<CurrencyField
*>(pNewWindow
)->EnableEmptyFieldValue( true );
841 *ppNewComp
= new VCLXNumericField
;
842 static_cast<VCLXFormattedSpinField
*>(*ppNewComp
)->SetFormatter( (FormatterBase
*)static_cast<CurrencyField
*>(pNewWindow
) );
845 pNewWindow
= VclPtr
<DateBox
>::Create( pParent
, nWinBits
);
847 case WINDOW_DATEFIELD
:
848 pNewWindow
= VclPtr
<DateField
>::Create( pParent
, nWinBits
);
849 static_cast<DateField
*>(pNewWindow
)->EnableEmptyFieldValue( true );
850 *ppNewComp
= new VCLXDateField
;
851 static_cast<VCLXFormattedSpinField
*>(*ppNewComp
)->SetFormatter( (FormatterBase
*)static_cast<DateField
*>(pNewWindow
) );
853 case WINDOW_DOCKINGAREA
:
854 pNewWindow
= VclPtr
<DockingAreaWindow
>::Create( pParent
);
856 case WINDOW_MULTILINEEDIT
:
858 pNewWindow
= VclPtr
<Edit
>::Create( pParent
, nWinBits
);
859 *ppNewComp
= new VCLXEdit
;
861 case WINDOW_ERRORBOX
:
862 pNewWindow
= VclPtr
<ErrorBox
>::Create( pParent
, nWinBits
, OUString() );
863 *ppNewComp
= new VCLXMessageBox
;
865 case WINDOW_FIXEDBITMAP
:
866 pNewWindow
= VclPtr
<FixedBitmap
>::Create( pParent
, nWinBits
);
868 case WINDOW_FIXEDIMAGE
:
869 pNewWindow
= VclPtr
<ImageControl
>::Create( pParent
, nWinBits
);
870 *ppNewComp
= new VCLXImageControl
;
872 case WINDOW_FIXEDLINE
:
873 pNewWindow
= VclPtr
<FixedLine
>::Create( pParent
, nWinBits
);
875 case WINDOW_FIXEDTEXT
:
876 pNewWindow
= VclPtr
<FixedText
>::Create( pParent
, nWinBits
);
877 *ppNewComp
= new VCLXFixedText
;
879 case WINDOW_FLOATINGWINDOW
:
880 pNewWindow
= VclPtr
<FloatingWindow
>::Create( pParent
, nWinBits
);
882 case WINDOW_GROUPBOX
:
883 pNewWindow
= VclPtr
<GroupBox
>::Create( pParent
, nWinBits
);
886 GroupBox
* pGroupBox
= static_cast< GroupBox
* >( pNewWindow
);
887 *ppNewComp
= new VCLXFrame
;
888 // Frame control needs to receive
890 pGroupBox
->SetMouseTransparent( false );
893 case WINDOW_HELPBUTTON
:
894 pNewWindow
= VclPtr
<HelpButton
>::Create( pParent
, nWinBits
);
895 *ppNewComp
= new VCLXButton
;
897 case WINDOW_IMAGEBUTTON
:
898 pNewWindow
= VclPtr
<ImageButton
>::Create( pParent
, nWinBits
);
899 *ppNewComp
= new VCLXButton
;
902 pNewWindow
= VclPtr
<InfoBox
>::Create( pParent
, OUString() );
903 *ppNewComp
= new VCLXMessageBox
;
906 pNewWindow
= VclPtr
<ListBox
>::Create( pParent
, nWinBits
|WB_SIMPLEMODE
|WB_AUTOHSCROLL
);
907 static_cast<ListBox
*>(pNewWindow
)->EnableAutoSize( false );
908 *ppNewComp
= new VCLXListBox
;
910 case WINDOW_LONGCURRENCYBOX
:
911 pNewWindow
= VclPtr
<LongCurrencyBox
>::Create( pParent
, nWinBits
);
913 case WINDOW_LONGCURRENCYFIELD
:
914 pNewWindow
= VclPtr
<LongCurrencyField
>::Create( pParent
, nWinBits
);
915 *ppNewComp
= new VCLXCurrencyField
;
916 static_cast<VCLXFormattedSpinField
*>(*ppNewComp
)->SetFormatter( (FormatterBase
*)static_cast<LongCurrencyField
*>(pNewWindow
) );
918 case WINDOW_MENUBUTTON
:
919 pNewWindow
= VclPtr
<MenuButton
>::Create( pParent
, nWinBits
);
920 *ppNewComp
= new VCLXButton
;
923 pNewWindow
= VclPtr
<MessBox
>::Create( pParent
, nWinBits
, OUString(), OUString() );
924 *ppNewComp
= new VCLXMessageBox
;
926 case WINDOW_METRICBOX
:
927 pNewWindow
= VclPtr
<MetricBox
>::Create( pParent
, nWinBits
);
929 case WINDOW_METRICFIELD
:
930 pNewWindow
= VclPtr
<MetricField
>::Create( pParent
, nWinBits
);
931 *ppNewComp
= new VCLXMetricField
;
932 static_cast<VCLXFormattedSpinField
*>(*ppNewComp
)->SetFormatter( (FormatterBase
*)static_cast<MetricField
*>(pNewWindow
) );
935 case WINDOW_MODALDIALOG
:
936 case WINDOW_MODELESSDIALOG
:
938 // Modal/Modeless nur durch Show/Execute
939 if ( (pParent
== NULL
) && ( rDescriptor
.ParentIndex
== -1 ) )
940 pNewWindow
= VclPtr
<toolkit::ScrollableWrapper
<Dialog
>>::Create( nullptr, nWinBits
, Dialog::InitFlag::NoParent
);
942 pNewWindow
= VclPtr
<toolkit::ScrollableWrapper
<Dialog
>>::Create( pParent
, nWinBits
);
943 // #i70217# Don't always create a new component object. It's possible that VCL has called
944 // GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() )
945 // which creates a component object.
946 css::uno::Reference
< css::awt::XWindowPeer
> xWinPeer
= pNewWindow
->GetComponentInterface( false );
948 *ppNewComp
= dynamic_cast< VCLXDialog
* >( xWinPeer
.get() );
950 *ppNewComp
= new VCLXDialog
;
953 case WINDOW_MOREBUTTON
:
954 pNewWindow
= VclPtr
<MoreButton
>::Create( pParent
, nWinBits
);
955 *ppNewComp
= new VCLXButton
;
957 case WINDOW_MULTILISTBOX
:
958 pNewWindow
= VclPtr
<MultiListBox
>::Create( pParent
, nWinBits
);
959 *ppNewComp
= new VCLXListBox
;
961 case WINDOW_NUMERICBOX
:
962 pNewWindow
= VclPtr
<NumericBox
>::Create( pParent
, nWinBits
);
964 case WINDOW_NUMERICFIELD
:
965 pNewWindow
= VclPtr
<NumericField
>::Create( pParent
, nWinBits
);
966 static_cast<NumericField
*>(pNewWindow
)->EnableEmptyFieldValue( true );
967 *ppNewComp
= new VCLXNumericField
;
968 static_cast<VCLXFormattedSpinField
*>(*ppNewComp
)->SetFormatter( (FormatterBase
*)static_cast<NumericField
*>(pNewWindow
) );
970 case WINDOW_OKBUTTON
:
971 pNewWindow
= VclPtr
<OKButton
>::Create( pParent
, nWinBits
);
972 *ppNewComp
= new VCLXButton
;
974 case WINDOW_PATTERNBOX
:
975 pNewWindow
= VclPtr
<PatternBox
>::Create( pParent
, nWinBits
);
977 case WINDOW_PATTERNFIELD
:
978 pNewWindow
= VclPtr
<PatternField
>::Create( pParent
, nWinBits
);
979 *ppNewComp
= new VCLXPatternField
;
980 static_cast<VCLXFormattedSpinField
*>(*ppNewComp
)->SetFormatter( (FormatterBase
*)static_cast<PatternField
*>(pNewWindow
) );
982 case WINDOW_PUSHBUTTON
:
983 pNewWindow
= VclPtr
<PushButton
>::Create( pParent
, nWinBits
);
984 *ppNewComp
= new VCLXButton
;
986 case WINDOW_QUERYBOX
:
987 pNewWindow
= VclPtr
<QueryBox
>::Create( pParent
, nWinBits
, OUString() );
988 *ppNewComp
= new VCLXMessageBox
;
990 case WINDOW_RADIOBUTTON
:
991 pNewWindow
= VclPtr
<RadioButton
>::Create( pParent
, nWinBits
);
992 *ppNewComp
= new VCLXRadioButton
;
994 // by default, disable RadioCheck
995 // Since the VCLXRadioButton really cares for it's RadioCheck settings, this is important:
996 // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState
997 // This leads to a strange behaviour if the control is newly created: when settings the initial
998 // state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck
999 // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls
1000 // is not really valid: the controls are grouped after they have been created, but we're still in
1001 // the creation process, so the RadioButton::Check relies on invalid grouping information.
1002 // 07.08.2001 - #87254# - frank.schoenheit@sun.com
1003 static_cast<RadioButton
*>(pNewWindow
)->EnableRadioCheck( false );
1005 case WINDOW_SCROLLBAR
:
1006 pNewWindow
= VclPtr
<ScrollBar
>::Create( pParent
, nWinBits
);
1007 *ppNewComp
= new VCLXScrollBar
;
1009 case WINDOW_SCROLLBARBOX
:
1010 pNewWindow
= VclPtr
<ScrollBarBox
>::Create( pParent
, nWinBits
);
1012 case WINDOW_SPINBUTTON
:
1013 pNewWindow
= VclPtr
<SpinButton
>::Create( pParent
, nWinBits
);
1014 *ppNewComp
= new ::toolkit::VCLXSpinButton
;
1016 case WINDOW_SPINFIELD
:
1017 pNewWindow
= VclPtr
<SpinField
>::Create( pParent
, nWinBits
);
1018 *ppNewComp
= new VCLXNumericField
;
1020 case WINDOW_SPLITTER
:
1021 pNewWindow
= VclPtr
<Splitter
>::Create( pParent
, nWinBits
);
1023 case WINDOW_SPLITWINDOW
:
1024 pNewWindow
= VclPtr
<SplitWindow
>::Create( pParent
, nWinBits
);
1026 case WINDOW_STATUSBAR
:
1027 pNewWindow
= VclPtr
<StatusBar
>::Create( pParent
, nWinBits
);
1029 case VCLWINDOW_SYSTEMCHILDWINDOW
:
1030 pNewWindow
= VclPtr
<SystemChildWindow
>::Create( pParent
, nWinBits
);
1031 *ppNewComp
= new VCLXSystemDependentWindow();
1033 case WINDOW_TABCONTROL
:
1034 pNewWindow
= VclPtr
<TabControl
>::Create( pParent
, nWinBits
);
1035 *ppNewComp
= new VCLXMultiPage
;
1037 case WINDOW_TABDIALOG
:
1038 pNewWindow
= VclPtr
<TabDialog
>::Create( pParent
, nWinBits
);
1040 case WINDOW_TABPAGE
:
1042 pNewWindow
= VclPtr
<TabPage
>::Create( pParent
, nWinBits
);
1043 *ppNewComp
= new VCLXTabPage
;
1046 case WINDOW_TIMEBOX
:
1047 pNewWindow
= VclPtr
<TimeBox
>::Create( pParent
, nWinBits
);
1049 case WINDOW_TIMEFIELD
:
1050 pNewWindow
= VclPtr
<TimeField
>::Create( pParent
, nWinBits
);
1051 static_cast<TimeField
*>(pNewWindow
)->EnableEmptyFieldValue( true );
1052 *ppNewComp
= new VCLXTimeField
;
1053 static_cast<VCLXFormattedSpinField
*>(*ppNewComp
)->SetFormatter( (FormatterBase
*)static_cast<TimeField
*>(pNewWindow
) );
1055 case WINDOW_TOOLBOX
:
1056 pNewWindow
= VclPtr
<ToolBox
>::Create( pParent
, nWinBits
);
1057 *ppNewComp
= new VCLXToolBox
;
1059 case WINDOW_TRISTATEBOX
:
1060 pNewWindow
= VclPtr
<TriStateBox
>::Create( pParent
, nWinBits
);
1062 case WINDOW_WARNINGBOX
:
1063 pNewWindow
= VclPtr
<WarningBox
>::Create( pParent
, nWinBits
, OUString() );
1064 *ppNewComp
= new VCLXMessageBox
;
1066 case WINDOW_WORKWINDOW
:
1068 case VCLWINDOW_FRAMEWINDOW
:
1069 case WINDOW_DOCKINGWINDOW
:
1070 if ( rDescriptor
.Type
== ::com::sun::star::awt::WindowClass_TOP
)
1072 if (nType
== WINDOW_DOCKINGWINDOW
)
1073 pNewWindow
= VclPtr
<DockingWindow
>::Create( pParent
, nWinBits
);
1076 if ((pParent
== NULL
) && rDescriptor
.Parent
.is())
1078 // try to get a system dependent window handle
1079 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XSystemDependentWindowPeer
> xSystemDepParent(rDescriptor
.Parent
, ::com::sun::star::uno::UNO_QUERY
);
1081 if (xSystemDepParent
.is())
1083 sal_Int8 processID
[16];
1085 rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8
*>(processID
) );
1087 ::com::sun::star::uno::Sequence
<sal_Int8
> processIdSeq((sal_Int8
*)processID
, 16);
1089 ::com::sun::star::uno::Any anyHandle
= xSystemDepParent
->getWindowHandle(processIdSeq
, SYSTEM_DEPENDENT_TYPE
);
1091 // use sal_Int64 here to accommodate all int types
1092 // uno::Any shift operator whill upcast if necessary
1093 sal_Int64 nWindowHandle
= 0;
1094 bool bXEmbed
= false;
1096 bool bUseParentData
= true;
1097 if( ! (anyHandle
>>= nWindowHandle
) )
1099 css::uno::Sequence
< css::beans::NamedValue
> aProps
;
1100 if( anyHandle
>>= aProps
)
1102 const int nProps
= aProps
.getLength();
1103 const css::beans::NamedValue
* pProps
= aProps
.getConstArray();
1104 for( int i
= 0; i
< nProps
; i
++ )
1106 if ( pProps
[i
].Name
== "WINDOW" )
1107 pProps
[i
].Value
>>= nWindowHandle
;
1108 else if ( pProps
[i
].Name
== "XEMBED" )
1109 pProps
[i
].Value
>>= bXEmbed
;
1113 bUseParentData
= false;
1116 if( bUseParentData
)
1118 SystemParentData aParentData
;
1119 aParentData
.nSize
= sizeof( aParentData
);
1121 aParentData
.pView
= reinterpret_cast<NSView
*>(nWindowHandle
);
1122 #elif defined ANDROID
1127 aParentData
.aWindow
= nWindowHandle
;
1128 aParentData
.bXEmbedSupport
= bXEmbed
;
1130 aParentData
.hWnd
= reinterpret_cast<HWND
>(nWindowHandle
);
1132 pNewWindow
= VclPtr
<WorkWindow
>::Create( &aParentData
);
1138 pNewWindow
= VclPtr
<WorkWindow
>::Create( pParent
, nWinBits
);
1141 *ppNewComp
= new VCLXTopWindow( pNewWindow
->GetType() == WINDOW_WORKWINDOW
);
1143 else if ( rDescriptor
.Type
== ::com::sun::star::awt::WindowClass_CONTAINER
)
1145 if (nType
== WINDOW_DOCKINGWINDOW
)
1146 pNewWindow
= VclPtr
<DockingWindow
>::Create( pParent
, nWinBits
);
1148 pNewWindow
= VclPtr
<vcl::Window
>::Create( pParent
, nWinBits
);
1149 *ppNewComp
= new VCLXContainer
;
1153 if (nType
== WINDOW_DOCKINGWINDOW
)
1154 pNewWindow
= VclPtr
<DockingWindow
>::Create( pParent
, nWinBits
);
1156 pNewWindow
= VclPtr
<vcl::Window
>::Create( pParent
, nWinBits
);
1157 *ppNewComp
= new VCLXWindow
;
1160 case WINDOW_CONTROL
:
1161 if ( rDescriptor
.WindowServiceName
.equalsIgnoreAsciiCase(
1162 "tabpagecontainer" ) )
1164 pNewWindow
= VclPtr
<TabControl
>::Create( pParent
, nWinBits
);
1165 *ppNewComp
= new VCLXTabPageContainer
;
1167 else if ( aServiceName
== "animatedimages" )
1169 pNewWindow
= VclPtr
<Throbber
>::Create( pParent
, nWinBits
);
1170 *ppNewComp
= new ::toolkit::AnimatedImagesPeer
;
1174 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" );
1182 #ifndef DISABLE_DYNLOADING
1184 extern "C" { static void SAL_CALL
thisModule() {} }
1188 extern "C" vcl::Window
* SAL_CALL
CreateWindow( VCLXWindow
** ppNewComp
, const ::com::sun::star::awt::WindowDescriptor
* pDescriptor
, vcl::Window
* pParent
, WinBits nWinBits
);
1192 css::uno::Reference
< css::awt::XWindowPeer
> VCLXToolkit::ImplCreateWindow(
1193 const css::awt::WindowDescriptor
& rDescriptor
,
1194 WinBits nForceWinBits
)
1196 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1198 SolarMutexGuard aSolarGuard
;
1200 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> xRef
;
1202 vcl::Window
* pParent
= NULL
;
1203 if ( rDescriptor
.Parent
.is() )
1205 VCLXWindow
* pParentComponent
= VCLXWindow::GetImplementation( rDescriptor
.Parent
);
1207 // #103939# Don't throw assertion, may be it's a system dependent window, used in ImplCreateWindow.
1208 // DBG_ASSERT( pParentComponent, "ParentComponent not valid" );
1210 if ( pParentComponent
)
1211 pParent
= pParentComponent
->GetWindow();
1213 WinBits nWinBits
= ImplGetWinBits( rDescriptor
.WindowAttributes
,
1214 ImplGetComponentType( rDescriptor
.WindowServiceName
) );
1215 nWinBits
|= nForceWinBits
;
1217 VCLXWindow
* pNewComp
= NULL
;
1219 vcl::Window
* pNewWindow
= NULL
;
1220 // Try to create the window with SvTools
1221 // (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way,
1222 // and we need to stay compatible)
1223 // try to load the lib
1224 if ( !fnSvtCreateWindow
1225 #ifndef DISABLE_DYNLOADING
1230 #ifndef DISABLE_DYNLOADING
1231 OUString
aLibName(SVT_DLL_NAME
);
1232 hSvToolsLib
= osl_loadModuleRelative(
1233 &thisModule
, aLibName
.pData
, SAL_LOADMODULE_DEFAULT
);
1236 OUString
aFunctionName( "CreateWindow" );
1237 fnSvtCreateWindow
= reinterpret_cast<FN_SvtCreateWindow
>(osl_getFunctionSymbol( hSvToolsLib
, aFunctionName
.pData
));
1240 fnSvtCreateWindow
= CreateWindow
;
1243 // ask the SvTool creation function
1244 if ( fnSvtCreateWindow
)
1245 pNewWindow
= fnSvtCreateWindow( &pNewComp
, &rDescriptor
, pParent
, nWinBits
);
1247 // if SvTools could not provide a window, create it ourself
1249 pNewWindow
= ImplCreateWindow( &pNewComp
, rDescriptor
, pParent
, nWinBits
);
1251 DBG_ASSERT( pNewWindow
, "createWindow: Unknown Component!" );
1252 DBG_ASSERTWARNING( pNewComp
, "createWindow: No special Interface!" );
1256 pNewWindow
->SetCreatedWithToolkit( true );
1257 //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead
1259 if ( rDescriptor
.WindowAttributes
& ::com::sun::star::awt::WindowAttribute::MINSIZE
)
1261 pNewWindow
->SetSizePixel( Size() );
1263 else if ( rDescriptor
.WindowAttributes
& ::com::sun::star::awt::WindowAttribute::FULLSIZE
)
1266 pNewWindow
->SetSizePixel( pParent
->GetOutputSizePixel() );
1268 else if ( !VCLUnoHelper::IsZero( rDescriptor
.Bounds
) )
1270 Rectangle aRect
= VCLRectangle( rDescriptor
.Bounds
);
1271 pNewWindow
->SetPosSizePixel( aRect
.TopLeft(), aRect
.GetSize() );
1276 // Default-Interface
1277 xRef
= pNewWindow
->GetComponentInterface( true );
1281 pNewComp
->SetCreatedWithToolkit( true );
1283 pNewWindow
->SetComponentInterface( xRef
);
1285 DBG_ASSERT( pNewWindow
->GetComponentInterface( false ) == xRef
,
1286 "VCLXToolkit::createWindow: did #133706# resurge?" );
1288 if ( rDescriptor
.WindowAttributes
& ::com::sun::star::awt::WindowAttribute::SHOW
)
1295 ::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
, std::exception
)
1297 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1299 sal_uInt32 nComponents
= rDescriptors
.getLength();
1300 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> > aSeq( nComponents
);
1301 for ( sal_uInt32 n
= 0; n
< nComponents
; n
++ )
1303 ::com::sun::star::awt::WindowDescriptor aDescr
= rDescriptors
.getConstArray()[n
];
1305 if ( aDescr
.ParentIndex
== (-1) )
1306 aDescr
.Parent
= NULL
;
1307 else if ( ( aDescr
.ParentIndex
>= 0 ) && ( aDescr
.ParentIndex
< (short)n
) )
1308 aDescr
.Parent
= aSeq
.getConstArray()[aDescr
.ParentIndex
];
1309 aSeq
.getArray()[n
] = createWindow( aDescr
);
1314 // ::com::sun::star::awt::XSystemChildFactory
1315 ::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
, std::exception
)
1317 VclPtr
<vcl::Window
> pChildWindow
;
1318 if ( nSystemType
== SYSTEM_DEPENDENT_TYPE
)
1320 // use sal_Int64 here to accommodate all int types
1321 // uno::Any shift operator whill upcast if necessary
1322 sal_Int64 nWindowHandle
= 0;
1323 bool bXEmbed
= false;
1325 bool bUseParentData
= true;
1326 if( ! (Parent
>>= nWindowHandle
) )
1328 css::uno::Sequence
< css::beans::NamedValue
> aProps
;
1329 if( Parent
>>= aProps
)
1331 const int nProps
= aProps
.getLength();
1332 const css::beans::NamedValue
* pProps
= aProps
.getConstArray();
1333 for( int i
= 0; i
< nProps
; i
++ )
1335 if ( pProps
[i
].Name
== "WINDOW" )
1336 pProps
[i
].Value
>>= nWindowHandle
;
1337 else if ( pProps
[i
].Name
== "XEMBED" )
1338 pProps
[i
].Value
>>= bXEmbed
;
1342 bUseParentData
= false;
1345 if( bUseParentData
)
1347 SystemParentData aParentData
;
1348 aParentData
.nSize
= sizeof( aParentData
);
1350 aParentData
.pView
= reinterpret_cast<NSView
*>(nWindowHandle
);
1351 #elif defined ANDROID
1356 aParentData
.aWindow
= nWindowHandle
;
1357 aParentData
.bXEmbedSupport
= bXEmbed
;
1359 aParentData
.hWnd
= reinterpret_cast<HWND
>(nWindowHandle
);
1361 SolarMutexGuard aGuard
;
1364 pChildWindow
.reset( VclPtr
<WorkWindow
>::Create( &aParentData
) );
1366 catch ( const ::com::sun::star::uno::RuntimeException
& rEx
)
1368 // system child window could not be created
1370 "VCLXToolkit::createSystemChild: caught %s\n",
1372 rEx
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
1373 pChildWindow
.clear();
1377 else if (nSystemType
== com::sun::star::lang::SystemDependent::SYSTEM_JAVA
)
1379 SolarMutexGuard aGuard
;
1380 pChildWindow
.reset(VclPtr
<WorkWindow
>::Create(nullptr, Parent
));
1383 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> xPeer
;
1386 VCLXTopWindow
* pPeer
= new VCLXTopWindow(true);
1387 SolarMutexGuard aGuard
;
1388 pPeer
->SetWindow( pChildWindow
);
1395 // ::com::sun::star::awt::XMessageBoxFactory
1396 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMessageBox
> SAL_CALL
VCLXToolkit::createMessageBox(
1397 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
>& aParent
,
1398 ::com::sun::star::awt::MessageBoxType eType
,
1399 ::sal_Int32 aButtons
,
1400 const OUString
& aTitle
,
1401 const OUString
& aMessage
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
1403 ::com::sun::star::awt::WindowDescriptor aDescriptor
;
1405 sal_Int32 nWindowAttributes
= css::awt::WindowAttribute::BORDER
|css::awt::WindowAttribute::MOVEABLE
|css::awt::WindowAttribute::CLOSEABLE
;
1407 // Map button definitions to window attributes
1408 if (( aButtons
& 0x0000ffffL
) == css::awt::MessageBoxButtons::BUTTONS_OK
)
1409 nWindowAttributes
|= css::awt::VclWindowPeerAttribute::OK
;
1410 else if (( aButtons
& 0x0000ffffL
) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL
)
1411 nWindowAttributes
|= css::awt::VclWindowPeerAttribute::OK_CANCEL
;
1412 else if (( aButtons
& 0x0000ffffL
) == css::awt::MessageBoxButtons::BUTTONS_YES_NO
)
1413 nWindowAttributes
|= css::awt::VclWindowPeerAttribute::YES_NO
;
1414 else if (( aButtons
& 0x0000ffffL
) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL
)
1415 nWindowAttributes
|= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL
;
1416 else if (( aButtons
& 0x0000ffffL
) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL
)
1417 nWindowAttributes
|= css::awt::VclWindowPeerAttribute::RETRY_CANCEL
;
1419 // Map default button definitions to window attributes
1420 if (sal_Int32( aButtons
& 0xffff0000L
) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK
)
1421 nWindowAttributes
|= css::awt::VclWindowPeerAttribute::DEF_OK
;
1422 else if (sal_Int32( aButtons
& 0xffff0000L
) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL
)
1423 nWindowAttributes
|= css::awt::VclWindowPeerAttribute::DEF_CANCEL
;
1424 else if (sal_Int32( aButtons
& 0xffff0000L
) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES
)
1425 nWindowAttributes
|= css::awt::VclWindowPeerAttribute::DEF_YES
;
1426 else if (sal_Int32( aButtons
& 0xffff0000L
) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO
)
1427 nWindowAttributes
|= css::awt::VclWindowPeerAttribute::DEF_NO
;
1428 else if (sal_Int32( aButtons
& 0xffff0000L
) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY
)
1429 nWindowAttributes
|= css::awt::VclWindowPeerAttribute::DEF_RETRY
;
1431 // No more bits for VclWindowPeerAttribute possible. Mapping must be
1432 // done explicitly using VCL methods
1433 WinBits
nAddWinBits( 0 );
1434 if (( aButtons
& 0x0000ffffL
) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY
)
1435 nAddWinBits
|= WB_ABORT_RETRY_IGNORE
;
1436 if ( sal_Int32( aButtons
& 0xffff0000L
) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE
)
1437 nAddWinBits
|= WB_DEF_IGNORE
;
1439 rtl::OUString aType
;
1440 lcl_convertMessageBoxType( aType
, eType
);
1442 aDescriptor
.Type
= css::awt::WindowClass_MODALTOP
;
1443 aDescriptor
.WindowServiceName
= aType
;
1444 aDescriptor
.ParentIndex
= -1;
1445 aDescriptor
.Parent
= aParent
;
1446 aDescriptor
.WindowAttributes
= nWindowAttributes
;
1447 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMessageBox
> xMsgBox(
1448 ImplCreateWindow( aDescriptor
, nAddWinBits
), css::uno::UNO_QUERY
);
1449 css::uno::Reference
< css::awt::XWindow
> xWindow( xMsgBox
, css::uno::UNO_QUERY
);
1450 if ( xMsgBox
.is() && xWindow
.is() )
1452 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( xWindow
);
1455 SolarMutexGuard aGuard
;
1456 xMsgBox
->setCaptionText( aTitle
);
1457 xMsgBox
->setMessageText( aMessage
);
1464 ::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
, std::exception
)
1468 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( window
);
1471 return pWindow
->GetDragGestureRecognizer();
1473 return ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer
>();
1476 ::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
, std::exception
)
1480 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( window
);
1483 return pWindow
->GetDragSource();
1485 return ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::dnd::XDragSource
>();
1488 ::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
, std::exception
)
1492 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( window
);
1495 return pWindow
->GetDropTarget();
1497 return ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::dnd::XDropTarget
>();
1500 ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::clipboard::XClipboard
> SAL_CALL
VCLXToolkit::getClipboard( const OUString
& clipboardName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
1502 if( clipboardName
.isEmpty() )
1504 if( !mxClipboard
.is() )
1506 // remember clipboard here
1507 mxClipboard
= css::datatransfer::clipboard::SystemClipboard::create(
1508 comphelper::getProcessComponentContext());
1514 else if( clipboardName
== "Selection" )
1519 return ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::clipboard::XClipboard
>();
1523 OUString
VCLXToolkit::getImplementationName() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
1525 return OUString("stardiv.Toolkit.VCLXToolkit");
1528 sal_Bool
VCLXToolkit::supportsService( const OUString
& rServiceName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
1530 return cppu::supportsService(this, rServiceName
);
1533 ::com::sun::star::uno::Sequence
< OUString
> VCLXToolkit::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
1535 return css::uno::Sequence
<OUString
>{
1536 "com.sun.star.awt.Toolkit", "stardiv.vcl.VclToolkit"};
1539 // css::awt::XExtendedToolkit:
1542 ::sal_Int32 SAL_CALL
VCLXToolkit::getTopWindowCount()
1543 throw (css::uno::RuntimeException
, std::exception
)
1545 return static_cast< ::sal_Int32
>(::Application::GetTopWindowCount());
1546 // XXX numeric overflow
1550 css::uno::Reference
< css::awt::XTopWindow
> SAL_CALL
1551 VCLXToolkit::getTopWindow(::sal_Int32 nIndex
)
1552 throw (css::uno::RuntimeException
, std::exception
)
1554 vcl::Window
* p
= ::Application::GetTopWindow(static_cast< long >(nIndex
));
1555 // XXX numeric overflow
1556 return css::uno::Reference
< css::awt::XTopWindow
>(
1557 p
== 0 ? 0 : static_cast< css::awt::XWindow
* >(p
->GetWindowPeer()),
1558 css::uno::UNO_QUERY
);
1562 css::uno::Reference
< css::awt::XTopWindow
> SAL_CALL
1563 VCLXToolkit::getActiveTopWindow() throw (css::uno::RuntimeException
, std::exception
)
1565 vcl::Window
* p
= ::Application::GetActiveTopWindow();
1566 return css::uno::Reference
< css::awt::XTopWindow
>(
1567 p
== 0 ? 0 : static_cast< css::awt::XWindow
* >(p
->GetWindowPeer()),
1568 css::uno::UNO_QUERY
);
1572 void SAL_CALL
VCLXToolkit::addTopWindowListener(
1573 css::uno::Reference
< css::awt::XTopWindowListener
> const & rListener
)
1574 throw (css::uno::RuntimeException
, std::exception
)
1576 OSL_ENSURE(rListener
.is(), "Null rListener");
1577 ::osl::ClearableMutexGuard
aGuard(rBHelper
.rMutex
);
1578 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
1581 rListener
->disposing(
1582 css::lang::EventObject(
1583 static_cast< ::cppu::OWeakObject
* >(this)));
1585 else if (m_aTopWindowListeners
.addInterface(rListener
) == 1
1586 && !m_bEventListener
)
1588 m_bEventListener
= true;
1589 ::Application::AddEventListener(m_aEventListenerLink
);
1594 void SAL_CALL
VCLXToolkit::removeTopWindowListener(
1595 css::uno::Reference
< css::awt::XTopWindowListener
> const & rListener
)
1596 throw (css::uno::RuntimeException
, std::exception
)
1598 ::osl::MutexGuard
aGuard(rBHelper
.rMutex
);
1599 if (!(rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
1600 && m_aTopWindowListeners
.removeInterface(rListener
) == 0
1601 && m_aFocusListeners
.getLength() == 0 && m_bEventListener
)
1603 ::Application::RemoveEventListener(m_aEventListenerLink
);
1604 m_bEventListener
= false;
1609 void SAL_CALL
VCLXToolkit::addKeyHandler(
1610 css::uno::Reference
< css::awt::XKeyHandler
> const & rHandler
)
1611 throw (css::uno::RuntimeException
, std::exception
)
1613 OSL_ENSURE(rHandler
.is(), "Null rHandler");
1614 ::osl::ClearableMutexGuard
aGuard(rBHelper
.rMutex
);
1615 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
1618 rHandler
->disposing(
1619 css::lang::EventObject(
1620 static_cast< ::cppu::OWeakObject
* >(this)));
1622 else if (m_aKeyHandlers
.addInterface(rHandler
) == 1 && !m_bKeyListener
)
1624 m_bKeyListener
= true;
1625 ::Application::AddKeyListener(m_aKeyListenerLink
);
1630 void SAL_CALL
VCLXToolkit::removeKeyHandler(
1631 css::uno::Reference
< css::awt::XKeyHandler
> const & rHandler
)
1632 throw (css::uno::RuntimeException
, std::exception
)
1634 ::osl::MutexGuard
aGuard(rBHelper
.rMutex
);
1635 if (!(rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
1636 && m_aKeyHandlers
.removeInterface(rHandler
) == 0 && m_bKeyListener
)
1638 ::Application::RemoveKeyListener(m_aKeyListenerLink
);
1639 m_bKeyListener
= false;
1644 void SAL_CALL
VCLXToolkit::addFocusListener(
1645 css::uno::Reference
< css::awt::XFocusListener
> const & rListener
)
1646 throw (css::uno::RuntimeException
, std::exception
)
1648 OSL_ENSURE(rListener
.is(), "Null rListener");
1649 ::osl::ClearableMutexGuard
aGuard(rBHelper
.rMutex
);
1650 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
1653 rListener
->disposing(
1654 css::lang::EventObject(
1655 static_cast< ::cppu::OWeakObject
* >(this)));
1657 else if (m_aFocusListeners
.addInterface(rListener
) == 1
1658 && !m_bEventListener
)
1660 m_bEventListener
= true;
1661 ::Application::AddEventListener(m_aEventListenerLink
);
1666 void SAL_CALL
VCLXToolkit::removeFocusListener(
1667 css::uno::Reference
< css::awt::XFocusListener
> const & rListener
)
1668 throw (css::uno::RuntimeException
, std::exception
)
1670 ::osl::MutexGuard
aGuard(rBHelper
.rMutex
);
1671 if (!(rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
1672 && m_aFocusListeners
.removeInterface(rListener
) == 0
1673 && m_aTopWindowListeners
.getLength() == 0 && m_bEventListener
)
1675 ::Application::RemoveEventListener(m_aEventListenerLink
);
1676 m_bEventListener
= false;
1681 void SAL_CALL
VCLXToolkit::fireFocusGained(
1682 ::com::sun::star::uno::Reference
<
1683 ::com::sun::star::uno::XInterface
> const &)
1684 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
1689 void SAL_CALL
VCLXToolkit::fireFocusLost(
1690 ::com::sun::star::uno::Reference
<
1691 ::com::sun::star::uno::XInterface
> const &)
1692 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
1697 IMPL_LINK(VCLXToolkit
, eventListenerHandler
, ::VclSimpleEvent
const *, pEvent
)
1699 switch (pEvent
->GetId())
1701 case VCLEVENT_WINDOW_SHOW
:
1702 callTopWindowListeners(
1703 pEvent
, &css::awt::XTopWindowListener::windowOpened
);
1705 case VCLEVENT_WINDOW_HIDE
:
1706 callTopWindowListeners(
1707 pEvent
, &css::awt::XTopWindowListener::windowClosed
);
1709 case VCLEVENT_WINDOW_ACTIVATE
:
1710 callTopWindowListeners(
1711 pEvent
, &css::awt::XTopWindowListener::windowActivated
);
1713 case VCLEVENT_WINDOW_DEACTIVATE
:
1714 callTopWindowListeners(
1715 pEvent
, &css::awt::XTopWindowListener::windowDeactivated
);
1717 case VCLEVENT_WINDOW_CLOSE
:
1718 callTopWindowListeners(
1719 pEvent
, &css::awt::XTopWindowListener::windowClosing
);
1721 case VCLEVENT_WINDOW_GETFOCUS
:
1722 callFocusListeners(pEvent
, true);
1724 case VCLEVENT_WINDOW_LOSEFOCUS
:
1725 callFocusListeners(pEvent
, false);
1727 case VCLEVENT_WINDOW_MINIMIZE
:
1728 callTopWindowListeners(
1729 pEvent
, &css::awt::XTopWindowListener::windowMinimized
);
1731 case VCLEVENT_WINDOW_NORMALIZE
:
1732 callTopWindowListeners(
1733 pEvent
, &css::awt::XTopWindowListener::windowNormalized
);
1739 IMPL_LINK(VCLXToolkit
, keyListenerHandler
, ::VclSimpleEvent
const *, pEvent
)
1741 switch (pEvent
->GetId())
1743 case VCLEVENT_WINDOW_KEYINPUT
:
1744 return callKeyHandlers(pEvent
, true);
1745 case VCLEVENT_WINDOW_KEYUP
:
1746 return callKeyHandlers(pEvent
, false);
1751 void VCLXToolkit::callTopWindowListeners(
1752 ::VclSimpleEvent
const * pEvent
,
1753 void (SAL_CALL
css::awt::XTopWindowListener::* pFn
)(
1754 css::lang::EventObject
const &))
1756 vcl::Window
* pWindow
1757 = static_cast< ::VclWindowEvent
const * >(pEvent
)->GetWindow();
1758 if (pWindow
->IsTopWindow())
1760 css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> >
1761 aListeners(m_aTopWindowListeners
.getElements());
1762 if (aListeners
.hasElements())
1764 css::lang::EventObject
aAwtEvent(
1765 static_cast< css::awt::XWindow
* >(pWindow
->GetWindowPeer()));
1766 for (::sal_Int32 i
= 0; i
< aListeners
.getLength(); ++i
)
1768 css::uno::Reference
< css::awt::XTopWindowListener
>
1769 xListener(aListeners
[i
], css::uno::UNO_QUERY
);
1772 (xListener
.get()->*pFn
)(aAwtEvent
);
1774 catch (const css::uno::RuntimeException
& rEx
)
1777 "VCLXToolkit::callTopWindowListeners: caught %s\n",
1779 rEx
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
1786 long VCLXToolkit::callKeyHandlers(::VclSimpleEvent
const * pEvent
,
1789 css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> >
1790 aHandlers(m_aKeyHandlers
.getElements());
1792 if (aHandlers
.hasElements())
1794 vcl::Window
* pWindow
= static_cast< ::VclWindowEvent
const * >(pEvent
)->GetWindow();
1796 // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event
1797 ::KeyEvent
* pKeyEvent
= static_cast< ::KeyEvent
* >(
1798 static_cast< ::VclWindowEvent
const * >(pEvent
)->GetData());
1799 css::awt::KeyEvent
aAwtEvent(
1800 static_cast< css::awt::XWindow
* >(pWindow
->GetWindowPeer()),
1801 (pKeyEvent
->GetKeyCode().IsShift()
1802 ? css::awt::KeyModifier::SHIFT
: 0)
1803 | (pKeyEvent
->GetKeyCode().IsMod1()
1804 ? css::awt::KeyModifier::MOD1
: 0)
1805 | (pKeyEvent
->GetKeyCode().IsMod2()
1806 ? css::awt::KeyModifier::MOD2
: 0)
1807 | (pKeyEvent
->GetKeyCode().IsMod3()
1808 ? css::awt::KeyModifier::MOD3
: 0),
1809 pKeyEvent
->GetKeyCode().GetCode(), pKeyEvent
->GetCharCode(),
1810 sal::static_int_cast
< sal_Int16
>(
1811 pKeyEvent
->GetKeyCode().GetFunction()));
1812 for (::sal_Int32 i
= 0; i
< aHandlers
.getLength(); ++i
)
1814 css::uno::Reference
< css::awt::XKeyHandler
> xHandler(
1815 aHandlers
[i
], css::uno::UNO_QUERY
);
1818 if ((bPressed
? xHandler
->keyPressed(aAwtEvent
)
1819 : xHandler
->keyReleased(aAwtEvent
)))
1822 catch (const css::uno::RuntimeException
& rEx
)
1825 "VCLXToolkit::callKeyHandlers: caught %s\n",
1827 rEx
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
1834 void VCLXToolkit::callFocusListeners(::VclSimpleEvent
const * pEvent
,
1837 vcl::Window
* pWindow
1838 = static_cast< ::VclWindowEvent
const * >(pEvent
)->GetWindow();
1839 if (pWindow
->IsTopWindow())
1841 css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> >
1842 aListeners(m_aFocusListeners
.getElements());
1843 if (aListeners
.hasElements())
1845 // Ignore the interior of compound controls when determining the
1846 // window that gets the focus next (see implementation in
1847 // vclxwindow.cxx for mapping between VCL and UNO AWT event):
1848 css::uno::Reference
< css::uno::XInterface
> xNext
;
1849 vcl::Window
* pFocus
= ::Application::GetFocusWindow();
1850 for (vcl::Window
* p
= pFocus
; p
!= 0; p
= p
->GetParent())
1851 if (!p
->IsCompoundControl())
1857 xNext
= pFocus
->GetComponentInterface(true);
1858 css::awt::FocusEvent
aAwtEvent(
1859 static_cast< css::awt::XWindow
* >(pWindow
->GetWindowPeer()),
1860 pWindow
->GetGetFocusFlags(), xNext
, false);
1861 for (::sal_Int32 i
= 0; i
< aListeners
.getLength(); ++i
)
1863 css::uno::Reference
< css::awt::XFocusListener
> xListener(
1864 aListeners
[i
], css::uno::UNO_QUERY
);
1867 bGained
? xListener
->focusGained(aAwtEvent
)
1868 : xListener
->focusLost(aAwtEvent
);
1870 catch (const css::uno::RuntimeException
& rEx
)
1873 "VCLXToolkit::callFocusListeners: caught %s\n",
1875 rEx
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
1882 // css::awt::XReschedule:
1884 void SAL_CALL
VCLXToolkit::reschedule()
1885 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
1887 SolarMutexGuard aSolarGuard
;
1888 Application::Reschedule(true);
1891 void SAL_CALL
VCLXToolkit::processEventsToIdle()
1892 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
1894 SolarMutexGuard aSolarGuard
;
1895 Scheduler::ProcessTaskScheduling(false);
1900 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
1901 stardiv_Toolkit_VCLXToolkit_get_implementation(
1902 css::uno::XComponentContext
*,
1903 css::uno::Sequence
<css::uno::Any
> const &)
1905 return cppu::acquire(new VCLXToolkit());
1908 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */