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,tty" ); /* 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;
66 MESSAGE( "wine: Could not load graphics driver '%s'.\n", buffer
);
67 if (!strcasecmp( buffer
, "x11" ))
68 MESSAGE( "Make sure that your X server is running and that $DISPLAY is set correctly.\n" );
72 driver
= HeapAlloc( GetProcessHeap(), 0, sizeof(*driver
) );
73 memcpy( driver
, &null_driver
, sizeof(*driver
) );
75 #define GET_USER_FUNC(name) \
76 do { if ((ptr = GetProcAddress( graphics_driver, #name ))) driver->p##name = ptr; } while(0)
78 GET_USER_FUNC(ActivateKeyboardLayout
);
80 GET_USER_FUNC(GetAsyncKeyState
);
81 GET_USER_FUNC(GetKeyNameText
);
82 GET_USER_FUNC(GetKeyboardLayout
);
83 GET_USER_FUNC(GetKeyboardLayoutList
);
84 GET_USER_FUNC(GetKeyboardLayoutName
);
85 GET_USER_FUNC(LoadKeyboardLayout
);
86 GET_USER_FUNC(MapVirtualKeyEx
);
87 GET_USER_FUNC(SendInput
);
88 GET_USER_FUNC(ToUnicodeEx
);
89 GET_USER_FUNC(UnloadKeyboardLayout
);
90 GET_USER_FUNC(VkKeyScanEx
);
91 GET_USER_FUNC(SetCursor
);
92 GET_USER_FUNC(GetCursorPos
);
93 GET_USER_FUNC(SetCursorPos
);
94 GET_USER_FUNC(GetScreenSaveActive
);
95 GET_USER_FUNC(SetScreenSaveActive
);
96 GET_USER_FUNC(AcquireClipboard
);
97 GET_USER_FUNC(EmptyClipboard
);
98 GET_USER_FUNC(SetClipboardData
);
99 GET_USER_FUNC(GetClipboardData
);
100 GET_USER_FUNC(CountClipboardFormats
);
101 GET_USER_FUNC(EnumClipboardFormats
);
102 GET_USER_FUNC(IsClipboardFormatAvailable
);
103 GET_USER_FUNC(RegisterClipboardFormat
);
104 GET_USER_FUNC(GetClipboardFormatName
);
105 GET_USER_FUNC(EndClipboardUpdate
);
106 GET_USER_FUNC(ResetSelectionOwner
);
107 GET_USER_FUNC(ChangeDisplaySettingsEx
);
108 GET_USER_FUNC(EnumDisplaySettingsEx
);
109 GET_USER_FUNC(CreateDesktopWindow
);
110 GET_USER_FUNC(CreateWindow
);
111 GET_USER_FUNC(DestroyWindow
);
112 GET_USER_FUNC(GetDCEx
);
113 GET_USER_FUNC(MsgWaitForMultipleObjectsEx
);
114 GET_USER_FUNC(ReleaseDC
);
115 GET_USER_FUNC(ScrollDC
);
116 GET_USER_FUNC(SetFocus
);
117 GET_USER_FUNC(SetParent
);
118 GET_USER_FUNC(SetWindowPos
);
119 GET_USER_FUNC(SetWindowRgn
);
120 GET_USER_FUNC(SetWindowIcon
);
121 GET_USER_FUNC(SetWindowStyle
);
122 GET_USER_FUNC(SetWindowText
);
123 GET_USER_FUNC(ShowWindow
);
124 GET_USER_FUNC(SysCommandSizeMove
);
125 GET_USER_FUNC(WindowFromDC
);
126 GET_USER_FUNC(WindowMessage
);
129 prev
= InterlockedCompareExchangePointer( (void **)&USER_Driver
, driver
, (void *)&lazy_load_driver
);
130 if (prev
!= &lazy_load_driver
)
132 /* another thread beat us to it */
133 HeapFree( GetProcessHeap(), 0, driver
);
134 FreeLibrary( graphics_driver
);
140 /* unload the graphics driver on process exit */
141 void USER_unload_driver(void)
143 /* make sure we don't try to call the driver after it has been detached */
144 USER_Driver
= &null_driver
;
148 /**********************************************************************
151 * These are fallbacks for entry points that are not implemented in the real driver.
154 static HKL
nulldrv_ActivateKeyboardLayout( HKL layout
, UINT flags
)
159 static void nulldrv_Beep(void)
163 static SHORT
nulldrv_GetAsyncKeyState( INT key
)
168 static INT
nulldrv_GetKeyNameText( LONG lparam
, LPWSTR buffer
, INT size
)
173 static HKL
nulldrv_GetKeyboardLayout( DWORD layout
)
178 static UINT
nulldrv_GetKeyboardLayoutList( INT count
, HKL
*layouts
)
183 static BOOL
nulldrv_GetKeyboardLayoutName( LPWSTR name
)
188 static HKL
nulldrv_LoadKeyboardLayout( LPCWSTR name
, UINT flags
)
193 static UINT
nulldrv_MapVirtualKeyEx( UINT code
, UINT type
, HKL layout
)
198 static UINT
nulldrv_SendInput( UINT count
, LPINPUT inputs
, int size
)
203 static INT
nulldrv_ToUnicodeEx( UINT virt
, UINT scan
, LPBYTE state
, LPWSTR str
,
204 int size
, UINT flags
, HKL layout
)
209 static BOOL
nulldrv_UnloadKeyboardLayout( HKL layout
)
214 static SHORT
nulldrv_VkKeyScanEx( WCHAR ch
, HKL layout
)
219 static void nulldrv_SetCursor( struct tagCURSORICONINFO
*info
)
223 static BOOL
nulldrv_GetCursorPos( LPPOINT pt
)
228 static BOOL
nulldrv_SetCursorPos( INT x
, INT y
)
233 static BOOL
nulldrv_GetScreenSaveActive(void)
238 static void nulldrv_SetScreenSaveActive( BOOL on
)
242 static void nulldrv_AcquireClipboard( HWND hwnd
)
246 static BOOL
nulldrv_CountClipboardFormats(void)
251 static void nulldrv_EmptyClipboard( BOOL keepunowned
)
255 static void nulldrv_EndClipboardUpdate(void)
259 static UINT
nulldrv_EnumClipboardFormats( UINT format
)
264 static BOOL
nulldrv_GetClipboardData( UINT format
, HANDLE16
*h16
, HANDLE
*h32
)
269 static INT
nulldrv_GetClipboardFormatName( UINT format
, LPWSTR buffer
, UINT len
)
274 static BOOL
nulldrv_IsClipboardFormatAvailable( UINT format
)
279 static UINT
nulldrv_RegisterClipboardFormat( LPCWSTR name
)
284 static void nulldrv_ResetSelectionOwner( HWND hwnd
, BOOL flag
)
288 static BOOL
nulldrv_SetClipboardData( UINT format
, HANDLE16 h16
, HANDLE h32
, BOOL owner
)
293 static LONG
nulldrv_ChangeDisplaySettingsEx( LPCWSTR name
, LPDEVMODEW mode
, HWND hwnd
,
294 DWORD flags
, LPVOID lparam
)
296 return DISP_CHANGE_FAILED
;
299 static BOOL
nulldrv_EnumDisplaySettingsEx( LPCWSTR name
, DWORD num
, LPDEVMODEW mode
, DWORD flags
)
304 static BOOL
nulldrv_CreateDesktopWindow( HWND hwnd
)
309 static BOOL
nulldrv_CreateWindow( HWND hwnd
, CREATESTRUCTA
*cs
, BOOL unicode
)
314 static void nulldrv_DestroyWindow( HWND hwnd
)
318 static HDC
nulldrv_GetDCEx( HWND hwnd
, HRGN hrgn
, DWORD flags
)
323 static DWORD
nulldrv_MsgWaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
, DWORD timeout
,
324 DWORD mask
, DWORD flags
)
326 return WaitForMultipleObjectsEx( count
, handles
, flags
& MWMO_WAITALL
,
327 timeout
, flags
& MWMO_ALERTABLE
);
330 static INT
nulldrv_ReleaseDC( HWND hwnd
, HDC hdc
, BOOL end_paint
)
335 static BOOL
nulldrv_ScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*scroll
, const RECT
*clip
,
336 HRGN hrgn
, LPRECT update
)
341 static void nulldrv_SetFocus( HWND hwnd
)
345 static HWND
nulldrv_SetParent( HWND hwnd
, HWND parent
)
350 static BOOL
nulldrv_SetWindowPos( WINDOWPOS
*pos
)
355 static int nulldrv_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
360 static void nulldrv_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
364 static void nulldrv_SetWindowStyle( HWND hwnd
, DWORD old_style
)
368 static void nulldrv_SetWindowText( HWND hwnd
, LPCWSTR text
)
372 static BOOL
nulldrv_ShowWindow( HWND hwnd
, INT cmd
)
377 static void nulldrv_SysCommandSizeMove( HWND hwnd
, WPARAM wparam
)
381 static HWND
nulldrv_WindowFromDC( HDC hdc
)
386 static LRESULT
nulldrv_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
391 static const USER_DRIVER null_driver
=
393 /* keyboard functions */
394 nulldrv_ActivateKeyboardLayout
,
396 nulldrv_GetAsyncKeyState
,
397 nulldrv_GetKeyNameText
,
398 nulldrv_GetKeyboardLayout
,
399 nulldrv_GetKeyboardLayoutList
,
400 nulldrv_GetKeyboardLayoutName
,
401 nulldrv_LoadKeyboardLayout
,
402 nulldrv_MapVirtualKeyEx
,
405 nulldrv_UnloadKeyboardLayout
,
407 /* mouse functions */
409 nulldrv_GetCursorPos
,
410 nulldrv_SetCursorPos
,
411 /* screen saver functions */
412 nulldrv_GetScreenSaveActive
,
413 nulldrv_SetScreenSaveActive
,
414 /* clipboard functions */
415 nulldrv_AcquireClipboard
,
416 nulldrv_CountClipboardFormats
,
417 nulldrv_EmptyClipboard
,
418 nulldrv_EndClipboardUpdate
,
419 nulldrv_EnumClipboardFormats
,
420 nulldrv_GetClipboardData
,
421 nulldrv_GetClipboardFormatName
,
422 nulldrv_IsClipboardFormatAvailable
,
423 nulldrv_RegisterClipboardFormat
,
424 nulldrv_ResetSelectionOwner
,
425 nulldrv_SetClipboardData
,
427 nulldrv_ChangeDisplaySettingsEx
,
428 nulldrv_EnumDisplaySettingsEx
,
429 /* windowing functions */
430 nulldrv_CreateDesktopWindow
,
431 nulldrv_CreateWindow
,
432 nulldrv_DestroyWindow
,
434 nulldrv_MsgWaitForMultipleObjectsEx
,
439 nulldrv_SetWindowPos
,
440 nulldrv_SetWindowRgn
,
441 nulldrv_SetWindowIcon
,
442 nulldrv_SetWindowStyle
,
443 nulldrv_SetWindowText
,
445 nulldrv_SysCommandSizeMove
,
446 nulldrv_WindowFromDC
,
447 nulldrv_WindowMessage
451 /**********************************************************************
452 * Lazy loading user driver
454 * Initial driver used before another driver is loaded.
455 * Each entry point simply loads the real driver and chains to it.
458 static HKL
loaderdrv_ActivateKeyboardLayout( HKL layout
, UINT flags
)
460 return load_driver()->pActivateKeyboardLayout( layout
, flags
);
463 static void loaderdrv_Beep(void)
465 load_driver()->pBeep();
468 static SHORT
loaderdrv_GetAsyncKeyState( INT key
)
470 return load_driver()->pGetAsyncKeyState( key
);
473 static INT
loaderdrv_GetKeyNameText( LONG lparam
, LPWSTR buffer
, INT size
)
475 return load_driver()->pGetKeyNameText( lparam
, buffer
, size
);
478 static HKL
loaderdrv_GetKeyboardLayout( DWORD layout
)
480 return load_driver()->pGetKeyboardLayout( layout
);
483 static UINT
loaderdrv_GetKeyboardLayoutList( INT count
, HKL
*layouts
)
485 return load_driver()->pGetKeyboardLayoutList( count
, layouts
);
488 static BOOL
loaderdrv_GetKeyboardLayoutName( LPWSTR name
)
490 return load_driver()->pGetKeyboardLayoutName( name
);
493 static HKL
loaderdrv_LoadKeyboardLayout( LPCWSTR name
, UINT flags
)
495 return load_driver()->pLoadKeyboardLayout( name
, flags
);
498 static UINT
loaderdrv_MapVirtualKeyEx( UINT code
, UINT type
, HKL layout
)
500 return load_driver()->pMapVirtualKeyEx( code
, type
, layout
);
503 static UINT
loaderdrv_SendInput( UINT count
, LPINPUT inputs
, int size
)
505 return load_driver()->pSendInput( count
, inputs
, size
);
508 static INT
loaderdrv_ToUnicodeEx( UINT virt
, UINT scan
, LPBYTE state
, LPWSTR str
,
509 int size
, UINT flags
, HKL layout
)
511 return load_driver()->pToUnicodeEx( virt
, scan
, state
, str
, size
, flags
, layout
);
514 static BOOL
loaderdrv_UnloadKeyboardLayout( HKL layout
)
516 return load_driver()->pUnloadKeyboardLayout( layout
);
519 static SHORT
loaderdrv_VkKeyScanEx( WCHAR ch
, HKL layout
)
521 return load_driver()->pVkKeyScanEx( ch
, layout
);
524 static void loaderdrv_SetCursor( struct tagCURSORICONINFO
*info
)
526 load_driver()->pSetCursor( info
);
529 static BOOL
loaderdrv_GetCursorPos( LPPOINT pt
)
531 return load_driver()->pGetCursorPos( pt
);
534 static BOOL
loaderdrv_SetCursorPos( INT x
, INT y
)
536 return load_driver()->pSetCursorPos( x
, y
);
539 static BOOL
loaderdrv_GetScreenSaveActive(void)
541 return load_driver()->pGetScreenSaveActive();
544 static void loaderdrv_SetScreenSaveActive( BOOL on
)
546 load_driver()->pSetScreenSaveActive( on
);
549 static void loaderdrv_AcquireClipboard( HWND hwnd
)
551 load_driver()->pAcquireClipboard( hwnd
);
554 static BOOL
loaderdrv_CountClipboardFormats(void)
556 return load_driver()->pCountClipboardFormats();
559 static void loaderdrv_EmptyClipboard( BOOL keepunowned
)
561 load_driver()->pEmptyClipboard( keepunowned
);
564 static void loaderdrv_EndClipboardUpdate(void)
566 load_driver()->pEndClipboardUpdate();
569 static UINT
loaderdrv_EnumClipboardFormats( UINT format
)
571 return load_driver()->pEnumClipboardFormats( format
);
574 static BOOL
loaderdrv_GetClipboardData( UINT format
, HANDLE16
*h16
, HANDLE
*h32
)
576 return load_driver()->pGetClipboardData( format
, h16
, h32
);
579 static INT
loaderdrv_GetClipboardFormatName( UINT format
, LPWSTR buffer
, UINT len
)
581 return load_driver()->pGetClipboardFormatName( format
, buffer
, len
);
584 static BOOL
loaderdrv_IsClipboardFormatAvailable( UINT format
)
586 return load_driver()->pIsClipboardFormatAvailable( format
);
589 static UINT
loaderdrv_RegisterClipboardFormat( LPCWSTR name
)
591 return load_driver()->pRegisterClipboardFormat( name
);
594 static void loaderdrv_ResetSelectionOwner( HWND hwnd
, BOOL flag
)
596 load_driver()->pResetSelectionOwner( hwnd
, flag
);
599 static BOOL
loaderdrv_SetClipboardData( UINT format
, HANDLE16 h16
, HANDLE h32
, BOOL owner
)
601 return load_driver()->pSetClipboardData( format
, h16
, h32
, owner
);
604 static LONG
loaderdrv_ChangeDisplaySettingsEx( LPCWSTR name
, LPDEVMODEW mode
, HWND hwnd
,
605 DWORD flags
, LPVOID lparam
)
607 return load_driver()->pChangeDisplaySettingsEx( name
, mode
, hwnd
, flags
, lparam
);
610 static BOOL
loaderdrv_EnumDisplaySettingsEx( LPCWSTR name
, DWORD num
, LPDEVMODEW mode
, DWORD flags
)
612 return load_driver()->pEnumDisplaySettingsEx( name
, num
, mode
, flags
);
615 static BOOL
loaderdrv_CreateDesktopWindow( HWND hwnd
)
617 return load_driver()->pCreateDesktopWindow( hwnd
);
620 static BOOL
loaderdrv_CreateWindow( HWND hwnd
, CREATESTRUCTA
*cs
, BOOL unicode
)
622 return load_driver()->pCreateWindow( hwnd
, cs
, unicode
);
625 static void loaderdrv_DestroyWindow( HWND hwnd
)
627 load_driver()->pDestroyWindow( hwnd
);
630 static HDC
loaderdrv_GetDCEx( HWND hwnd
, HRGN hrgn
, DWORD flags
)
632 return load_driver()->pGetDCEx( hwnd
, hrgn
, flags
);
635 static DWORD
loaderdrv_MsgWaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
, DWORD timeout
,
636 DWORD mask
, DWORD flags
)
638 return load_driver()->pMsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
, flags
);
641 static INT
loaderdrv_ReleaseDC( HWND hwnd
, HDC hdc
, BOOL end_paint
)
643 return load_driver()->pReleaseDC( hwnd
, hdc
, end_paint
);
646 static BOOL
loaderdrv_ScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*scroll
, const RECT
*clip
,
647 HRGN hrgn
, LPRECT update
)
649 return load_driver()->pScrollDC( hdc
, dx
, dy
, scroll
, clip
, hrgn
, update
);
652 static void loaderdrv_SetFocus( HWND hwnd
)
654 load_driver()->pSetFocus( hwnd
);
657 static HWND
loaderdrv_SetParent( HWND hwnd
, HWND parent
)
659 return load_driver()->pSetParent( hwnd
, parent
);
662 static BOOL
loaderdrv_SetWindowPos( WINDOWPOS
*pos
)
664 return load_driver()->pSetWindowPos( pos
);
667 static int loaderdrv_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
669 return load_driver()->pSetWindowRgn( hwnd
, hrgn
, redraw
);
672 static void loaderdrv_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
674 load_driver()->pSetWindowIcon( hwnd
, type
, icon
);
677 static void loaderdrv_SetWindowStyle( HWND hwnd
, DWORD old_style
)
679 load_driver()->pSetWindowStyle( hwnd
, old_style
);
682 static void loaderdrv_SetWindowText( HWND hwnd
, LPCWSTR text
)
684 load_driver()->pSetWindowText( hwnd
, text
);
687 static BOOL
loaderdrv_ShowWindow( HWND hwnd
, INT cmd
)
689 return load_driver()->pShowWindow( hwnd
, cmd
);
692 static void loaderdrv_SysCommandSizeMove( HWND hwnd
, WPARAM wparam
)
694 load_driver()->pSysCommandSizeMove( hwnd
, wparam
);
697 static HWND
loaderdrv_WindowFromDC( HDC hdc
)
699 return load_driver()->pWindowFromDC( hdc
);
702 static LRESULT
loaderdrv_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
704 return load_driver()->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
707 static const USER_DRIVER lazy_load_driver
=
709 /* keyboard functions */
710 loaderdrv_ActivateKeyboardLayout
,
712 loaderdrv_GetAsyncKeyState
,
713 loaderdrv_GetKeyNameText
,
714 loaderdrv_GetKeyboardLayout
,
715 loaderdrv_GetKeyboardLayoutList
,
716 loaderdrv_GetKeyboardLayoutName
,
717 loaderdrv_LoadKeyboardLayout
,
718 loaderdrv_MapVirtualKeyEx
,
720 loaderdrv_ToUnicodeEx
,
721 loaderdrv_UnloadKeyboardLayout
,
722 loaderdrv_VkKeyScanEx
,
723 /* mouse functions */
725 loaderdrv_GetCursorPos
,
726 loaderdrv_SetCursorPos
,
727 /* screen saver functions */
728 loaderdrv_GetScreenSaveActive
,
729 loaderdrv_SetScreenSaveActive
,
730 /* clipboard functions */
731 loaderdrv_AcquireClipboard
,
732 loaderdrv_CountClipboardFormats
,
733 loaderdrv_EmptyClipboard
,
734 loaderdrv_EndClipboardUpdate
,
735 loaderdrv_EnumClipboardFormats
,
736 loaderdrv_GetClipboardData
,
737 loaderdrv_GetClipboardFormatName
,
738 loaderdrv_IsClipboardFormatAvailable
,
739 loaderdrv_RegisterClipboardFormat
,
740 loaderdrv_ResetSelectionOwner
,
741 loaderdrv_SetClipboardData
,
743 loaderdrv_ChangeDisplaySettingsEx
,
744 loaderdrv_EnumDisplaySettingsEx
,
745 /* windowing functions */
746 loaderdrv_CreateDesktopWindow
,
747 loaderdrv_CreateWindow
,
748 loaderdrv_DestroyWindow
,
750 loaderdrv_MsgWaitForMultipleObjectsEx
,
755 loaderdrv_SetWindowPos
,
756 loaderdrv_SetWindowRgn
,
757 loaderdrv_SetWindowIcon
,
758 loaderdrv_SetWindowStyle
,
759 loaderdrv_SetWindowText
,
760 loaderdrv_ShowWindow
,
761 loaderdrv_SysCommandSizeMove
,
762 loaderdrv_WindowFromDC
,
763 loaderdrv_WindowMessage