Exchanged the values for LVA_ALIGNLEFT style and LVA_DEFAULT style.
[wine/testsucceed.git] / dlls / user / user_main.c
blob66bb888e2a4762ab81b6080c9b7861b1047b838f
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 <stdarg.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "wine/winbase16.h"
30 #include "wine/winuser16.h"
32 #include "controls.h"
33 #include "user_private.h"
34 #include "win.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
39 USER_DRIVER USER_Driver;
41 WORD USER_HeapSel = 0; /* USER heap selector */
42 HMODULE user32_module = 0;
44 static SYSLEVEL USER_SysLevel;
45 static CRITICAL_SECTION_DEBUG critsect_debug =
47 0, 0, &USER_SysLevel.crst,
48 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
49 0, 0, { 0, (DWORD)(__FILE__ ": USER_SysLevel") }
51 static SYSLEVEL USER_SysLevel = { { &critsect_debug, -1, 0, 0, 0, 0 }, 2 };
53 static HPALETTE (WINAPI *pfnGDISelectPalette)( HDC hdc, HPALETTE hpal, WORD bkgnd );
54 static UINT (WINAPI *pfnGDIRealizePalette)( HDC hdc );
55 static HPALETTE hPrimaryPalette;
57 static HMODULE graphics_driver;
58 static DWORD exiting_thread_id;
60 extern void WDML_NotifyThreadDetach(void);
62 #define GET_USER_FUNC(name) USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name )
64 /* load the graphics driver */
65 static BOOL load_driver(void)
67 char buffer[MAX_PATH], libname[32], *name, *next;
68 HKEY hkey;
70 strcpy( buffer, "x11,tty" ); /* default value */
71 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Drivers", &hkey ))
73 DWORD type, count = sizeof(buffer);
74 RegQueryValueExA( hkey, "Graphics", 0, &type, buffer, &count );
75 RegCloseKey( hkey );
78 name = buffer;
79 while (name)
81 next = strchr( name, ',' );
82 if (next) *next++ = 0;
84 snprintf( libname, sizeof(libname), "wine%s.drv", name );
85 if ((graphics_driver = LoadLibraryA( libname )) != 0) break;
86 name = next;
88 if (!graphics_driver)
90 MESSAGE( "wine: Could not load graphics driver '%s'.\n", buffer );
91 if (!strcasecmp( buffer, "x11" ))
92 MESSAGE( "Make sure that your X server is running and that $DISPLAY is set correctly.\n" );
93 ExitProcess(1);
96 GET_USER_FUNC(ActivateKeyboardLayout);
97 GET_USER_FUNC(Beep);
98 GET_USER_FUNC(GetAsyncKeyState);
99 GET_USER_FUNC(GetKeyNameText);
100 GET_USER_FUNC(GetKeyboardLayout);
101 GET_USER_FUNC(GetKeyboardLayoutList);
102 GET_USER_FUNC(GetKeyboardLayoutName);
103 GET_USER_FUNC(LoadKeyboardLayout);
104 GET_USER_FUNC(MapVirtualKeyEx);
105 GET_USER_FUNC(SendInput);
106 GET_USER_FUNC(ToUnicodeEx);
107 GET_USER_FUNC(UnloadKeyboardLayout);
108 GET_USER_FUNC(VkKeyScanEx);
109 GET_USER_FUNC(SetCursor);
110 GET_USER_FUNC(GetCursorPos);
111 GET_USER_FUNC(SetCursorPos);
112 GET_USER_FUNC(GetScreenSaveActive);
113 GET_USER_FUNC(SetScreenSaveActive);
114 GET_USER_FUNC(AcquireClipboard);
115 GET_USER_FUNC(EmptyClipboard);
116 GET_USER_FUNC(SetClipboardData);
117 GET_USER_FUNC(GetClipboardData);
118 GET_USER_FUNC(CountClipboardFormats);
119 GET_USER_FUNC(EnumClipboardFormats);
120 GET_USER_FUNC(IsClipboardFormatAvailable);
121 GET_USER_FUNC(RegisterClipboardFormat);
122 GET_USER_FUNC(GetClipboardFormatName);
123 GET_USER_FUNC(EndClipboardUpdate);
124 GET_USER_FUNC(ResetSelectionOwner);
125 GET_USER_FUNC(ChangeDisplaySettingsExW);
126 GET_USER_FUNC(EnumDisplaySettingsExW);
127 GET_USER_FUNC(CreateWindow);
128 GET_USER_FUNC(DestroyWindow);
129 GET_USER_FUNC(GetDCEx);
130 GET_USER_FUNC(MsgWaitForMultipleObjectsEx);
131 GET_USER_FUNC(ReleaseDC);
132 GET_USER_FUNC(ScrollDC);
133 GET_USER_FUNC(SetFocus);
134 GET_USER_FUNC(SetParent);
135 GET_USER_FUNC(SetWindowPos);
136 GET_USER_FUNC(SetWindowRgn);
137 GET_USER_FUNC(SetWindowIcon);
138 GET_USER_FUNC(SetWindowStyle);
139 GET_USER_FUNC(SetWindowText);
140 GET_USER_FUNC(ShowWindow);
141 GET_USER_FUNC(SysCommandSizeMove);
142 GET_USER_FUNC(WindowFromDC);
143 GET_USER_FUNC(WindowMessage);
145 return TRUE;
149 /***********************************************************************
150 * USER_Lock
152 void USER_Lock(void)
154 _EnterSysLevel( &USER_SysLevel );
158 /***********************************************************************
159 * USER_Unlock
161 void USER_Unlock(void)
163 _LeaveSysLevel( &USER_SysLevel );
167 /***********************************************************************
168 * USER_CheckNotLock
170 * Make sure that we don't hold the user lock.
172 void USER_CheckNotLock(void)
174 _CheckNotSysLevel( &USER_SysLevel );
178 /***********************************************************************
179 * UserSelectPalette (Not a Windows API)
181 static HPALETTE WINAPI UserSelectPalette( HDC hDC, HPALETTE hPal, BOOL bForceBackground )
183 WORD wBkgPalette = 1;
185 if (!bForceBackground && (hPal != GetStockObject(DEFAULT_PALETTE)))
187 HWND hwnd = WindowFromDC( hDC );
188 if (hwnd)
190 HWND hForeground = GetForegroundWindow();
191 /* set primary palette if it's related to current active */
192 if (hForeground == hwnd || IsChild(hForeground,hwnd))
194 wBkgPalette = 0;
195 hPrimaryPalette = hPal;
199 return pfnGDISelectPalette( hDC, hPal, wBkgPalette);
203 /***********************************************************************
204 * UserRealizePalette (USER32.@)
206 UINT WINAPI UserRealizePalette( HDC hDC )
208 UINT realized = pfnGDIRealizePalette( hDC );
210 /* do not send anything if no colors were changed */
211 if (realized && GetCurrentObject( hDC, OBJ_PAL ) == hPrimaryPalette)
213 /* send palette change notification */
214 HWND hWnd = WindowFromDC( hDC );
215 if (hWnd) SendMessageTimeoutW( HWND_BROADCAST, WM_PALETTECHANGED, (WPARAM)hWnd, 0,
216 SMTO_ABORTIFHUNG, 2000, NULL );
218 return realized;
222 /***********************************************************************
223 * palette_init
225 * Patch the function pointers in GDI for SelectPalette and RealizePalette
227 static void palette_init(void)
229 void **ptr;
230 HMODULE module = GetModuleHandleA( "gdi32" );
231 if (!module)
233 ERR( "cannot get GDI32 handle\n" );
234 return;
236 if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" )))
237 pfnGDISelectPalette = InterlockedExchangePointer( ptr, UserSelectPalette );
238 else ERR( "cannot find pfnSelectPalette in GDI32\n" );
239 if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" )))
240 pfnGDIRealizePalette = InterlockedExchangePointer( ptr, UserRealizePalette );
241 else ERR( "cannot find pfnRealizePalette in GDI32\n" );
245 /***********************************************************************
246 * USER initialisation routine
248 static BOOL process_attach(void)
250 HINSTANCE16 instance;
252 /* Create USER heap */
253 if ((instance = LoadLibrary16( "USER.EXE" )) >= 32) USER_HeapSel = instance | 7;
254 else
256 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 65536 );
257 LocalInit16( USER_HeapSel, 32, 65534 );
260 /* some Win9x dlls expect keyboard to be loaded */
261 if (GetVersion() & 0x80000000) LoadLibrary16( "keyboard.drv" );
263 /* Load the graphics driver */
264 if (!load_driver()) return FALSE;
266 /* Initialize system colors and metrics */
267 SYSPARAMS_Init();
269 /* Setup palette function pointers */
270 palette_init();
272 /* Initialize built-in window classes */
273 CLASS_RegisterBuiltinClasses();
275 /* Initialize menus */
276 if (!MENU_Init()) return FALSE;
278 /* Initialize message spying */
279 if (!SPY_Init()) return FALSE;
281 /* Create desktop window */
282 if (!WIN_CreateDesktopWindow()) return FALSE;
284 return TRUE;
288 /**********************************************************************
289 * USER_IsExitingThread
291 BOOL USER_IsExitingThread( DWORD tid )
293 return (tid == exiting_thread_id);
297 /**********************************************************************
298 * thread_detach
300 static void thread_detach(void)
302 exiting_thread_id = GetCurrentThreadId();
304 WDML_NotifyThreadDetach();
306 WIN_DestroyThreadWindows( GetDesktopWindow() );
307 CloseHandle( get_user_thread_info()->server_queue );
309 exiting_thread_id = 0;
313 /**********************************************************************
314 * process_detach
316 static void process_detach(void)
318 memset(&USER_Driver, 0, sizeof(USER_Driver));
319 FreeLibrary(graphics_driver);
322 /***********************************************************************
323 * UserClientDllInitialize (USER32.@)
325 * USER dll initialisation routine (exported as UserClientDllInitialize for compatibility).
327 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
329 BOOL ret = TRUE;
330 switch(reason)
332 case DLL_PROCESS_ATTACH:
333 user32_module = inst;
334 ret = process_attach();
335 break;
336 case DLL_PROCESS_DETACH:
337 process_detach();
338 break;
339 case DLL_THREAD_DETACH:
340 thread_detach();
341 break;
343 return ret;