Moved ScrollWindowEx implementation to the graphics driver.
[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 "global.h"
16 #include "input.h"
17 #include "keyboard.h"
18 #include "message.h"
19 #include "queue.h"
20 #include "spy.h"
21 #include "sysmetrics.h"
22 #include "user.h"
23 #include "win.h"
24 #include "debugtools.h"
25
26 DEFAULT_DEBUG_CHANNEL(graphics);
27
28 USER_DRIVER USER_Driver;
29
30 WINE_LOOK TWEAK_WineLook = WIN31_LOOK;
31
32 WORD USER_HeapSel = 0;  /* USER heap selector */
33
34 static HMODULE graphics_driver;
35
36 #define GET_USER_FUNC(name) \
37    if (!(USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name ))) \
38       FIXME("%s not found in graphics driver\n", #name)
39
40 /* load the graphics driver */
41 static BOOL load_driver(void)
42 {
43     char buffer[MAX_PATH];
44     HKEY hkey;
45     DWORD type, count;
46
47     strcpy( buffer, "x11drv" );  /* default value */
48     if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
49     {
50         count = sizeof(buffer);
51         RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
52         RegCloseKey( hkey );
53     }
54
55     if (!(graphics_driver = LoadLibraryA( buffer )))
56     {
57         MESSAGE( "Could not load graphics driver '%s'\n", buffer );
58         return FALSE;
59     }
60
61     GET_USER_FUNC(UserRepaintDisable);
62     GET_USER_FUNC(InitKeyboard);
63     GET_USER_FUNC(VkKeyScan);
64     GET_USER_FUNC(MapVirtualKey);
65     GET_USER_FUNC(GetKeyNameText);
66     GET_USER_FUNC(ToUnicode);
67     GET_USER_FUNC(Beep);
68     GET_USER_FUNC(GetDIState);
69     GET_USER_FUNC(GetDIData);
70     GET_USER_FUNC(InitMouse);
71     GET_USER_FUNC(SetCursor);
72     GET_USER_FUNC(MoveCursor);
73     GET_USER_FUNC(GetScreenSaveActive);
74     GET_USER_FUNC(SetScreenSaveActive);
75     GET_USER_FUNC(GetScreenSaveTimeout);
76     GET_USER_FUNC(SetScreenSaveTimeout);
77     GET_USER_FUNC(LoadOEMResource);
78     GET_USER_FUNC(IsSingleWindow);
79     GET_USER_FUNC(AcquireClipboard);
80     GET_USER_FUNC(ReleaseClipboard);
81     GET_USER_FUNC(SetClipboardData);
82     GET_USER_FUNC(GetClipboardData);
83     GET_USER_FUNC(IsClipboardFormatAvailable);
84     GET_USER_FUNC(RegisterClipboardFormat);
85     GET_USER_FUNC(IsSelectionOwner);
86     GET_USER_FUNC(ResetSelectionOwner);
87     GET_USER_FUNC(CreateWindow);
88     GET_USER_FUNC(DestroyWindow);
89     GET_USER_FUNC(GetDC);
90     GET_USER_FUNC(EnableWindow);
91     GET_USER_FUNC(ScrollWindowEx);
92     GET_USER_FUNC(SetFocus);
93     GET_USER_FUNC(SetParent);
94     GET_USER_FUNC(SetWindowPos);
95     GET_USER_FUNC(SetWindowRgn);
96     GET_USER_FUNC(SetWindowIcon);
97     GET_USER_FUNC(SetWindowText);
98     GET_USER_FUNC(SysCommandSizeMove);
99
100     return TRUE;
101 }
102
103
104 /***********************************************************************
105  *           controls_init
106  *
107  * Register the classes for the builtin controls
108  */
109 static void controls_init(void)
110 {
111     extern const struct builtin_class_descr BUTTON_builtin_class;
112     extern const struct builtin_class_descr COMBO_builtin_class;
113     extern const struct builtin_class_descr COMBOLBOX_builtin_class;
114     extern const struct builtin_class_descr DIALOG_builtin_class;
115     extern const struct builtin_class_descr DESKTOP_builtin_class;
116     extern const struct builtin_class_descr EDIT_builtin_class;
117     extern const struct builtin_class_descr ICONTITLE_builtin_class;
118     extern const struct builtin_class_descr LISTBOX_builtin_class;
119     extern const struct builtin_class_descr MDICLIENT_builtin_class;
120     extern const struct builtin_class_descr MENU_builtin_class;
121     extern const struct builtin_class_descr SCROLL_builtin_class;
122     extern const struct builtin_class_descr STATIC_builtin_class;
123
124     CLASS_RegisterBuiltinClass( &BUTTON_builtin_class );
125     CLASS_RegisterBuiltinClass( &COMBO_builtin_class );
126     CLASS_RegisterBuiltinClass( &COMBOLBOX_builtin_class );
127     CLASS_RegisterBuiltinClass( &DIALOG_builtin_class );
128     CLASS_RegisterBuiltinClass( &DESKTOP_builtin_class );
129     CLASS_RegisterBuiltinClass( &EDIT_builtin_class );
130     CLASS_RegisterBuiltinClass( &ICONTITLE_builtin_class );
131     CLASS_RegisterBuiltinClass( &LISTBOX_builtin_class );
132     CLASS_RegisterBuiltinClass( &MDICLIENT_builtin_class );
133     CLASS_RegisterBuiltinClass( &MENU_builtin_class );
134     CLASS_RegisterBuiltinClass( &SCROLL_builtin_class );
135     CLASS_RegisterBuiltinClass( &STATIC_builtin_class );
136 }
137
138
139 /***********************************************************************
140  *           palette_init
141  *
142  * Patch the function pointers in GDI for SelectPalette and RealizePalette
143  */
144 static void palette_init(void)
145 {
146     void **ptr;
147     HMODULE module = GetModuleHandleA( "gdi32" );
148     if (!module)
149     {
150         ERR( "cannot get GDI32 handle\n" );
151         return;
152     }
153     if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" ))) *ptr = SelectPalette16;
154     else ERR( "cannot find pfnSelectPalette in GDI32\n" );
155     if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" ))) *ptr = UserRealizePalette;
156     else ERR( "cannot find pfnRealizePalette in GDI32\n" );
157 }
158
159
160 /***********************************************************************
161  *           tweak_init
162  */
163 static void tweak_init(void)
164 {
165     static const char *OS = "Win3.1";
166     char buffer[80];
167     HKEY hkey;
168     DWORD type, count = sizeof(buffer);
169
170     if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Layout", &hkey ))
171         return;
172     if (RegQueryValueExA( hkey, "WineLook", 0, &type, buffer, &count ))
173         strcpy( buffer, "Win31" );  /* default value */
174     RegCloseKey( hkey );
175
176     /* WIN31_LOOK is default */
177     if (!strncasecmp( buffer, "Win95", 5 ))
178     {
179         TWEAK_WineLook = WIN95_LOOK;
180         OS = "Win95";
181     }
182     else if (!strncasecmp( buffer, "Win98", 5 ))
183     {
184         TWEAK_WineLook = WIN98_LOOK;
185         OS = "Win98";
186     }
187     TRACE("Using %s look and feel.\n", OS);
188 }
189
190
191 /***********************************************************************
192  *           USER initialisation routine
193  */
194 BOOL WINAPI USER_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
195 {
196     HINSTANCE16 instance;
197     int queueSize;
198
199     if ( USER_HeapSel ) return TRUE;
200
201     /* Create USER heap */
202     if ((instance = LoadLibrary16( "USER.EXE" )) < 32) return FALSE;
203     USER_HeapSel = instance | 7;
204
205      /* Global atom table initialisation */
206     if (!ATOM_Init( USER_HeapSel )) return FALSE;
207
208     /* Load the graphics driver */
209     tweak_init();
210     if (!load_driver()) return FALSE;
211
212     /* Initialize system colors and metrics*/
213     SYSMETRICS_Init();
214     SYSCOLOR_Init();
215
216     /* Setup palette function pointers */
217     palette_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 }