4 * Copyright 2000, 2005 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "user_private.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(user
);
32 static const USER_DRIVER null_driver
, lazy_load_driver
;
34 const USER_DRIVER
*USER_Driver
= &lazy_load_driver
;
36 /* load the graphics driver */
37 static const USER_DRIVER
*load_driver(void)
39 char buffer
[MAX_PATH
], libname
[32], *name
, *next
;
42 HMODULE graphics_driver
;
43 USER_DRIVER
*driver
, *prev
;
45 strcpy( buffer
, "x11" ); /* default value */
46 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
47 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Drivers", &hkey
))
49 DWORD type
, count
= sizeof(buffer
);
50 RegQueryValueExA( hkey
, "Graphics", 0, &type
, (LPBYTE
) buffer
, &count
);
57 next
= strchr( name
, ',' );
58 if (next
) *next
++ = 0;
60 snprintf( libname
, sizeof(libname
), "wine%s.drv", name
);
61 if ((graphics_driver
= LoadLibraryA( libname
)) != 0) break;
65 driver
= HeapAlloc( GetProcessHeap(), 0, sizeof(*driver
) );
66 memcpy( driver
, &null_driver
, sizeof(*driver
) );
70 #define GET_USER_FUNC(name) \
71 do { if ((ptr = GetProcAddress( graphics_driver, #name ))) driver->p##name = ptr; } while(0)
73 GET_USER_FUNC(ActivateKeyboardLayout
);
75 GET_USER_FUNC(GetAsyncKeyState
);
76 GET_USER_FUNC(GetKeyNameText
);
77 GET_USER_FUNC(GetKeyboardLayout
);
78 GET_USER_FUNC(GetKeyboardLayoutList
);
79 GET_USER_FUNC(GetKeyboardLayoutName
);
80 GET_USER_FUNC(LoadKeyboardLayout
);
81 GET_USER_FUNC(MapVirtualKeyEx
);
82 GET_USER_FUNC(SendInput
);
83 GET_USER_FUNC(ToUnicodeEx
);
84 GET_USER_FUNC(UnloadKeyboardLayout
);
85 GET_USER_FUNC(VkKeyScanEx
);
86 GET_USER_FUNC(SetCursor
);
87 GET_USER_FUNC(GetCursorPos
);
88 GET_USER_FUNC(SetCursorPos
);
89 GET_USER_FUNC(GetScreenSaveActive
);
90 GET_USER_FUNC(SetScreenSaveActive
);
91 GET_USER_FUNC(AcquireClipboard
);
92 GET_USER_FUNC(EmptyClipboard
);
93 GET_USER_FUNC(SetClipboardData
);
94 GET_USER_FUNC(GetClipboardData
);
95 GET_USER_FUNC(CountClipboardFormats
);
96 GET_USER_FUNC(EnumClipboardFormats
);
97 GET_USER_FUNC(IsClipboardFormatAvailable
);
98 GET_USER_FUNC(RegisterClipboardFormat
);
99 GET_USER_FUNC(GetClipboardFormatName
);
100 GET_USER_FUNC(EndClipboardUpdate
);
101 GET_USER_FUNC(ResetSelectionOwner
);
102 GET_USER_FUNC(ChangeDisplaySettingsEx
);
103 GET_USER_FUNC(EnumDisplaySettingsEx
);
104 GET_USER_FUNC(CreateDesktopWindow
);
105 GET_USER_FUNC(CreateWindow
);
106 GET_USER_FUNC(DestroyWindow
);
107 GET_USER_FUNC(GetDCEx
);
108 GET_USER_FUNC(MsgWaitForMultipleObjectsEx
);
109 GET_USER_FUNC(ReleaseDC
);
110 GET_USER_FUNC(ScrollDC
);
111 GET_USER_FUNC(SetFocus
);
112 GET_USER_FUNC(SetParent
);
113 GET_USER_FUNC(SetWindowPos
);
114 GET_USER_FUNC(SetWindowRgn
);
115 GET_USER_FUNC(SetWindowIcon
);
116 GET_USER_FUNC(SetWindowStyle
);
117 GET_USER_FUNC(SetWindowText
);
118 GET_USER_FUNC(ShowWindow
);
119 GET_USER_FUNC(SysCommandSizeMove
);
120 GET_USER_FUNC(WindowFromDC
);
121 GET_USER_FUNC(WindowMessage
);
125 prev
= InterlockedCompareExchangePointer( (void **)&USER_Driver
, driver
, (void *)&lazy_load_driver
);
126 if (prev
!= &lazy_load_driver
)
128 /* another thread beat us to it */
129 HeapFree( GetProcessHeap(), 0, driver
);
130 FreeLibrary( graphics_driver
);
136 /* unload the graphics driver on process exit */
137 void USER_unload_driver(void)
139 /* make sure we don't try to call the driver after it has been detached */
140 USER_Driver
= &null_driver
;
144 /**********************************************************************
147 * These are fallbacks for entry points that are not implemented in the real driver.
150 static HKL
nulldrv_ActivateKeyboardLayout( HKL layout
, UINT flags
)
155 static void nulldrv_Beep(void)
159 static SHORT
nulldrv_GetAsyncKeyState( INT key
)
164 static INT
nulldrv_GetKeyNameText( LONG lparam
, LPWSTR buffer
, INT size
)
169 static HKL
nulldrv_GetKeyboardLayout( DWORD layout
)
174 static UINT
nulldrv_GetKeyboardLayoutList( INT count
, HKL
*layouts
)
179 static BOOL
nulldrv_GetKeyboardLayoutName( LPWSTR name
)
184 static HKL
nulldrv_LoadKeyboardLayout( LPCWSTR name
, UINT flags
)
189 static UINT
nulldrv_MapVirtualKeyEx( UINT code
, UINT type
, HKL layout
)
194 static UINT
nulldrv_SendInput( UINT count
, LPINPUT inputs
, int size
)
199 static INT
nulldrv_ToUnicodeEx( UINT virt
, UINT scan
, LPBYTE state
, LPWSTR str
,
200 int size
, UINT flags
, HKL layout
)
205 static BOOL
nulldrv_UnloadKeyboardLayout( HKL layout
)
210 static SHORT
nulldrv_VkKeyScanEx( WCHAR ch
, HKL layout
)
215 static void nulldrv_SetCursor( struct tagCURSORICONINFO
*info
)
219 static BOOL
nulldrv_GetCursorPos( LPPOINT pt
)
224 static BOOL
nulldrv_SetCursorPos( INT x
, INT y
)
229 static BOOL
nulldrv_GetScreenSaveActive(void)
234 static void nulldrv_SetScreenSaveActive( BOOL on
)
238 static void nulldrv_AcquireClipboard( HWND hwnd
)
242 static BOOL
nulldrv_CountClipboardFormats(void)
247 static void nulldrv_EmptyClipboard( BOOL keepunowned
)
251 static void nulldrv_EndClipboardUpdate(void)
255 static UINT
nulldrv_EnumClipboardFormats( UINT format
)
260 static BOOL
nulldrv_GetClipboardData( UINT format
, HANDLE16
*h16
, HANDLE
*h32
)
265 static INT
nulldrv_GetClipboardFormatName( UINT format
, LPWSTR buffer
, UINT len
)
270 static BOOL
nulldrv_IsClipboardFormatAvailable( UINT format
)
275 static UINT
nulldrv_RegisterClipboardFormat( LPCWSTR name
)
280 static void nulldrv_ResetSelectionOwner( HWND hwnd
, BOOL flag
)
284 static BOOL
nulldrv_SetClipboardData( UINT format
, HANDLE16 h16
, HANDLE h32
, BOOL owner
)
289 static LONG
nulldrv_ChangeDisplaySettingsEx( LPCWSTR name
, LPDEVMODEW mode
, HWND hwnd
,
290 DWORD flags
, LPVOID lparam
)
292 return DISP_CHANGE_FAILED
;
295 static BOOL
nulldrv_EnumDisplaySettingsEx( LPCWSTR name
, DWORD num
, LPDEVMODEW mode
, DWORD flags
)
300 static BOOL
nulldrv_CreateDesktopWindow( HWND hwnd
)
305 static BOOL
nulldrv_CreateWindow( HWND hwnd
, CREATESTRUCTA
*cs
, BOOL unicode
)
310 MESSAGE( "Application tries to create a window, but no driver could be loaded.\n"
311 "Make sure that your X server is running and that $DISPLAY is set correctly.\n" );
315 static void nulldrv_DestroyWindow( HWND hwnd
)
319 static HDC
nulldrv_GetDCEx( HWND hwnd
, HRGN hrgn
, DWORD flags
)
324 static DWORD
nulldrv_MsgWaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
, DWORD timeout
,
325 DWORD mask
, DWORD flags
)
327 return WaitForMultipleObjectsEx( count
, handles
, flags
& MWMO_WAITALL
,
328 timeout
, flags
& MWMO_ALERTABLE
);
331 static INT
nulldrv_ReleaseDC( HWND hwnd
, HDC hdc
, BOOL end_paint
)
336 static BOOL
nulldrv_ScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*scroll
, const RECT
*clip
,
337 HRGN hrgn
, LPRECT update
)
342 static void nulldrv_SetFocus( HWND hwnd
)
346 static HWND
nulldrv_SetParent( HWND hwnd
, HWND parent
)
351 static BOOL
nulldrv_SetWindowPos( WINDOWPOS
*pos
)
356 static int nulldrv_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
361 static void nulldrv_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
365 static void nulldrv_SetWindowStyle( HWND hwnd
, DWORD old_style
)
369 static void nulldrv_SetWindowText( HWND hwnd
, LPCWSTR text
)
373 static BOOL
nulldrv_ShowWindow( HWND hwnd
, INT cmd
)
378 static void nulldrv_SysCommandSizeMove( HWND hwnd
, WPARAM wparam
)
382 static HWND
nulldrv_WindowFromDC( HDC hdc
)
387 static LRESULT
nulldrv_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
392 static const USER_DRIVER null_driver
=
394 /* keyboard functions */
395 nulldrv_ActivateKeyboardLayout
,
397 nulldrv_GetAsyncKeyState
,
398 nulldrv_GetKeyNameText
,
399 nulldrv_GetKeyboardLayout
,
400 nulldrv_GetKeyboardLayoutList
,
401 nulldrv_GetKeyboardLayoutName
,
402 nulldrv_LoadKeyboardLayout
,
403 nulldrv_MapVirtualKeyEx
,
406 nulldrv_UnloadKeyboardLayout
,
408 /* mouse functions */
410 nulldrv_GetCursorPos
,
411 nulldrv_SetCursorPos
,
412 /* screen saver functions */
413 nulldrv_GetScreenSaveActive
,
414 nulldrv_SetScreenSaveActive
,
415 /* clipboard functions */
416 nulldrv_AcquireClipboard
,
417 nulldrv_CountClipboardFormats
,
418 nulldrv_EmptyClipboard
,
419 nulldrv_EndClipboardUpdate
,
420 nulldrv_EnumClipboardFormats
,
421 nulldrv_GetClipboardData
,
422 nulldrv_GetClipboardFormatName
,
423 nulldrv_IsClipboardFormatAvailable
,
424 nulldrv_RegisterClipboardFormat
,
425 nulldrv_ResetSelectionOwner
,
426 nulldrv_SetClipboardData
,
428 nulldrv_ChangeDisplaySettingsEx
,
429 nulldrv_EnumDisplaySettingsEx
,
430 /* windowing functions */
431 nulldrv_CreateDesktopWindow
,
432 nulldrv_CreateWindow
,
433 nulldrv_DestroyWindow
,
435 nulldrv_MsgWaitForMultipleObjectsEx
,
440 nulldrv_SetWindowPos
,
441 nulldrv_SetWindowRgn
,
442 nulldrv_SetWindowIcon
,
443 nulldrv_SetWindowStyle
,
444 nulldrv_SetWindowText
,
446 nulldrv_SysCommandSizeMove
,
447 nulldrv_WindowFromDC
,
448 nulldrv_WindowMessage
452 /**********************************************************************
453 * Lazy loading user driver
455 * Initial driver used before another driver is loaded.
456 * Each entry point simply loads the real driver and chains to it.
459 static HKL
loaderdrv_ActivateKeyboardLayout( HKL layout
, UINT flags
)
461 return load_driver()->pActivateKeyboardLayout( layout
, flags
);
464 static void loaderdrv_Beep(void)
466 load_driver()->pBeep();
469 static SHORT
loaderdrv_GetAsyncKeyState( INT key
)
471 return load_driver()->pGetAsyncKeyState( key
);
474 static INT
loaderdrv_GetKeyNameText( LONG lparam
, LPWSTR buffer
, INT size
)
476 return load_driver()->pGetKeyNameText( lparam
, buffer
, size
);
479 static HKL
loaderdrv_GetKeyboardLayout( DWORD layout
)
481 return load_driver()->pGetKeyboardLayout( layout
);
484 static UINT
loaderdrv_GetKeyboardLayoutList( INT count
, HKL
*layouts
)
486 return load_driver()->pGetKeyboardLayoutList( count
, layouts
);
489 static BOOL
loaderdrv_GetKeyboardLayoutName( LPWSTR name
)
491 return load_driver()->pGetKeyboardLayoutName( name
);
494 static HKL
loaderdrv_LoadKeyboardLayout( LPCWSTR name
, UINT flags
)
496 return load_driver()->pLoadKeyboardLayout( name
, flags
);
499 static UINT
loaderdrv_MapVirtualKeyEx( UINT code
, UINT type
, HKL layout
)
501 return load_driver()->pMapVirtualKeyEx( code
, type
, layout
);
504 static UINT
loaderdrv_SendInput( UINT count
, LPINPUT inputs
, int size
)
506 return load_driver()->pSendInput( count
, inputs
, size
);
509 static INT
loaderdrv_ToUnicodeEx( UINT virt
, UINT scan
, LPBYTE state
, LPWSTR str
,
510 int size
, UINT flags
, HKL layout
)
512 return load_driver()->pToUnicodeEx( virt
, scan
, state
, str
, size
, flags
, layout
);
515 static BOOL
loaderdrv_UnloadKeyboardLayout( HKL layout
)
517 return load_driver()->pUnloadKeyboardLayout( layout
);
520 static SHORT
loaderdrv_VkKeyScanEx( WCHAR ch
, HKL layout
)
522 return load_driver()->pVkKeyScanEx( ch
, layout
);
525 static void loaderdrv_SetCursor( struct tagCURSORICONINFO
*info
)
527 load_driver()->pSetCursor( info
);
530 static BOOL
loaderdrv_GetCursorPos( LPPOINT pt
)
532 return load_driver()->pGetCursorPos( pt
);
535 static BOOL
loaderdrv_SetCursorPos( INT x
, INT y
)
537 return load_driver()->pSetCursorPos( x
, y
);
540 static BOOL
loaderdrv_GetScreenSaveActive(void)
542 return load_driver()->pGetScreenSaveActive();
545 static void loaderdrv_SetScreenSaveActive( BOOL on
)
547 load_driver()->pSetScreenSaveActive( on
);
550 static void loaderdrv_AcquireClipboard( HWND hwnd
)
552 load_driver()->pAcquireClipboard( hwnd
);
555 static BOOL
loaderdrv_CountClipboardFormats(void)
557 return load_driver()->pCountClipboardFormats();
560 static void loaderdrv_EmptyClipboard( BOOL keepunowned
)
562 load_driver()->pEmptyClipboard( keepunowned
);
565 static void loaderdrv_EndClipboardUpdate(void)
567 load_driver()->pEndClipboardUpdate();
570 static UINT
loaderdrv_EnumClipboardFormats( UINT format
)
572 return load_driver()->pEnumClipboardFormats( format
);
575 static BOOL
loaderdrv_GetClipboardData( UINT format
, HANDLE16
*h16
, HANDLE
*h32
)
577 return load_driver()->pGetClipboardData( format
, h16
, h32
);
580 static INT
loaderdrv_GetClipboardFormatName( UINT format
, LPWSTR buffer
, UINT len
)
582 return load_driver()->pGetClipboardFormatName( format
, buffer
, len
);
585 static BOOL
loaderdrv_IsClipboardFormatAvailable( UINT format
)
587 return load_driver()->pIsClipboardFormatAvailable( format
);
590 static UINT
loaderdrv_RegisterClipboardFormat( LPCWSTR name
)
592 return load_driver()->pRegisterClipboardFormat( name
);
595 static void loaderdrv_ResetSelectionOwner( HWND hwnd
, BOOL flag
)
597 load_driver()->pResetSelectionOwner( hwnd
, flag
);
600 static BOOL
loaderdrv_SetClipboardData( UINT format
, HANDLE16 h16
, HANDLE h32
, BOOL owner
)
602 return load_driver()->pSetClipboardData( format
, h16
, h32
, owner
);
605 static LONG
loaderdrv_ChangeDisplaySettingsEx( LPCWSTR name
, LPDEVMODEW mode
, HWND hwnd
,
606 DWORD flags
, LPVOID lparam
)
608 return load_driver()->pChangeDisplaySettingsEx( name
, mode
, hwnd
, flags
, lparam
);
611 static BOOL
loaderdrv_EnumDisplaySettingsEx( LPCWSTR name
, DWORD num
, LPDEVMODEW mode
, DWORD flags
)
613 return load_driver()->pEnumDisplaySettingsEx( name
, num
, mode
, flags
);
616 static BOOL
loaderdrv_CreateDesktopWindow( HWND hwnd
)
618 return load_driver()->pCreateDesktopWindow( hwnd
);
621 static BOOL
loaderdrv_CreateWindow( HWND hwnd
, CREATESTRUCTA
*cs
, BOOL unicode
)
623 return load_driver()->pCreateWindow( hwnd
, cs
, unicode
);
626 static void loaderdrv_DestroyWindow( HWND hwnd
)
628 load_driver()->pDestroyWindow( hwnd
);
631 static HDC
loaderdrv_GetDCEx( HWND hwnd
, HRGN hrgn
, DWORD flags
)
633 return load_driver()->pGetDCEx( hwnd
, hrgn
, flags
);
636 static DWORD
loaderdrv_MsgWaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
, DWORD timeout
,
637 DWORD mask
, DWORD flags
)
639 return load_driver()->pMsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
, flags
);
642 static INT
loaderdrv_ReleaseDC( HWND hwnd
, HDC hdc
, BOOL end_paint
)
644 return load_driver()->pReleaseDC( hwnd
, hdc
, end_paint
);
647 static BOOL
loaderdrv_ScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*scroll
, const RECT
*clip
,
648 HRGN hrgn
, LPRECT update
)
650 return load_driver()->pScrollDC( hdc
, dx
, dy
, scroll
, clip
, hrgn
, update
);
653 static void loaderdrv_SetFocus( HWND hwnd
)
655 load_driver()->pSetFocus( hwnd
);
658 static HWND
loaderdrv_SetParent( HWND hwnd
, HWND parent
)
660 return load_driver()->pSetParent( hwnd
, parent
);
663 static BOOL
loaderdrv_SetWindowPos( WINDOWPOS
*pos
)
665 return load_driver()->pSetWindowPos( pos
);
668 static int loaderdrv_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
670 return load_driver()->pSetWindowRgn( hwnd
, hrgn
, redraw
);
673 static void loaderdrv_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
675 load_driver()->pSetWindowIcon( hwnd
, type
, icon
);
678 static void loaderdrv_SetWindowStyle( HWND hwnd
, DWORD old_style
)
680 load_driver()->pSetWindowStyle( hwnd
, old_style
);
683 static void loaderdrv_SetWindowText( HWND hwnd
, LPCWSTR text
)
685 load_driver()->pSetWindowText( hwnd
, text
);
688 static BOOL
loaderdrv_ShowWindow( HWND hwnd
, INT cmd
)
690 return load_driver()->pShowWindow( hwnd
, cmd
);
693 static void loaderdrv_SysCommandSizeMove( HWND hwnd
, WPARAM wparam
)
695 load_driver()->pSysCommandSizeMove( hwnd
, wparam
);
698 static HWND
loaderdrv_WindowFromDC( HDC hdc
)
700 return load_driver()->pWindowFromDC( hdc
);
703 static LRESULT
loaderdrv_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
705 return load_driver()->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
708 static const USER_DRIVER lazy_load_driver
=
710 /* keyboard functions */
711 loaderdrv_ActivateKeyboardLayout
,
713 loaderdrv_GetAsyncKeyState
,
714 loaderdrv_GetKeyNameText
,
715 loaderdrv_GetKeyboardLayout
,
716 loaderdrv_GetKeyboardLayoutList
,
717 loaderdrv_GetKeyboardLayoutName
,
718 loaderdrv_LoadKeyboardLayout
,
719 loaderdrv_MapVirtualKeyEx
,
721 loaderdrv_ToUnicodeEx
,
722 loaderdrv_UnloadKeyboardLayout
,
723 loaderdrv_VkKeyScanEx
,
724 /* mouse functions */
726 loaderdrv_GetCursorPos
,
727 loaderdrv_SetCursorPos
,
728 /* screen saver functions */
729 loaderdrv_GetScreenSaveActive
,
730 loaderdrv_SetScreenSaveActive
,
731 /* clipboard functions */
732 loaderdrv_AcquireClipboard
,
733 loaderdrv_CountClipboardFormats
,
734 loaderdrv_EmptyClipboard
,
735 loaderdrv_EndClipboardUpdate
,
736 loaderdrv_EnumClipboardFormats
,
737 loaderdrv_GetClipboardData
,
738 loaderdrv_GetClipboardFormatName
,
739 loaderdrv_IsClipboardFormatAvailable
,
740 loaderdrv_RegisterClipboardFormat
,
741 loaderdrv_ResetSelectionOwner
,
742 loaderdrv_SetClipboardData
,
744 loaderdrv_ChangeDisplaySettingsEx
,
745 loaderdrv_EnumDisplaySettingsEx
,
746 /* windowing functions */
747 loaderdrv_CreateDesktopWindow
,
748 loaderdrv_CreateWindow
,
749 loaderdrv_DestroyWindow
,
751 loaderdrv_MsgWaitForMultipleObjectsEx
,
756 loaderdrv_SetWindowPos
,
757 loaderdrv_SetWindowRgn
,
758 loaderdrv_SetWindowIcon
,
759 loaderdrv_SetWindowStyle
,
760 loaderdrv_SetWindowText
,
761 loaderdrv_ShowWindow
,
762 loaderdrv_SysCommandSizeMove
,
763 loaderdrv_WindowFromDC
,
764 loaderdrv_WindowMessage