2 * USER initialization code
11 #include "wine/winbase16.h"
12 #include "wine/winuser16.h"
15 #include "cursoricon.h"
22 #include "sysmetrics.h"
25 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(graphics);
29 USER_DRIVER USER_Driver;
31 WINE_LOOK TWEAK_WineLook = WIN31_LOOK;
33 WORD USER_HeapSel = 0; /* USER heap selector */
35 static HMODULE graphics_driver;
36 static DWORD exiting_thread_id;
38 extern void COMM_Init(void);
39 extern void WDML_NotifyThreadDetach(void);
41 #define GET_USER_FUNC(name) USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name )
43 /* load the graphics driver */
44 static BOOL load_driver(void)
46 char buffer[MAX_PATH];
50 strcpy( buffer, "x11drv" ); /* default value */
51 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
53 count = sizeof(buffer);
54 RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
58 if (!(graphics_driver = LoadLibraryA( buffer )))
60 MESSAGE( "Could not load graphics driver '%s'\n", buffer );
64 GET_USER_FUNC(InitKeyboard);
65 GET_USER_FUNC(VkKeyScan);
66 GET_USER_FUNC(MapVirtualKey);
67 GET_USER_FUNC(GetKeyNameText);
68 GET_USER_FUNC(ToUnicode);
70 GET_USER_FUNC(InitMouse);
71 GET_USER_FUNC(SetCursor);
72 GET_USER_FUNC(GetCursorPos);
73 GET_USER_FUNC(SetCursorPos);
74 GET_USER_FUNC(GetScreenSaveActive);
75 GET_USER_FUNC(SetScreenSaveActive);
76 GET_USER_FUNC(AcquireClipboard);
77 GET_USER_FUNC(ReleaseClipboard);
78 GET_USER_FUNC(SetClipboardData);
79 GET_USER_FUNC(GetClipboardData);
80 GET_USER_FUNC(IsClipboardFormatAvailable);
81 GET_USER_FUNC(RegisterClipboardFormat);
82 GET_USER_FUNC(IsSelectionOwner);
83 GET_USER_FUNC(ResetSelectionOwner);
84 GET_USER_FUNC(CreateWindow);
85 GET_USER_FUNC(DestroyWindow);
87 GET_USER_FUNC(ForceWindowRaise);
88 GET_USER_FUNC(MsgWaitForMultipleObjectsEx);
89 GET_USER_FUNC(ScrollDC);
90 GET_USER_FUNC(ScrollWindowEx);
91 GET_USER_FUNC(SetFocus);
92 GET_USER_FUNC(SetParent);
93 GET_USER_FUNC(SetWindowPos);
94 GET_USER_FUNC(SetWindowRgn);
95 GET_USER_FUNC(SetWindowIcon);
96 GET_USER_FUNC(SetWindowStyle);
97 GET_USER_FUNC(SetWindowText);
98 GET_USER_FUNC(ShowWindow);
99 GET_USER_FUNC(SysCommandSizeMove);
105 /***********************************************************************
108 * Register the classes for the builtin controls
110 static void controls_init(void)
112 extern const struct builtin_class_descr BUTTON_builtin_class;
113 extern const struct builtin_class_descr COMBO_builtin_class;
114 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
115 extern const struct builtin_class_descr DIALOG_builtin_class;
116 extern const struct builtin_class_descr DESKTOP_builtin_class;
117 extern const struct builtin_class_descr EDIT_builtin_class;
118 extern const struct builtin_class_descr ICONTITLE_builtin_class;
119 extern const struct builtin_class_descr LISTBOX_builtin_class;
120 extern const struct builtin_class_descr MDICLIENT_builtin_class;
121 extern const struct builtin_class_descr MENU_builtin_class;
122 extern const struct builtin_class_descr SCROLL_builtin_class;
123 extern const struct builtin_class_descr STATIC_builtin_class;
125 CLASS_RegisterBuiltinClass( &BUTTON_builtin_class );
126 CLASS_RegisterBuiltinClass( &COMBO_builtin_class );
127 CLASS_RegisterBuiltinClass( &COMBOLBOX_builtin_class );
128 CLASS_RegisterBuiltinClass( &DIALOG_builtin_class );
129 CLASS_RegisterBuiltinClass( &DESKTOP_builtin_class );
130 CLASS_RegisterBuiltinClass( &EDIT_builtin_class );
131 CLASS_RegisterBuiltinClass( &ICONTITLE_builtin_class );
132 CLASS_RegisterBuiltinClass( &LISTBOX_builtin_class );
133 CLASS_RegisterBuiltinClass( &MDICLIENT_builtin_class );
134 CLASS_RegisterBuiltinClass( &MENU_builtin_class );
135 CLASS_RegisterBuiltinClass( &SCROLL_builtin_class );
136 CLASS_RegisterBuiltinClass( &STATIC_builtin_class );
140 /***********************************************************************
143 * Patch the function pointers in GDI for SelectPalette and RealizePalette
145 static void palette_init(void)
148 HMODULE module = GetModuleHandleA( "gdi32" );
151 ERR( "cannot get GDI32 handle\n" );
154 if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" ))) *ptr = SelectPalette16;
155 else ERR( "cannot find pfnSelectPalette in GDI32\n" );
156 if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" ))) *ptr = UserRealizePalette;
157 else ERR( "cannot find pfnRealizePalette in GDI32\n" );
161 /***********************************************************************
164 static void tweak_init(void)
166 static const char *OS = "Win3.1";
169 DWORD type, count = sizeof(buffer);
171 if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Layout", &hkey ))
173 if (RegQueryValueExA( hkey, "WineLook", 0, &type, buffer, &count ))
174 strcpy( buffer, "Win31" ); /* default value */
177 /* WIN31_LOOK is default */
178 if (!strncasecmp( buffer, "Win95", 5 ))
180 TWEAK_WineLook = WIN95_LOOK;
183 else if (!strncasecmp( buffer, "Win98", 5 ))
185 TWEAK_WineLook = WIN98_LOOK;
188 TRACE("Using %s look and feel.\n", OS);
192 /***********************************************************************
193 * USER initialisation routine
195 static BOOL process_attach(void)
197 HINSTANCE16 instance;
199 /* Create USER heap */
200 if ((instance = LoadLibrary16( "USER.EXE" )) < 32) return FALSE;
201 USER_HeapSel = instance | 7;
203 /* Global atom table initialisation */
204 if (!ATOM_Init( USER_HeapSel )) return FALSE;
206 /* Load the graphics driver */
208 if (!load_driver()) return FALSE;
210 /* Initialize system colors and metrics*/
214 /* Setup palette function pointers */
217 /* Initialize window procedures */
218 if (!WINPROC_Init()) return FALSE;
220 /* Initialize built-in window classes */
223 /* Initialize dialog manager */
224 if (!DIALOG_Init()) return FALSE;
226 /* Initialize menus */
227 if (!MENU_Init()) return FALSE;
229 /* Initialize message spying */
230 if (!SPY_Init()) return FALSE;
232 /* Create message queue of initial thread */
233 InitThreadInput16( 0, 0 );
235 /* Create desktop window */
236 if (!WIN_CreateDesktopWindow()) return FALSE;
238 /* Initialize keyboard driver */
239 if (USER_Driver.pInitKeyboard) USER_Driver.pInitKeyboard( InputKeyStateTable );
241 /* Initialize mouse driver */
242 if (USER_Driver.pInitMouse) USER_Driver.pInitMouse( InputKeyStateTable );
244 /* Initialize 16-bit serial communications */
251 /**********************************************************************
252 * USER_IsExitingThread
254 BOOL USER_IsExitingThread( DWORD tid )
256 return (tid == exiting_thread_id);
260 /**********************************************************************
263 static void thread_detach(void)
265 HQUEUE16 hQueue = GetThreadQueue16( 0 );
267 exiting_thread_id = GetCurrentThreadId();
269 WDML_NotifyThreadDetach();
273 TIMER_RemoveQueueTimers( hQueue );
274 HOOK_FreeQueueHooks();
275 WIN_DestroyThreadWindows( GetDesktopWindow() );
276 QUEUE_DeleteMsgQueue();
279 if (!(NtCurrentTeb()->tibflags & TEBF_WIN32))
281 HMODULE16 hModule = GetExePtr( MapHModuleLS(0) );
283 /* FIXME: maybe destroy menus (Windows only complains about them
286 if (GetModuleUsage16( hModule ) <= 1)
288 /* ModuleUnload() in "Internals" */
289 HOOK_FreeModuleHooks( hModule );
290 CLASS_FreeModuleClasses( hModule );
291 CURSORICON_FreeModuleIcons( hModule );
294 exiting_thread_id = 0;
298 /***********************************************************************
299 * UserClientDllInitialize (USER32.@)
301 * USER dll initialisation routine
303 BOOL WINAPI UserClientDllInitialize( HINSTANCE inst, DWORD reason, LPVOID reserved )
308 case DLL_PROCESS_ATTACH:
309 ret = process_attach();
311 case DLL_THREAD_DETACH: