Updated.
[wine] / dlls / user / user_main.c
1 /*
2  * USER initialization code
3  */
4
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"
13
14 #include "controls.h"
15 #include "dce.h"
16 #include "global.h"
17 #include "input.h"
18 #include "keyboard.h"
19 #include "message.h"
20 #include "queue.h"
21 #include "spy.h"
22 #include "sysmetrics.h"
23 #include "user.h"
24 #include "win.h"
25 #include "debugtools.h"
26
27 DEFAULT_DEBUG_CHANNEL(graphics);
28
29 USER_DRIVER USER_Driver;
30
31 WINE_LOOK TWEAK_WineLook = WIN31_LOOK;
32
33 static HMODULE graphics_driver;
34
35 #define GET_USER_FUNC(name) \
36    if (!(USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name ))) \
37       FIXME("%s not found in graphics driver\n", #name)
38
39 /* load the graphics driver */
40 static BOOL load_driver(void)
41 {
42     char buffer[MAX_PATH];
43     HKEY hkey;
44     DWORD type, count;
45
46     if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", 0, NULL,
47                          REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
48     {
49         MESSAGE("load_driver: Cannot create config registry key\n" );
50         return FALSE;
51     }
52     count = sizeof(buffer);
53     if (RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count ))
54         strcpy( buffer, "x11drv" );  /* default value */
55     RegCloseKey( hkey );
56
57     if (!(graphics_driver = LoadLibraryA( buffer )))
58     {
59         MESSAGE( "Could not load graphics driver '%s'\n", buffer );
60         return FALSE;
61     }
62
63     GET_USER_FUNC(Synchronize);
64     GET_USER_FUNC(CheckFocus);
65     GET_USER_FUNC(UserRepaintDisable);
66     GET_USER_FUNC(InitKeyboard);
67     GET_USER_FUNC(VkKeyScan);
68     GET_USER_FUNC(MapVirtualKey);
69     GET_USER_FUNC(GetKeyNameText);
70     GET_USER_FUNC(ToUnicode);
71     GET_USER_FUNC(GetBeepActive);
72     GET_USER_FUNC(SetBeepActive);
73     GET_USER_FUNC(Beep);
74     GET_USER_FUNC(GetDIState);
75     GET_USER_FUNC(GetDIData);
76     GET_USER_FUNC(GetKeyboardConfig);
77     GET_USER_FUNC(SetKeyboardConfig);
78     GET_USER_FUNC(InitMouse);
79     GET_USER_FUNC(SetCursor);
80     GET_USER_FUNC(MoveCursor);
81     GET_USER_FUNC(GetScreenSaveActive);
82     GET_USER_FUNC(SetScreenSaveActive);
83     GET_USER_FUNC(GetScreenSaveTimeout);
84     GET_USER_FUNC(SetScreenSaveTimeout);
85     GET_USER_FUNC(LoadOEMResource);
86     GET_USER_FUNC(IsSingleWindow);
87     GET_USER_FUNC(AcquireClipboard);
88     GET_USER_FUNC(ReleaseClipboard);
89     GET_USER_FUNC(SetClipboardData);
90     GET_USER_FUNC(GetClipboardData);
91     GET_USER_FUNC(IsClipboardFormatAvailable);
92     GET_USER_FUNC(RegisterClipboardFormat);
93     GET_USER_FUNC(IsSelectionOwner);
94     GET_USER_FUNC(ResetSelectionOwner);
95
96     return TRUE;
97 }
98
99
100 /***********************************************************************
101  *           controls_init
102  *
103  * Register the classes for the builtin controls
104  */
105 static void controls_init(void)
106 {
107     extern const struct builtin_class_descr BUTTON_builtin_class;
108     extern const struct builtin_class_descr COMBO_builtin_class;
109     extern const struct builtin_class_descr COMBOLBOX_builtin_class;
110     extern const struct builtin_class_descr DIALOG_builtin_class;
111     extern const struct builtin_class_descr DESKTOP_builtin_class;
112     extern const struct builtin_class_descr EDIT_builtin_class;
113     extern const struct builtin_class_descr ICONTITLE_builtin_class;
114     extern const struct builtin_class_descr LISTBOX_builtin_class;
115     extern const struct builtin_class_descr MDICLIENT_builtin_class;
116     extern const struct builtin_class_descr MENU_builtin_class;
117     extern const struct builtin_class_descr SCROLL_builtin_class;
118     extern const struct builtin_class_descr STATIC_builtin_class;
119
120     CLASS_RegisterBuiltinClass( &BUTTON_builtin_class );
121     CLASS_RegisterBuiltinClass( &COMBO_builtin_class );
122     CLASS_RegisterBuiltinClass( &COMBOLBOX_builtin_class );
123     CLASS_RegisterBuiltinClass( &DIALOG_builtin_class );
124     CLASS_RegisterBuiltinClass( &DESKTOP_builtin_class );
125     CLASS_RegisterBuiltinClass( &EDIT_builtin_class );
126     CLASS_RegisterBuiltinClass( &ICONTITLE_builtin_class );
127     CLASS_RegisterBuiltinClass( &LISTBOX_builtin_class );
128     CLASS_RegisterBuiltinClass( &MDICLIENT_builtin_class );
129     CLASS_RegisterBuiltinClass( &MENU_builtin_class );
130     CLASS_RegisterBuiltinClass( &SCROLL_builtin_class );
131     CLASS_RegisterBuiltinClass( &STATIC_builtin_class );
132 }
133
134
135 /***********************************************************************
136  *           palette_init
137  *
138  * Patch the function pointers in GDI for SelectPalette and RealizePalette
139  */
140 static void palette_init(void)
141 {
142     void **ptr;
143     HMODULE module = GetModuleHandleA( "gdi32" );
144     if (!module)
145     {
146         ERR( "cannot get GDI32 handle\n" );
147         return;
148     }
149     if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" ))) *ptr = SelectPalette16;
150     else ERR( "cannot find pfnSelectPalette in GDI32\n" );
151     if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" ))) *ptr = UserRealizePalette;
152     else ERR( "cannot find pfnRealizePalette in GDI32\n" );
153 }
154
155
156 /***********************************************************************
157  *           tweak_init
158  */
159 static void tweak_init(void)
160 {
161     static const char *OS = "Win3.1";
162     char buffer[80];
163     HKEY hkey;
164     DWORD type, count = sizeof(buffer);
165
166     if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Layout", 0, NULL,
167                          REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
168         return;
169     if (RegQueryValueExA( hkey, "WineLook", 0, &type, buffer, &count ))
170         strcpy( buffer, "Win31" );  /* default value */
171     RegCloseKey( hkey );
172
173     /* WIN31_LOOK is default */
174     if (!strncasecmp( buffer, "Win95", 5 ))
175     {
176         TWEAK_WineLook = WIN95_LOOK;
177         OS = "Win95";
178     }
179     else if (!strncasecmp( buffer, "Win98", 5 ))
180     {
181         TWEAK_WineLook = WIN98_LOOK;
182         OS = "Win98";
183     }
184     TRACE("Using %s look and feel.\n", OS);
185 }
186
187
188 /***********************************************************************
189  *           USER initialisation routine
190  */
191 BOOL WINAPI USER_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
192 {
193     HINSTANCE16 instance;
194     int queueSize;
195
196     if ( USER_HeapSel ) return TRUE;
197
198     /* Create USER heap */
199     if ((instance = LoadLibrary16( "USER.EXE" )) < 32) return FALSE;
200     USER_HeapSel = GlobalHandleToSel16( instance );
201
202      /* Global atom table initialisation */
203     if (!ATOM_Init( USER_HeapSel )) return FALSE;
204
205     /* Load the graphics driver */
206     tweak_init();
207     if (!load_driver()) return FALSE;
208
209     /* Initialize system colors and metrics*/
210     SYSMETRICS_Init();
211     SYSCOLOR_Init();
212
213     /* Setup palette function pointers */
214     palette_init();
215
216     /* Create the DCEs */
217     DCE_Init();
218
219     /* Initialize window procedures */
220     if (!WINPROC_Init()) return FALSE;
221
222     /* Initialize built-in window classes */
223     controls_init();
224
225     /* Initialize dialog manager */
226     if (!DIALOG_Init()) return FALSE;
227
228     /* Initialize menus */
229     if (!MENU_Init()) return FALSE;
230
231     /* Initialize message spying */
232     if (!SPY_Init()) return FALSE;
233
234     /* Create system message queue */
235     queueSize = GetProfileIntA( "windows", "TypeAhead", 120 );
236     if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
237
238     /* Set double click time */
239     SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
240
241     /* Create message queue of initial thread */
242     InitThreadInput16( 0, 0 );
243
244     /* Create desktop window */
245     if (!WIN_CreateDesktopWindow()) return FALSE;
246
247     /* Initialize keyboard driver */
248     KEYBOARD_Enable( keybd_event, InputKeyStateTable );
249
250     /* Initialize mouse driver */
251     MOUSE_Enable( mouse_event );
252
253     /* Start processing X events */
254     USER_Driver.pUserRepaintDisable( FALSE );
255
256     return TRUE;
257 }