- Add a max wait time for selection notifies.
[wine.git] / dlls / user / user_main.c
blobd406e34aeee303cbe0e5a8d08059006ad7bc7001
1 /*
2 * USER initialization code
4 * Copyright 2000 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
21 #include <string.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winuser.h"
26 #include "winreg.h"
27 #include "wine/winbase16.h"
28 #include "wine/winuser16.h"
30 #include "controls.h"
31 #include "cursoricon.h"
32 #include "global.h"
33 #include "input.h"
34 #include "hook.h"
35 #include "message.h"
36 #include "queue.h"
37 #include "spy.h"
38 #include "sysmetrics.h"
39 #include "user.h"
40 #include "win.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
45 USER_DRIVER USER_Driver;
47 WINE_LOOK TWEAK_WineLook = WIN31_LOOK;
49 WORD USER_HeapSel = 0; /* USER heap selector */
51 static HMODULE graphics_driver;
52 static DWORD exiting_thread_id;
54 extern void COMM_Init(void);
55 extern void WDML_NotifyThreadDetach(void);
57 #define GET_USER_FUNC(name) USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name )
59 /* load the graphics driver */
60 static BOOL load_driver(void)
62 char buffer[MAX_PATH];
63 HKEY hkey;
64 DWORD type, count;
66 strcpy( buffer, "x11drv" ); /* default value */
67 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
69 count = sizeof(buffer);
70 RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
71 RegCloseKey( hkey );
74 if (!(graphics_driver = LoadLibraryA( buffer )))
76 MESSAGE( "Could not load graphics driver '%s'\n", buffer );
77 return FALSE;
80 GET_USER_FUNC(InitKeyboard);
81 GET_USER_FUNC(VkKeyScan);
82 GET_USER_FUNC(MapVirtualKey);
83 GET_USER_FUNC(GetKeyNameText);
84 GET_USER_FUNC(ToUnicode);
85 GET_USER_FUNC(Beep);
86 GET_USER_FUNC(InitMouse);
87 GET_USER_FUNC(SetCursor);
88 GET_USER_FUNC(GetCursorPos);
89 GET_USER_FUNC(SetCursorPos);
90 GET_USER_FUNC(GetScreenSaveActive);
91 GET_USER_FUNC(SetScreenSaveActive);
92 GET_USER_FUNC(AcquireClipboard);
93 GET_USER_FUNC(ReleaseClipboard);
94 GET_USER_FUNC(SetClipboardData);
95 GET_USER_FUNC(GetClipboardData);
96 GET_USER_FUNC(IsClipboardFormatAvailable);
97 GET_USER_FUNC(RegisterClipboardFormat);
98 GET_USER_FUNC(GetClipboardFormatName);
99 GET_USER_FUNC(IsSelectionOwner);
100 GET_USER_FUNC(ResetSelectionOwner);
101 GET_USER_FUNC(CreateWindow);
102 GET_USER_FUNC(DestroyWindow);
103 GET_USER_FUNC(GetDC);
104 GET_USER_FUNC(ForceWindowRaise);
105 GET_USER_FUNC(MsgWaitForMultipleObjectsEx);
106 GET_USER_FUNC(ScrollDC);
107 GET_USER_FUNC(ScrollWindowEx);
108 GET_USER_FUNC(SetFocus);
109 GET_USER_FUNC(SetParent);
110 GET_USER_FUNC(SetWindowPos);
111 GET_USER_FUNC(SetWindowRgn);
112 GET_USER_FUNC(SetWindowIcon);
113 GET_USER_FUNC(SetWindowStyle);
114 GET_USER_FUNC(SetWindowText);
115 GET_USER_FUNC(ShowWindow);
116 GET_USER_FUNC(SysCommandSizeMove);
118 return TRUE;
122 /***********************************************************************
123 * controls_init
125 * Register the classes for the builtin controls
127 static void controls_init(void)
129 extern const struct builtin_class_descr BUTTON_builtin_class;
130 extern const struct builtin_class_descr COMBO_builtin_class;
131 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
132 extern const struct builtin_class_descr DIALOG_builtin_class;
133 extern const struct builtin_class_descr DESKTOP_builtin_class;
134 extern const struct builtin_class_descr EDIT_builtin_class;
135 extern const struct builtin_class_descr ICONTITLE_builtin_class;
136 extern const struct builtin_class_descr LISTBOX_builtin_class;
137 extern const struct builtin_class_descr MDICLIENT_builtin_class;
138 extern const struct builtin_class_descr MENU_builtin_class;
139 extern const struct builtin_class_descr SCROLL_builtin_class;
140 extern const struct builtin_class_descr STATIC_builtin_class;
142 CLASS_RegisterBuiltinClass( &BUTTON_builtin_class );
143 CLASS_RegisterBuiltinClass( &COMBO_builtin_class );
144 CLASS_RegisterBuiltinClass( &COMBOLBOX_builtin_class );
145 CLASS_RegisterBuiltinClass( &DIALOG_builtin_class );
146 CLASS_RegisterBuiltinClass( &DESKTOP_builtin_class );
147 CLASS_RegisterBuiltinClass( &EDIT_builtin_class );
148 CLASS_RegisterBuiltinClass( &ICONTITLE_builtin_class );
149 CLASS_RegisterBuiltinClass( &LISTBOX_builtin_class );
150 CLASS_RegisterBuiltinClass( &MDICLIENT_builtin_class );
151 CLASS_RegisterBuiltinClass( &MENU_builtin_class );
152 CLASS_RegisterBuiltinClass( &SCROLL_builtin_class );
153 CLASS_RegisterBuiltinClass( &STATIC_builtin_class );
157 /***********************************************************************
158 * palette_init
160 * Patch the function pointers in GDI for SelectPalette and RealizePalette
162 static void palette_init(void)
164 void **ptr;
165 HMODULE module = GetModuleHandleA( "gdi32" );
166 if (!module)
168 ERR( "cannot get GDI32 handle\n" );
169 return;
171 if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" ))) *ptr = SelectPalette16;
172 else ERR( "cannot find pfnSelectPalette in GDI32\n" );
173 if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" ))) *ptr = UserRealizePalette;
174 else ERR( "cannot find pfnRealizePalette in GDI32\n" );
178 /***********************************************************************
179 * tweak_init
181 static void tweak_init(void)
183 static const char *OS = "Win3.1";
184 char buffer[80];
185 HKEY hkey;
186 DWORD type, count = sizeof(buffer);
188 if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Layout", &hkey ))
189 return;
190 if (RegQueryValueExA( hkey, "WineLook", 0, &type, buffer, &count ))
191 strcpy( buffer, "Win31" ); /* default value */
192 RegCloseKey( hkey );
194 /* WIN31_LOOK is default */
195 if (!strncasecmp( buffer, "Win95", 5 ))
197 TWEAK_WineLook = WIN95_LOOK;
198 OS = "Win95";
200 else if (!strncasecmp( buffer, "Win98", 5 ))
202 TWEAK_WineLook = WIN98_LOOK;
203 OS = "Win98";
205 TRACE("Using %s look and feel.\n", OS);
209 /***********************************************************************
210 * USER initialisation routine
212 static BOOL process_attach(void)
214 HINSTANCE16 instance;
216 /* Create USER heap */
217 if ((instance = LoadLibrary16( "USER.EXE" )) < 32) return FALSE;
218 USER_HeapSel = instance | 7;
220 /* Global atom table initialisation */
221 if (!ATOM_Init( USER_HeapSel )) return FALSE;
223 /* Load the graphics driver */
224 tweak_init();
225 if (!load_driver()) return FALSE;
227 /* Initialize system colors and metrics */
228 SYSMETRICS_Init();
229 SYSCOLOR_Init();
231 /* Setup palette function pointers */
232 palette_init();
234 /* Initialize window procedures */
235 if (!WINPROC_Init()) return FALSE;
237 /* Initialize built-in window classes */
238 controls_init();
240 /* Initialize dialog manager */
241 if (!DIALOG_Init()) return FALSE;
243 /* Initialize menus */
244 if (!MENU_Init()) return FALSE;
246 /* Initialize message spying */
247 if (!SPY_Init()) return FALSE;
249 /* Create message queue of initial thread */
250 InitThreadInput16( 0, 0 );
252 /* Create desktop window */
253 if (!WIN_CreateDesktopWindow()) return FALSE;
255 /* Initialize keyboard driver */
256 if (USER_Driver.pInitKeyboard) USER_Driver.pInitKeyboard( InputKeyStateTable );
258 /* Initialize mouse driver */
259 if (USER_Driver.pInitMouse) USER_Driver.pInitMouse( InputKeyStateTable );
261 /* Initialize 16-bit serial communications */
262 COMM_Init();
264 return TRUE;
268 /**********************************************************************
269 * USER_IsExitingThread
271 BOOL USER_IsExitingThread( DWORD tid )
273 return (tid == exiting_thread_id);
277 /**********************************************************************
278 * thread_detach
280 static void thread_detach(void)
282 HQUEUE16 hQueue = GetThreadQueue16( 0 );
284 exiting_thread_id = GetCurrentThreadId();
286 WDML_NotifyThreadDetach();
288 if (hQueue)
290 TIMER_RemoveQueueTimers( hQueue );
291 HOOK_FreeQueueHooks();
292 WIN_DestroyThreadWindows( GetDesktopWindow() );
293 QUEUE_DeleteMsgQueue();
296 if (!(NtCurrentTeb()->tibflags & TEBF_WIN32))
298 HMODULE16 hModule = GetExePtr( MapHModuleLS(0) );
300 /* FIXME: maybe destroy menus (Windows only complains about them
301 * but does nothing);
303 if (GetModuleUsage16( hModule ) <= 1)
305 /* ModuleUnload() in "Internals" */
306 HOOK_FreeModuleHooks( hModule );
307 CLASS_FreeModuleClasses( hModule );
308 CURSORICON_FreeModuleIcons( hModule );
311 exiting_thread_id = 0;
315 /***********************************************************************
316 * UserClientDllInitialize (USER32.@)
318 * USER dll initialisation routine
320 BOOL WINAPI UserClientDllInitialize( HINSTANCE inst, DWORD reason, LPVOID reserved )
322 BOOL ret = TRUE;
323 switch(reason)
325 case DLL_PROCESS_ATTACH:
326 ret = process_attach();
327 break;
328 case DLL_THREAD_DETACH:
329 thread_detach();
330 break;
332 return ret;