We need to set _WIN32_WINNT to 0x501 to get CS_DROPSHADOW and
[wine] / dlls / user / user_main.c
1 /*
2  * USER initialization code
3  *
4  * Copyright 2000 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <string.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "wine/winbase16.h"
29 #include "wine/winuser16.h"
30
31 #include "controls.h"
32 #include "cursoricon.h"
33 #include "message.h"
34 #include "user.h"
35 #include "win.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
39
40 USER_DRIVER USER_Driver;
41
42 WINE_LOOK TWEAK_WineLook = WIN31_LOOK;
43
44 WORD USER_HeapSel = 0;  /* USER heap selector */
45
46 extern HPALETTE (WINAPI *pfnGDISelectPalette)(HDC hdc, HPALETTE hpal, WORD bkgnd );
47 extern UINT (WINAPI *pfnGDIRealizePalette)(HDC hdc);
48
49 static HMODULE graphics_driver;
50 static DWORD exiting_thread_id;
51
52 extern void WDML_NotifyThreadDetach(void);
53
54 #define GET_USER_FUNC(name) USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name )
55
56 /* load the graphics driver */
57 static BOOL load_driver(void)
58 {
59     char buffer[MAX_PATH];
60     HKEY hkey;
61     DWORD type, count;
62
63     strcpy( buffer, "x11drv" );  /* default value */
64     if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
65     {
66         count = sizeof(buffer);
67         RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
68         RegCloseKey( hkey );
69     }
70
71     if (!(graphics_driver = LoadLibraryA( buffer )))
72     {
73         MESSAGE( "Could not load graphics driver '%s'\n", buffer );
74         return FALSE;
75     }
76
77     GET_USER_FUNC(InitKeyboard);
78     GET_USER_FUNC(VkKeyScanEx);
79     GET_USER_FUNC(MapVirtualKeyEx);
80     GET_USER_FUNC(GetKeyNameText);
81     GET_USER_FUNC(ToUnicodeEx);
82     GET_USER_FUNC(GetKeyboardLayoutList);
83     GET_USER_FUNC(GetKeyboardLayout);
84     GET_USER_FUNC(GetKeyboardLayoutName);
85     GET_USER_FUNC(LoadKeyboardLayout);
86     GET_USER_FUNC(ActivateKeyboardLayout);
87     GET_USER_FUNC(UnloadKeyboardLayout);
88     GET_USER_FUNC(Beep);
89     GET_USER_FUNC(InitMouse);
90     GET_USER_FUNC(SetCursor);
91     GET_USER_FUNC(GetCursorPos);
92     GET_USER_FUNC(SetCursorPos);
93     GET_USER_FUNC(GetScreenSaveActive);
94     GET_USER_FUNC(SetScreenSaveActive);
95     GET_USER_FUNC(AcquireClipboard);
96     GET_USER_FUNC(EmptyClipboard);
97     GET_USER_FUNC(SetClipboardData);
98     GET_USER_FUNC(GetClipboardData);
99     GET_USER_FUNC(CountClipboardFormats);
100     GET_USER_FUNC(EnumClipboardFormats);
101     GET_USER_FUNC(IsClipboardFormatAvailable);
102     GET_USER_FUNC(RegisterClipboardFormat);
103     GET_USER_FUNC(GetClipboardFormatName);
104     GET_USER_FUNC(EndClipboardUpdate);
105     GET_USER_FUNC(ResetSelectionOwner);
106     GET_USER_FUNC(ChangeDisplaySettingsExW);
107     GET_USER_FUNC(EnumDisplaySettingsExW);
108     GET_USER_FUNC(CreateWindow);
109     GET_USER_FUNC(DestroyWindow);
110     GET_USER_FUNC(GetDC);
111     GET_USER_FUNC(ForceWindowRaise);
112     GET_USER_FUNC(MsgWaitForMultipleObjectsEx);
113     GET_USER_FUNC(ReleaseDC);
114     GET_USER_FUNC(ScrollWindowEx);
115     GET_USER_FUNC(SetFocus);
116     GET_USER_FUNC(SetParent);
117     GET_USER_FUNC(SetWindowPos);
118     GET_USER_FUNC(SetWindowRgn);
119     GET_USER_FUNC(SetWindowIcon);
120     GET_USER_FUNC(SetWindowStyle);
121     GET_USER_FUNC(SetWindowText);
122     GET_USER_FUNC(ShowWindow);
123     GET_USER_FUNC(SysCommandSizeMove);
124
125     return TRUE;
126 }
127
128
129 /***********************************************************************
130  *           palette_init
131  *
132  * Patch the function pointers in GDI for SelectPalette and RealizePalette
133  */
134 static void palette_init(void)
135 {
136     void **ptr;
137     HMODULE module = GetModuleHandleA( "gdi32" );
138     if (!module)
139     {
140         ERR( "cannot get GDI32 handle\n" );
141         return;
142     }
143     if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" )))
144         pfnGDISelectPalette = InterlockedExchangePointer( ptr, SelectPalette );
145     else ERR( "cannot find pfnSelectPalette in GDI32\n" );
146     if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" )))
147         pfnGDIRealizePalette = InterlockedExchangePointer( ptr, UserRealizePalette );
148     else ERR( "cannot find pfnRealizePalette in GDI32\n" );
149 }
150
151
152 /***********************************************************************
153  *           tweak_init
154  */
155 static void tweak_init(void)
156 {
157     static const char *OS = "Win3.1";
158     char buffer[80];
159     HKEY hkey;
160     DWORD type, count = sizeof(buffer);
161
162     if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Layout", &hkey ))
163         return;
164     if (RegQueryValueExA( hkey, "WineLook", 0, &type, buffer, &count ))
165         strcpy( buffer, "Win31" );  /* default value */
166     RegCloseKey( hkey );
167
168     /* WIN31_LOOK is default */
169     if (!strncasecmp( buffer, "Win95", 5 ))
170     {
171         TWEAK_WineLook = WIN95_LOOK;
172         OS = "Win95";
173     }
174     else if (!strncasecmp( buffer, "Win98", 5 ))
175     {
176         TWEAK_WineLook = WIN98_LOOK;
177         OS = "Win98";
178     }
179     TRACE("Using %s look and feel.\n", OS);
180 }
181
182
183 /***********************************************************************
184  *           USER initialisation routine
185  */
186 static BOOL process_attach( HINSTANCE inst )
187 {
188     HINSTANCE16 instance;
189
190     /* Create USER heap */
191     if ((instance = LoadLibrary16( "USER.EXE" )) >= 32) USER_HeapSel = instance | 7;
192     else
193     {
194         USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 65536 );
195         LocalInit16( USER_HeapSel, 32, 65534 );
196     }
197
198     /* Load the graphics driver */
199     tweak_init();
200     if (!load_driver()) return FALSE;
201
202     /* Initialize system colors and metrics */
203     SYSMETRICS_Init();
204     SYSCOLOR_Init();
205
206     /* Setup palette function pointers */
207     palette_init();
208
209     /* Initialize built-in window classes */
210     CLASS_RegisterBuiltinClasses( inst );
211
212     /* Initialize menus */
213     if (!MENU_Init()) return FALSE;
214
215     /* Initialize message spying */
216     if (!SPY_Init()) return FALSE;
217
218     /* Create message queue of initial thread */
219     InitThreadInput16( 0, 0 );
220
221     /* Create desktop window */
222     if (!WIN_CreateDesktopWindow()) return FALSE;
223
224     /* Initialize keyboard driver */
225     if (USER_Driver.pInitKeyboard) USER_Driver.pInitKeyboard( InputKeyStateTable );
226
227     /* Initialize mouse driver */
228     if (USER_Driver.pInitMouse) USER_Driver.pInitMouse( InputKeyStateTable );
229
230     return TRUE;
231 }
232
233
234 /**********************************************************************
235  *           USER_IsExitingThread
236  */
237 BOOL USER_IsExitingThread( DWORD tid )
238 {
239     return (tid == exiting_thread_id);
240 }
241
242
243 /**********************************************************************
244  *           thread_detach
245  */
246 static void thread_detach(void)
247 {
248     exiting_thread_id = GetCurrentThreadId();
249
250     WDML_NotifyThreadDetach();
251
252     TIMER_RemoveThreadTimers();
253     WIN_DestroyThreadWindows( GetDesktopWindow() );
254     QUEUE_DeleteMsgQueue();
255
256     exiting_thread_id = 0;
257 }
258
259
260 /***********************************************************************
261  *           UserClientDllInitialize  (USER32.@)
262  *
263  * USER dll initialisation routine (exported as UserClientDllInitialize for compatibility).
264  */
265 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
266 {
267     BOOL ret = TRUE;
268     switch(reason)
269     {
270     case DLL_PROCESS_ATTACH:
271         ret = process_attach( inst );
272         break;
273     case DLL_THREAD_DETACH:
274         thread_detach();
275         break;
276     }
277     return ret;
278 }