2000-03-19 12:08:09 +00:00
|
|
|
/*
|
|
|
|
* USER initialization code
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-03-19 12:08:09 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
2001-01-22 02:17:29 +00:00
|
|
|
#include <string.h>
|
2000-03-19 12:08:09 +00:00
|
|
|
#include "windef.h"
|
2000-12-19 04:53:20 +00:00
|
|
|
#include "winbase.h"
|
2000-03-19 12:08:09 +00:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2000-08-03 00:04:24 +00:00
|
|
|
#include "winreg.h"
|
2000-03-19 12:08:09 +00:00
|
|
|
#include "wine/winbase16.h"
|
2000-09-16 20:57:39 +00:00
|
|
|
#include "wine/winuser16.h"
|
2000-03-19 12:08:09 +00:00
|
|
|
|
2000-12-10 23:01:33 +00:00
|
|
|
#include "controls.h"
|
2000-03-19 12:08:09 +00:00
|
|
|
#include "message.h"
|
2004-12-08 18:06:14 +00:00
|
|
|
#include "user_private.h"
|
2000-03-19 12:08:09 +00:00
|
|
|
#include "win.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
2000-08-03 00:04:24 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(graphics);
|
2000-08-10 01:16:19 +00:00
|
|
|
|
|
|
|
USER_DRIVER USER_Driver;
|
|
|
|
|
2001-03-23 19:13:23 +00:00
|
|
|
WORD USER_HeapSel = 0; /* USER heap selector */
|
2004-02-12 00:35:01 +00:00
|
|
|
HMODULE user32_module = 0;
|
2001-03-23 19:13:23 +00:00
|
|
|
|
2004-12-08 14:12:09 +00:00
|
|
|
static HPALETTE (WINAPI *pfnGDISelectPalette)( HDC hdc, HPALETTE hpal, WORD bkgnd );
|
|
|
|
static UINT (WINAPI *pfnGDIRealizePalette)( HDC hdc );
|
|
|
|
static HPALETTE hPrimaryPalette;
|
2002-10-18 04:05:49 +00:00
|
|
|
|
2000-08-10 01:16:19 +00:00
|
|
|
static HMODULE graphics_driver;
|
2001-10-16 21:58:58 +00:00
|
|
|
static DWORD exiting_thread_id;
|
2000-08-10 01:16:19 +00:00
|
|
|
|
2001-10-16 21:58:58 +00:00
|
|
|
extern void WDML_NotifyThreadDetach(void);
|
2001-07-24 20:49:41 +00:00
|
|
|
|
2001-06-29 01:26:41 +00:00
|
|
|
#define GET_USER_FUNC(name) USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name )
|
2000-08-03 00:04:24 +00:00
|
|
|
|
|
|
|
/* load the graphics driver */
|
|
|
|
static BOOL load_driver(void)
|
|
|
|
{
|
2004-07-13 03:53:55 +00:00
|
|
|
char buffer[MAX_PATH], *name, *next;
|
2000-08-03 00:04:24 +00:00
|
|
|
HKEY hkey;
|
|
|
|
|
2004-07-13 03:53:55 +00:00
|
|
|
strcpy( buffer, "x11drv,ttydrv" ); /* default value */
|
2001-03-23 19:13:23 +00:00
|
|
|
if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
|
2000-08-03 00:04:24 +00:00
|
|
|
{
|
2004-07-13 03:53:55 +00:00
|
|
|
DWORD type, count = sizeof(buffer);
|
2001-03-23 19:13:23 +00:00
|
|
|
RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
|
|
|
|
RegCloseKey( hkey );
|
2000-08-03 00:04:24 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 03:53:55 +00:00
|
|
|
name = buffer;
|
|
|
|
while (name)
|
2000-08-03 00:04:24 +00:00
|
|
|
{
|
2004-07-13 03:53:55 +00:00
|
|
|
next = strchr( name, ',' );
|
|
|
|
if (next) *next++ = 0;
|
|
|
|
|
|
|
|
if ((graphics_driver = LoadLibraryA( name )) != 0) break;
|
|
|
|
name = next;
|
|
|
|
}
|
|
|
|
if (!graphics_driver)
|
|
|
|
{
|
|
|
|
MESSAGE( "wine: Could not load graphics driver '%s'.\n", buffer );
|
|
|
|
if (!strcasecmp( buffer, "x11drv" ))
|
|
|
|
MESSAGE( "Make sure that your X server is running and that $DISPLAY is set correctly.\n" );
|
|
|
|
ExitProcess(1);
|
2000-08-03 00:04:24 +00:00
|
|
|
}
|
2000-08-10 01:16:19 +00:00
|
|
|
|
2005-03-09 16:45:23 +00:00
|
|
|
GET_USER_FUNC(ActivateKeyboardLayout);
|
|
|
|
GET_USER_FUNC(Beep);
|
|
|
|
GET_USER_FUNC(GetAsyncKeyState);
|
2000-08-10 01:16:19 +00:00
|
|
|
GET_USER_FUNC(GetKeyNameText);
|
2003-11-14 03:32:43 +00:00
|
|
|
GET_USER_FUNC(GetKeyboardLayout);
|
2005-03-09 16:45:23 +00:00
|
|
|
GET_USER_FUNC(GetKeyboardLayoutList);
|
2003-11-14 03:32:43 +00:00
|
|
|
GET_USER_FUNC(GetKeyboardLayoutName);
|
|
|
|
GET_USER_FUNC(LoadKeyboardLayout);
|
2005-03-09 16:45:23 +00:00
|
|
|
GET_USER_FUNC(MapVirtualKeyEx);
|
|
|
|
GET_USER_FUNC(SendInput);
|
|
|
|
GET_USER_FUNC(ToUnicodeEx);
|
2003-11-14 03:32:43 +00:00
|
|
|
GET_USER_FUNC(UnloadKeyboardLayout);
|
2005-03-09 16:45:23 +00:00
|
|
|
GET_USER_FUNC(VkKeyScanEx);
|
2000-08-10 01:16:19 +00:00
|
|
|
GET_USER_FUNC(SetCursor);
|
2001-06-21 00:44:09 +00:00
|
|
|
GET_USER_FUNC(GetCursorPos);
|
|
|
|
GET_USER_FUNC(SetCursorPos);
|
2000-08-10 01:16:19 +00:00
|
|
|
GET_USER_FUNC(GetScreenSaveActive);
|
|
|
|
GET_USER_FUNC(SetScreenSaveActive);
|
|
|
|
GET_USER_FUNC(AcquireClipboard);
|
2003-06-23 23:02:02 +00:00
|
|
|
GET_USER_FUNC(EmptyClipboard);
|
2000-08-10 01:16:19 +00:00
|
|
|
GET_USER_FUNC(SetClipboardData);
|
|
|
|
GET_USER_FUNC(GetClipboardData);
|
2003-06-23 23:02:02 +00:00
|
|
|
GET_USER_FUNC(CountClipboardFormats);
|
|
|
|
GET_USER_FUNC(EnumClipboardFormats);
|
2000-08-10 01:16:19 +00:00
|
|
|
GET_USER_FUNC(IsClipboardFormatAvailable);
|
|
|
|
GET_USER_FUNC(RegisterClipboardFormat);
|
2002-08-27 19:19:49 +00:00
|
|
|
GET_USER_FUNC(GetClipboardFormatName);
|
2003-06-23 23:02:02 +00:00
|
|
|
GET_USER_FUNC(EndClipboardUpdate);
|
2000-08-10 01:16:19 +00:00
|
|
|
GET_USER_FUNC(ResetSelectionOwner);
|
2003-04-22 00:15:48 +00:00
|
|
|
GET_USER_FUNC(ChangeDisplaySettingsExW);
|
|
|
|
GET_USER_FUNC(EnumDisplaySettingsExW);
|
2001-04-24 23:28:52 +00:00
|
|
|
GET_USER_FUNC(CreateWindow);
|
|
|
|
GET_USER_FUNC(DestroyWindow);
|
|
|
|
GET_USER_FUNC(GetDC);
|
2001-05-18 22:51:56 +00:00
|
|
|
GET_USER_FUNC(MsgWaitForMultipleObjectsEx);
|
2002-11-14 22:30:20 +00:00
|
|
|
GET_USER_FUNC(ReleaseDC);
|
2004-06-15 17:04:02 +00:00
|
|
|
GET_USER_FUNC(ScrollDC);
|
2001-04-24 23:28:52 +00:00
|
|
|
GET_USER_FUNC(SetFocus);
|
|
|
|
GET_USER_FUNC(SetParent);
|
|
|
|
GET_USER_FUNC(SetWindowPos);
|
|
|
|
GET_USER_FUNC(SetWindowRgn);
|
|
|
|
GET_USER_FUNC(SetWindowIcon);
|
2001-10-03 18:44:02 +00:00
|
|
|
GET_USER_FUNC(SetWindowStyle);
|
2001-04-24 23:28:52 +00:00
|
|
|
GET_USER_FUNC(SetWindowText);
|
2001-06-04 21:55:17 +00:00
|
|
|
GET_USER_FUNC(ShowWindow);
|
2001-05-09 17:21:04 +00:00
|
|
|
GET_USER_FUNC(SysCommandSizeMove);
|
2005-03-07 17:19:24 +00:00
|
|
|
GET_USER_FUNC(WindowMessage);
|
2000-08-10 01:16:19 +00:00
|
|
|
|
2000-08-03 00:04:24 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2000-03-19 12:08:09 +00:00
|
|
|
|
|
|
|
|
2004-12-08 14:12:09 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* UserSelectPalette (Not a Windows API)
|
|
|
|
*/
|
|
|
|
static HPALETTE WINAPI UserSelectPalette( HDC hDC, HPALETTE hPal, BOOL bForceBackground )
|
|
|
|
{
|
|
|
|
WORD wBkgPalette = 1;
|
|
|
|
|
|
|
|
if (!bForceBackground && (hPal != GetStockObject(DEFAULT_PALETTE)))
|
|
|
|
{
|
|
|
|
HWND hwnd = WindowFromDC( hDC );
|
|
|
|
if (hwnd)
|
|
|
|
{
|
|
|
|
HWND hForeground = GetForegroundWindow();
|
|
|
|
/* set primary palette if it's related to current active */
|
|
|
|
if (hForeground == hwnd || IsChild(hForeground,hwnd))
|
|
|
|
{
|
|
|
|
wBkgPalette = 0;
|
|
|
|
hPrimaryPalette = hPal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pfnGDISelectPalette( hDC, hPal, wBkgPalette);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UserRealizePalette (USER32.@)
|
|
|
|
*/
|
|
|
|
UINT WINAPI UserRealizePalette( HDC hDC )
|
|
|
|
{
|
|
|
|
UINT realized = pfnGDIRealizePalette( hDC );
|
|
|
|
|
|
|
|
/* do not send anything if no colors were changed */
|
|
|
|
if (realized && GetCurrentObject( hDC, OBJ_PAL ) == hPrimaryPalette)
|
|
|
|
{
|
|
|
|
/* send palette change notification */
|
|
|
|
HWND hWnd = WindowFromDC( hDC );
|
|
|
|
if (hWnd) SendMessageTimeoutW( HWND_BROADCAST, WM_PALETTECHANGED, (WPARAM)hWnd, 0,
|
|
|
|
SMTO_ABORTIFHUNG, 2000, NULL );
|
|
|
|
}
|
|
|
|
return realized;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-16 20:57:39 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* palette_init
|
|
|
|
*
|
|
|
|
* Patch the function pointers in GDI for SelectPalette and RealizePalette
|
|
|
|
*/
|
|
|
|
static void palette_init(void)
|
|
|
|
{
|
|
|
|
void **ptr;
|
|
|
|
HMODULE module = GetModuleHandleA( "gdi32" );
|
|
|
|
if (!module)
|
|
|
|
{
|
|
|
|
ERR( "cannot get GDI32 handle\n" );
|
|
|
|
return;
|
|
|
|
}
|
2002-10-18 04:05:49 +00:00
|
|
|
if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" )))
|
2004-12-08 14:12:09 +00:00
|
|
|
pfnGDISelectPalette = InterlockedExchangePointer( ptr, UserSelectPalette );
|
2000-09-16 20:57:39 +00:00
|
|
|
else ERR( "cannot find pfnSelectPalette in GDI32\n" );
|
2002-10-18 04:05:49 +00:00
|
|
|
if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" )))
|
|
|
|
pfnGDIRealizePalette = InterlockedExchangePointer( ptr, UserRealizePalette );
|
2000-09-16 20:57:39 +00:00
|
|
|
else ERR( "cannot find pfnRealizePalette in GDI32\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-19 12:08:09 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* USER initialisation routine
|
|
|
|
*/
|
2004-02-12 00:35:01 +00:00
|
|
|
static BOOL process_attach(void)
|
2000-03-19 12:08:09 +00:00
|
|
|
{
|
2000-05-07 18:41:15 +00:00
|
|
|
HINSTANCE16 instance;
|
2000-03-19 12:08:09 +00:00
|
|
|
|
|
|
|
/* Create USER heap */
|
2002-10-02 02:36:20 +00:00
|
|
|
if ((instance = LoadLibrary16( "USER.EXE" )) >= 32) USER_HeapSel = instance | 7;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 65536 );
|
|
|
|
LocalInit16( USER_HeapSel, 32, 65534 );
|
|
|
|
}
|
2000-03-19 12:08:09 +00:00
|
|
|
|
2004-04-21 22:30:08 +00:00
|
|
|
/* some Win9x dlls expect keyboard to be loaded */
|
|
|
|
if (GetVersion() & 0x80000000) LoadLibrary16( "keyboard.drv" );
|
|
|
|
|
2000-08-03 00:04:24 +00:00
|
|
|
/* Load the graphics driver */
|
|
|
|
if (!load_driver()) return FALSE;
|
|
|
|
|
2002-05-20 18:01:44 +00:00
|
|
|
/* Initialize system colors and metrics */
|
2004-12-09 13:48:56 +00:00
|
|
|
SYSPARAMS_Init();
|
2000-03-19 12:08:09 +00:00
|
|
|
|
2000-09-16 20:57:39 +00:00
|
|
|
/* Setup palette function pointers */
|
|
|
|
palette_init();
|
|
|
|
|
2000-03-19 12:08:09 +00:00
|
|
|
/* Initialize built-in window classes */
|
2004-02-12 00:35:01 +00:00
|
|
|
CLASS_RegisterBuiltinClasses();
|
2000-03-19 12:08:09 +00:00
|
|
|
|
|
|
|
/* Initialize menus */
|
|
|
|
if (!MENU_Init()) return FALSE;
|
|
|
|
|
|
|
|
/* Initialize message spying */
|
|
|
|
if (!SPY_Init()) return FALSE;
|
|
|
|
|
|
|
|
/* Create message queue of initial thread */
|
|
|
|
InitThreadInput16( 0, 0 );
|
|
|
|
|
|
|
|
/* Create desktop window */
|
|
|
|
if (!WIN_CreateDesktopWindow()) return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-05-16 19:52:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-10-16 21:58:58 +00:00
|
|
|
* USER_IsExitingThread
|
|
|
|
*/
|
|
|
|
BOOL USER_IsExitingThread( DWORD tid )
|
|
|
|
{
|
|
|
|
return (tid == exiting_thread_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* thread_detach
|
2001-05-16 19:52:29 +00:00
|
|
|
*/
|
|
|
|
static void thread_detach(void)
|
|
|
|
{
|
2001-10-16 21:58:58 +00:00
|
|
|
exiting_thread_id = GetCurrentThreadId();
|
|
|
|
|
2001-08-09 22:07:22 +00:00
|
|
|
WDML_NotifyThreadDetach();
|
|
|
|
|
2002-10-29 21:32:37 +00:00
|
|
|
WIN_DestroyThreadWindows( GetDesktopWindow() );
|
|
|
|
QUEUE_DeleteMsgQueue();
|
2001-05-16 19:52:29 +00:00
|
|
|
|
2001-10-16 21:58:58 +00:00
|
|
|
exiting_thread_id = 0;
|
2001-05-16 19:52:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-18 21:25:26 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* process_detach
|
|
|
|
*/
|
|
|
|
static void process_detach(void)
|
|
|
|
{
|
|
|
|
memset(&USER_Driver, 0, sizeof(USER_Driver));
|
|
|
|
FreeLibrary(graphics_driver);
|
|
|
|
}
|
|
|
|
|
2001-05-16 19:52:29 +00:00
|
|
|
/***********************************************************************
|
2001-10-08 20:42:14 +00:00
|
|
|
* UserClientDllInitialize (USER32.@)
|
|
|
|
*
|
2003-10-10 04:30:54 +00:00
|
|
|
* USER dll initialisation routine (exported as UserClientDllInitialize for compatibility).
|
2001-05-16 19:52:29 +00:00
|
|
|
*/
|
2003-10-10 04:30:54 +00:00
|
|
|
BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
|
2001-05-16 19:52:29 +00:00
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
switch(reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2004-02-12 00:35:01 +00:00
|
|
|
user32_module = inst;
|
|
|
|
ret = process_attach();
|
2001-05-16 19:52:29 +00:00
|
|
|
break;
|
2004-10-18 21:25:26 +00:00
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
process_detach();
|
|
|
|
break;
|
2001-05-16 19:52:29 +00:00
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
thread_detach();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|