Added internal Wine messages to perform SetWindowPos, ShowWindow and
[wine/multimedia.git] / dlls / user / user_main.c
bloba4fa0277b30714b35cc2dc0a88af4c4172ddd5bf
1 /*
2 * USER initialization code
3 */
5 #include <string.h>
6 #include "windef.h"
7 #include "winbase.h"
8 #include "wingdi.h"
9 #include "winuser.h"
10 #include "winreg.h"
11 #include "wine/winbase16.h"
12 #include "wine/winuser16.h"
14 #include "controls.h"
15 #include "cursoricon.h"
16 #include "global.h"
17 #include "input.h"
18 #include "hook.h"
19 #include "keyboard.h"
20 #include "message.h"
21 #include "queue.h"
22 #include "spy.h"
23 #include "sysmetrics.h"
24 #include "user.h"
25 #include "win.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];
48 HKEY hkey;
49 DWORD type, count;
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 );
56 RegCloseKey( hkey );
59 if (!(graphics_driver = LoadLibraryA( buffer )))
61 MESSAGE( "Could not load graphics driver '%s'\n", buffer );
62 return FALSE;
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);
70 GET_USER_FUNC(Beep);
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);
92 GET_USER_FUNC(GetDC);
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);
108 return TRUE;
112 /***********************************************************************
113 * controls_init
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 /***********************************************************************
148 * palette_init
150 * Patch the function pointers in GDI for SelectPalette and RealizePalette
152 static void palette_init(void)
154 void **ptr;
155 HMODULE module = GetModuleHandleA( "gdi32" );
156 if (!module)
158 ERR( "cannot get GDI32 handle\n" );
159 return;
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 /***********************************************************************
169 * tweak_init
171 static void tweak_init(void)
173 static const char *OS = "Win3.1";
174 char buffer[80];
175 HKEY hkey;
176 DWORD type, count = sizeof(buffer);
178 if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Layout", &hkey ))
179 return;
180 if (RegQueryValueExA( hkey, "WineLook", 0, &type, buffer, &count ))
181 strcpy( buffer, "Win31" ); /* default value */
182 RegCloseKey( hkey );
184 /* WIN31_LOOK is default */
185 if (!strncasecmp( buffer, "Win95", 5 ))
187 TWEAK_WineLook = WIN95_LOOK;
188 OS = "Win95";
190 else if (!strncasecmp( buffer, "Win98", 5 ))
192 TWEAK_WineLook = WIN98_LOOK;
193 OS = "Win98";
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 */
214 tweak_init();
215 if (!load_driver()) return FALSE;
217 /* Initialize system colors and metrics*/
218 SYSMETRICS_Init();
219 SYSCOLOR_Init();
221 /* Setup palette function pointers */
222 palette_init();
224 /* Initialize window procedures */
225 if (!WINPROC_Init()) return FALSE;
227 /* Initialize built-in window classes */
228 controls_init();
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 */
255 COMM_Init();
257 return TRUE;
261 /**********************************************************************
262 * USER_IsExitingThread
264 BOOL USER_IsExitingThread( DWORD tid )
266 return (tid == exiting_thread_id);
270 /**********************************************************************
271 * thread_detach
273 static void thread_detach(void)
275 HQUEUE16 hQueue = GetThreadQueue16( 0 );
277 exiting_thread_id = GetCurrentThreadId();
279 WDML_NotifyThreadDetach();
281 if (hQueue)
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
294 * but does nothing);
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 )
315 BOOL ret = TRUE;
316 switch(reason)
318 case DLL_PROCESS_ATTACH:
319 ret = process_attach();
320 break;
321 case DLL_THREAD_DETACH:
322 thread_detach();
323 break;
325 return ret;