2 * USER initialization code
11 #include "wine/winbase16.h"
12 #include "wine/winuser16.h"
15 #include "cursoricon.h"
23 #include "sysmetrics.h"
26 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(graphics
);
30 USER_DRIVER USER_Driver
;
32 WINE_LOOK TWEAK_WineLook
= WIN31_LOOK
;
34 WORD USER_HeapSel
= 0; /* USER heap selector */
36 static HMODULE graphics_driver
;
37 static DWORD exiting_thread_id
;
39 extern void COMM_Init(void);
40 extern void WDML_NotifyThreadDetach(void);
42 #define GET_USER_FUNC(name) USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name )
44 /* load the graphics driver */
45 static BOOL
load_driver(void)
47 char buffer
[MAX_PATH
];
51 strcpy( buffer
, "x11drv" ); /* default value */
52 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\Wine", &hkey
))
54 count
= sizeof(buffer
);
55 RegQueryValueExA( hkey
, "GraphicsDriver", 0, &type
, buffer
, &count
);
59 if (!(graphics_driver
= LoadLibraryA( buffer
)))
61 MESSAGE( "Could not load graphics driver '%s'\n", buffer
);
65 GET_USER_FUNC(InitKeyboard
);
66 GET_USER_FUNC(VkKeyScan
);
67 GET_USER_FUNC(MapVirtualKey
);
68 GET_USER_FUNC(GetKeyNameText
);
69 GET_USER_FUNC(ToUnicode
);
71 GET_USER_FUNC(GetDIState
);
72 GET_USER_FUNC(GetDIData
);
73 GET_USER_FUNC(InitMouse
);
74 GET_USER_FUNC(SetCursor
);
75 GET_USER_FUNC(GetCursorPos
);
76 GET_USER_FUNC(SetCursorPos
);
77 GET_USER_FUNC(GetScreenSaveActive
);
78 GET_USER_FUNC(SetScreenSaveActive
);
79 GET_USER_FUNC(GetScreenSaveTimeout
);
80 GET_USER_FUNC(SetScreenSaveTimeout
);
81 GET_USER_FUNC(LoadOEMResource
);
82 GET_USER_FUNC(AcquireClipboard
);
83 GET_USER_FUNC(ReleaseClipboard
);
84 GET_USER_FUNC(SetClipboardData
);
85 GET_USER_FUNC(GetClipboardData
);
86 GET_USER_FUNC(IsClipboardFormatAvailable
);
87 GET_USER_FUNC(RegisterClipboardFormat
);
88 GET_USER_FUNC(IsSelectionOwner
);
89 GET_USER_FUNC(ResetSelectionOwner
);
90 GET_USER_FUNC(CreateWindow
);
91 GET_USER_FUNC(DestroyWindow
);
93 GET_USER_FUNC(EnableWindow
);
94 GET_USER_FUNC(ForceWindowRaise
);
95 GET_USER_FUNC(MsgWaitForMultipleObjectsEx
);
96 GET_USER_FUNC(ScrollDC
);
97 GET_USER_FUNC(ScrollWindowEx
);
98 GET_USER_FUNC(SetFocus
);
99 GET_USER_FUNC(SetParent
);
100 GET_USER_FUNC(SetWindowPos
);
101 GET_USER_FUNC(SetWindowRgn
);
102 GET_USER_FUNC(SetWindowIcon
);
103 GET_USER_FUNC(SetWindowStyle
);
104 GET_USER_FUNC(SetWindowText
);
105 GET_USER_FUNC(ShowWindow
);
106 GET_USER_FUNC(SysCommandSizeMove
);
112 /***********************************************************************
115 * Register the classes for the builtin controls
117 static void controls_init(void)
119 extern const struct builtin_class_descr BUTTON_builtin_class
;
120 extern const struct builtin_class_descr COMBO_builtin_class
;
121 extern const struct builtin_class_descr COMBOLBOX_builtin_class
;
122 extern const struct builtin_class_descr DIALOG_builtin_class
;
123 extern const struct builtin_class_descr DESKTOP_builtin_class
;
124 extern const struct builtin_class_descr EDIT_builtin_class
;
125 extern const struct builtin_class_descr ICONTITLE_builtin_class
;
126 extern const struct builtin_class_descr LISTBOX_builtin_class
;
127 extern const struct builtin_class_descr MDICLIENT_builtin_class
;
128 extern const struct builtin_class_descr MENU_builtin_class
;
129 extern const struct builtin_class_descr SCROLL_builtin_class
;
130 extern const struct builtin_class_descr STATIC_builtin_class
;
132 CLASS_RegisterBuiltinClass( &BUTTON_builtin_class
);
133 CLASS_RegisterBuiltinClass( &COMBO_builtin_class
);
134 CLASS_RegisterBuiltinClass( &COMBOLBOX_builtin_class
);
135 CLASS_RegisterBuiltinClass( &DIALOG_builtin_class
);
136 CLASS_RegisterBuiltinClass( &DESKTOP_builtin_class
);
137 CLASS_RegisterBuiltinClass( &EDIT_builtin_class
);
138 CLASS_RegisterBuiltinClass( &ICONTITLE_builtin_class
);
139 CLASS_RegisterBuiltinClass( &LISTBOX_builtin_class
);
140 CLASS_RegisterBuiltinClass( &MDICLIENT_builtin_class
);
141 CLASS_RegisterBuiltinClass( &MENU_builtin_class
);
142 CLASS_RegisterBuiltinClass( &SCROLL_builtin_class
);
143 CLASS_RegisterBuiltinClass( &STATIC_builtin_class
);
147 /***********************************************************************
150 * Patch the function pointers in GDI for SelectPalette and RealizePalette
152 static void palette_init(void)
155 HMODULE module
= GetModuleHandleA( "gdi32" );
158 ERR( "cannot get GDI32 handle\n" );
161 if ((ptr
= (void**)GetProcAddress( module
, "pfnSelectPalette" ))) *ptr
= SelectPalette16
;
162 else ERR( "cannot find pfnSelectPalette in GDI32\n" );
163 if ((ptr
= (void**)GetProcAddress( module
, "pfnRealizePalette" ))) *ptr
= UserRealizePalette
;
164 else ERR( "cannot find pfnRealizePalette in GDI32\n" );
168 /***********************************************************************
171 static void tweak_init(void)
173 static const char *OS
= "Win3.1";
176 DWORD type
, count
= sizeof(buffer
);
178 if (RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\Tweak.Layout", &hkey
))
180 if (RegQueryValueExA( hkey
, "WineLook", 0, &type
, buffer
, &count
))
181 strcpy( buffer
, "Win31" ); /* default value */
184 /* WIN31_LOOK is default */
185 if (!strncasecmp( buffer
, "Win95", 5 ))
187 TWEAK_WineLook
= WIN95_LOOK
;
190 else if (!strncasecmp( buffer
, "Win98", 5 ))
192 TWEAK_WineLook
= WIN98_LOOK
;
195 TRACE("Using %s look and feel.\n", OS
);
199 /***********************************************************************
200 * USER initialisation routine
202 static BOOL
process_attach(void)
204 HINSTANCE16 instance
;
206 /* Create USER heap */
207 if ((instance
= LoadLibrary16( "USER.EXE" )) < 32) return FALSE
;
208 USER_HeapSel
= instance
| 7;
210 /* Global atom table initialisation */
211 if (!ATOM_Init( USER_HeapSel
)) return FALSE
;
213 /* Load the graphics driver */
215 if (!load_driver()) return FALSE
;
217 /* Initialize system colors and metrics*/
221 /* Setup palette function pointers */
224 /* Initialize window procedures */
225 if (!WINPROC_Init()) return FALSE
;
227 /* Initialize built-in window classes */
230 /* Initialize dialog manager */
231 if (!DIALOG_Init()) return FALSE
;
233 /* Initialize menus */
234 if (!MENU_Init()) return FALSE
;
236 /* Initialize message spying */
237 if (!SPY_Init()) return FALSE
;
239 /* Set double click time */
240 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
242 /* Create message queue of initial thread */
243 InitThreadInput16( 0, 0 );
245 /* Create desktop window */
246 if (!WIN_CreateDesktopWindow()) return FALSE
;
248 /* Initialize keyboard driver */
249 KEYBOARD_Enable( keybd_event
, InputKeyStateTable
);
251 /* Initialize mouse driver */
252 MOUSE_Enable( mouse_event
);
254 /* Initialize 16-bit serial communications */
261 /**********************************************************************
262 * USER_IsExitingThread
264 BOOL
USER_IsExitingThread( DWORD tid
)
266 return (tid
== exiting_thread_id
);
270 /**********************************************************************
273 static void thread_detach(void)
275 HQUEUE16 hQueue
= GetThreadQueue16( 0 );
277 exiting_thread_id
= GetCurrentThreadId();
279 WDML_NotifyThreadDetach();
283 TIMER_RemoveQueueTimers( hQueue
);
284 HOOK_FreeQueueHooks();
285 WIN_DestroyThreadWindows( GetDesktopWindow() );
286 QUEUE_DeleteMsgQueue();
289 if (!(NtCurrentTeb()->tibflags
& TEBF_WIN32
))
291 HMODULE16 hModule
= GetExePtr( MapHModuleLS(0) );
293 /* FIXME: maybe destroy menus (Windows only complains about them
296 if (GetModuleUsage16( hModule
) <= 1)
298 /* ModuleUnload() in "Internals" */
299 HOOK_FreeModuleHooks( hModule
);
300 CLASS_FreeModuleClasses( hModule
);
301 CURSORICON_FreeModuleIcons( hModule
);
304 exiting_thread_id
= 0;
308 /***********************************************************************
309 * UserClientDllInitialize (USER32.@)
311 * USER dll initialisation routine
313 BOOL WINAPI
UserClientDllInitialize( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
318 case DLL_PROCESS_ATTACH
:
319 ret
= process_attach();
321 case DLL_THREAD_DETACH
: