2000-03-19 13:08:09 +01:00
|
|
|
/*
|
|
|
|
* USER initialization code
|
2002-03-10 00:29:33 +01: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 13:08:09 +01:00
|
|
|
*/
|
|
|
|
|
2001-01-22 03:17:29 +01:00
|
|
|
#include <string.h>
|
2000-03-19 13:08:09 +01:00
|
|
|
#include "windef.h"
|
2000-12-19 05:53:20 +01:00
|
|
|
#include "winbase.h"
|
2000-03-19 13:08:09 +01:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2000-08-03 02:04:24 +02:00
|
|
|
#include "winreg.h"
|
2000-03-19 13:08:09 +01:00
|
|
|
#include "wine/winbase16.h"
|
2000-09-16 22:57:39 +02:00
|
|
|
#include "wine/winuser16.h"
|
2000-03-19 13:08:09 +01:00
|
|
|
|
2000-12-11 00:01:33 +01:00
|
|
|
#include "controls.h"
|
2001-05-16 21:52:29 +02:00
|
|
|
#include "cursoricon.h"
|
2000-03-19 13:08:09 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "message.h"
|
|
|
|
#include "queue.h"
|
|
|
|
#include "spy.h"
|
|
|
|
#include "sysmetrics.h"
|
|
|
|
#include "user.h"
|
|
|
|
#include "win.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-08-03 02:04:24 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(graphics);
|
2000-08-10 03:16:19 +02:00
|
|
|
|
|
|
|
USER_DRIVER USER_Driver;
|
|
|
|
|
2001-01-15 21:12:55 +01:00
|
|
|
WINE_LOOK TWEAK_WineLook = WIN31_LOOK;
|
|
|
|
|
2001-03-23 20:13:23 +01:00
|
|
|
WORD USER_HeapSel = 0; /* USER heap selector */
|
|
|
|
|
2002-10-18 06:05:49 +02:00
|
|
|
extern HPALETTE (WINAPI *pfnGDISelectPalette)(HDC hdc, HPALETTE hpal, WORD bkgnd );
|
|
|
|
extern UINT (WINAPI *pfnGDIRealizePalette)(HDC hdc);
|
|
|
|
|
2000-08-10 03:16:19 +02:00
|
|
|
static HMODULE graphics_driver;
|
2001-10-16 23:58:58 +02:00
|
|
|
static DWORD exiting_thread_id;
|
2000-08-10 03:16:19 +02:00
|
|
|
|
2001-07-24 22:49:41 +02:00
|
|
|
extern void COMM_Init(void);
|
2001-10-16 23:58:58 +02:00
|
|
|
extern void WDML_NotifyThreadDetach(void);
|
2001-07-24 22:49:41 +02:00
|
|
|
|
2001-06-29 03:26:41 +02:00
|
|
|
#define GET_USER_FUNC(name) USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name )
|
2000-08-03 02:04:24 +02:00
|
|
|
|
|
|
|
/* load the graphics driver */
|
|
|
|
static BOOL load_driver(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
HKEY hkey;
|
|
|
|
DWORD type, count;
|
|
|
|
|
2001-03-23 20:13:23 +01:00
|
|
|
strcpy( buffer, "x11drv" ); /* default value */
|
|
|
|
if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
|
2000-08-03 02:04:24 +02:00
|
|
|
{
|
2001-03-23 20:13:23 +01:00
|
|
|
count = sizeof(buffer);
|
|
|
|
RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
|
|
|
|
RegCloseKey( hkey );
|
2000-08-03 02:04:24 +02:00
|
|
|
}
|
|
|
|
|
2000-08-10 03:16:19 +02:00
|
|
|
if (!(graphics_driver = LoadLibraryA( buffer )))
|
2000-08-03 02:04:24 +02:00
|
|
|
{
|
|
|
|
MESSAGE( "Could not load graphics driver '%s'\n", buffer );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-08-10 03:16:19 +02:00
|
|
|
|
|
|
|
GET_USER_FUNC(InitKeyboard);
|
|
|
|
GET_USER_FUNC(VkKeyScan);
|
|
|
|
GET_USER_FUNC(MapVirtualKey);
|
|
|
|
GET_USER_FUNC(GetKeyNameText);
|
2000-10-25 23:34:31 +02:00
|
|
|
GET_USER_FUNC(ToUnicode);
|
2000-08-10 03:16:19 +02:00
|
|
|
GET_USER_FUNC(Beep);
|
|
|
|
GET_USER_FUNC(InitMouse);
|
|
|
|
GET_USER_FUNC(SetCursor);
|
2001-06-21 02:44:09 +02:00
|
|
|
GET_USER_FUNC(GetCursorPos);
|
|
|
|
GET_USER_FUNC(SetCursorPos);
|
2000-08-10 03:16:19 +02:00
|
|
|
GET_USER_FUNC(GetScreenSaveActive);
|
|
|
|
GET_USER_FUNC(SetScreenSaveActive);
|
|
|
|
GET_USER_FUNC(AcquireClipboard);
|
|
|
|
GET_USER_FUNC(ReleaseClipboard);
|
|
|
|
GET_USER_FUNC(SetClipboardData);
|
|
|
|
GET_USER_FUNC(GetClipboardData);
|
|
|
|
GET_USER_FUNC(IsClipboardFormatAvailable);
|
|
|
|
GET_USER_FUNC(RegisterClipboardFormat);
|
2002-08-27 21:19:49 +02:00
|
|
|
GET_USER_FUNC(GetClipboardFormatName);
|
2000-08-10 03:16:19 +02:00
|
|
|
GET_USER_FUNC(IsSelectionOwner);
|
|
|
|
GET_USER_FUNC(ResetSelectionOwner);
|
2001-04-25 01:28:52 +02:00
|
|
|
GET_USER_FUNC(CreateWindow);
|
|
|
|
GET_USER_FUNC(DestroyWindow);
|
|
|
|
GET_USER_FUNC(GetDC);
|
2001-06-29 03:26:41 +02:00
|
|
|
GET_USER_FUNC(ForceWindowRaise);
|
2001-05-19 00:51:56 +02:00
|
|
|
GET_USER_FUNC(MsgWaitForMultipleObjectsEx);
|
2002-11-14 23:30:20 +01:00
|
|
|
GET_USER_FUNC(ReleaseDC);
|
2001-06-04 23:55:17 +02:00
|
|
|
GET_USER_FUNC(ScrollDC);
|
2001-05-10 05:23:59 +02:00
|
|
|
GET_USER_FUNC(ScrollWindowEx);
|
2001-04-25 01:28:52 +02:00
|
|
|
GET_USER_FUNC(SetFocus);
|
|
|
|
GET_USER_FUNC(SetParent);
|
|
|
|
GET_USER_FUNC(SetWindowPos);
|
|
|
|
GET_USER_FUNC(SetWindowRgn);
|
|
|
|
GET_USER_FUNC(SetWindowIcon);
|
2001-10-03 20:44:02 +02:00
|
|
|
GET_USER_FUNC(SetWindowStyle);
|
2001-04-25 01:28:52 +02:00
|
|
|
GET_USER_FUNC(SetWindowText);
|
2001-06-04 23:55:17 +02:00
|
|
|
GET_USER_FUNC(ShowWindow);
|
2001-05-09 19:21:04 +02:00
|
|
|
GET_USER_FUNC(SysCommandSizeMove);
|
2000-08-10 03:16:19 +02:00
|
|
|
|
2000-08-03 02:04:24 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2000-03-19 13:08:09 +01:00
|
|
|
|
|
|
|
|
2000-12-11 00:01:33 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* controls_init
|
|
|
|
*
|
|
|
|
* Register the classes for the builtin controls
|
|
|
|
*/
|
|
|
|
static void controls_init(void)
|
|
|
|
{
|
|
|
|
extern const struct builtin_class_descr BUTTON_builtin_class;
|
|
|
|
extern const struct builtin_class_descr COMBO_builtin_class;
|
|
|
|
extern const struct builtin_class_descr COMBOLBOX_builtin_class;
|
|
|
|
extern const struct builtin_class_descr DIALOG_builtin_class;
|
|
|
|
extern const struct builtin_class_descr DESKTOP_builtin_class;
|
|
|
|
extern const struct builtin_class_descr EDIT_builtin_class;
|
|
|
|
extern const struct builtin_class_descr ICONTITLE_builtin_class;
|
|
|
|
extern const struct builtin_class_descr LISTBOX_builtin_class;
|
|
|
|
extern const struct builtin_class_descr MDICLIENT_builtin_class;
|
|
|
|
extern const struct builtin_class_descr MENU_builtin_class;
|
|
|
|
extern const struct builtin_class_descr SCROLL_builtin_class;
|
|
|
|
extern const struct builtin_class_descr STATIC_builtin_class;
|
|
|
|
|
|
|
|
CLASS_RegisterBuiltinClass( &BUTTON_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &COMBO_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &COMBOLBOX_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &DIALOG_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &DESKTOP_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &EDIT_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &ICONTITLE_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &LISTBOX_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &MDICLIENT_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &MENU_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &SCROLL_builtin_class );
|
|
|
|
CLASS_RegisterBuiltinClass( &STATIC_builtin_class );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-16 22:57:39 +02: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 06:05:49 +02:00
|
|
|
if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" )))
|
|
|
|
pfnGDISelectPalette = InterlockedExchangePointer( ptr, SelectPalette );
|
2000-09-16 22:57:39 +02:00
|
|
|
else ERR( "cannot find pfnSelectPalette in GDI32\n" );
|
2002-10-18 06:05:49 +02:00
|
|
|
if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" )))
|
|
|
|
pfnGDIRealizePalette = InterlockedExchangePointer( ptr, UserRealizePalette );
|
2000-09-16 22:57:39 +02:00
|
|
|
else ERR( "cannot find pfnRealizePalette in GDI32\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-15 21:12:55 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* tweak_init
|
|
|
|
*/
|
|
|
|
static void tweak_init(void)
|
|
|
|
{
|
|
|
|
static const char *OS = "Win3.1";
|
|
|
|
char buffer[80];
|
|
|
|
HKEY hkey;
|
|
|
|
DWORD type, count = sizeof(buffer);
|
|
|
|
|
2001-03-23 20:13:23 +01:00
|
|
|
if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Layout", &hkey ))
|
2001-01-15 21:12:55 +01:00
|
|
|
return;
|
|
|
|
if (RegQueryValueExA( hkey, "WineLook", 0, &type, buffer, &count ))
|
|
|
|
strcpy( buffer, "Win31" ); /* default value */
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
|
|
|
|
/* WIN31_LOOK is default */
|
|
|
|
if (!strncasecmp( buffer, "Win95", 5 ))
|
|
|
|
{
|
|
|
|
TWEAK_WineLook = WIN95_LOOK;
|
|
|
|
OS = "Win95";
|
|
|
|
}
|
|
|
|
else if (!strncasecmp( buffer, "Win98", 5 ))
|
|
|
|
{
|
|
|
|
TWEAK_WineLook = WIN98_LOOK;
|
|
|
|
OS = "Win98";
|
|
|
|
}
|
|
|
|
TRACE("Using %s look and feel.\n", OS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-19 13:08:09 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* USER initialisation routine
|
|
|
|
*/
|
2001-05-16 21:52:29 +02:00
|
|
|
static BOOL process_attach(void)
|
2000-03-19 13:08:09 +01:00
|
|
|
{
|
2000-05-07 20:41:15 +02:00
|
|
|
HINSTANCE16 instance;
|
2000-03-19 13:08:09 +01:00
|
|
|
|
|
|
|
/* Create USER heap */
|
2002-10-02 04:36:20 +02: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 13:08:09 +01:00
|
|
|
|
2000-08-03 02:04:24 +02:00
|
|
|
/* Load the graphics driver */
|
2001-01-15 21:12:55 +01:00
|
|
|
tweak_init();
|
2000-08-03 02:04:24 +02:00
|
|
|
if (!load_driver()) return FALSE;
|
|
|
|
|
2002-05-20 20:01:44 +02:00
|
|
|
/* Initialize system colors and metrics */
|
2000-03-19 13:08:09 +01:00
|
|
|
SYSMETRICS_Init();
|
|
|
|
SYSCOLOR_Init();
|
|
|
|
|
2000-09-16 22:57:39 +02:00
|
|
|
/* Setup palette function pointers */
|
|
|
|
palette_init();
|
|
|
|
|
2000-03-19 13:08:09 +01:00
|
|
|
/* Initialize window procedures */
|
|
|
|
if (!WINPROC_Init()) return FALSE;
|
|
|
|
|
|
|
|
/* Initialize built-in window classes */
|
2000-12-11 00:01:33 +01:00
|
|
|
controls_init();
|
2000-03-19 13:08:09 +01:00
|
|
|
|
|
|
|
/* Initialize dialog manager */
|
|
|
|
if (!DIALOG_Init()) return FALSE;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* Initialize keyboard driver */
|
2001-10-18 23:38:59 +02:00
|
|
|
if (USER_Driver.pInitKeyboard) USER_Driver.pInitKeyboard( InputKeyStateTable );
|
2000-03-19 13:08:09 +01:00
|
|
|
|
|
|
|
/* Initialize mouse driver */
|
2001-10-18 23:38:59 +02:00
|
|
|
if (USER_Driver.pInitMouse) USER_Driver.pInitMouse( InputKeyStateTable );
|
2000-03-19 13:08:09 +01:00
|
|
|
|
2001-07-24 22:49:41 +02:00
|
|
|
/* Initialize 16-bit serial communications */
|
|
|
|
COMM_Init();
|
|
|
|
|
2000-03-19 13:08:09 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2001-05-16 21:52:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-10-16 23:58:58 +02:00
|
|
|
* USER_IsExitingThread
|
|
|
|
*/
|
|
|
|
BOOL USER_IsExitingThread( DWORD tid )
|
|
|
|
{
|
|
|
|
return (tid == exiting_thread_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* thread_detach
|
2001-05-16 21:52:29 +02:00
|
|
|
*/
|
|
|
|
static void thread_detach(void)
|
|
|
|
{
|
2001-10-16 23:58:58 +02:00
|
|
|
exiting_thread_id = GetCurrentThreadId();
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_NotifyThreadDetach();
|
|
|
|
|
2002-10-29 22:32:37 +01:00
|
|
|
TIMER_RemoveThreadTimers();
|
|
|
|
WIN_DestroyThreadWindows( GetDesktopWindow() );
|
|
|
|
QUEUE_DeleteMsgQueue();
|
2001-05-16 21:52:29 +02:00
|
|
|
|
|
|
|
if (!(NtCurrentTeb()->tibflags & TEBF_WIN32))
|
|
|
|
{
|
|
|
|
HMODULE16 hModule = GetExePtr( MapHModuleLS(0) );
|
|
|
|
|
|
|
|
/* FIXME: maybe destroy menus (Windows only complains about them
|
|
|
|
* but does nothing);
|
|
|
|
*/
|
|
|
|
if (GetModuleUsage16( hModule ) <= 1)
|
|
|
|
{
|
|
|
|
/* ModuleUnload() in "Internals" */
|
2002-10-29 01:41:42 +01:00
|
|
|
/* HOOK_FreeModuleHooks( hModule ); */
|
2001-05-16 21:52:29 +02:00
|
|
|
CLASS_FreeModuleClasses( hModule );
|
|
|
|
CURSORICON_FreeModuleIcons( hModule );
|
|
|
|
}
|
|
|
|
}
|
2001-10-16 23:58:58 +02:00
|
|
|
exiting_thread_id = 0;
|
2001-05-16 21:52:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-10-08 22:42:14 +02:00
|
|
|
* UserClientDllInitialize (USER32.@)
|
|
|
|
*
|
|
|
|
* USER dll initialisation routine
|
2001-05-16 21:52:29 +02:00
|
|
|
*/
|
2001-10-08 22:42:14 +02:00
|
|
|
BOOL WINAPI UserClientDllInitialize( HINSTANCE inst, DWORD reason, LPVOID reserved )
|
2001-05-16 21:52:29 +02:00
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
switch(reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
ret = process_attach();
|
|
|
|
break;
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
thread_detach();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|