Moved UTSelectorOffsetToLinear and UTLinearToSelectorOffset to
[wine] / dlls / user / user_main.c
1 /*
2  * USER initialization code
3  */
4
5 #include "windef.h"
6 #include "wingdi.h"
7 #include "winuser.h"
8 #include "winreg.h"
9 #include "wine/winbase16.h"
10 #include "wine/winuser16.h"
11
12 #include "dce.h"
13 #include "dialog.h"
14 #include "global.h"
15 #include "input.h"
16 #include "keyboard.h"
17 #include "menu.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 static HMODULE graphics_driver;
31
32 #define GET_USER_FUNC(name) \
33    if (!(USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name ))) \
34       FIXME("%s not found in graphics driver\n", #name)
35
36 /* load the graphics driver */
37 static BOOL load_driver(void)
38 {
39     char buffer[MAX_PATH];
40     HKEY hkey;
41     DWORD type, count;
42
43     if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", 0, NULL,
44                          REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
45     {
46         MESSAGE("load_driver: Cannot create config registry key\n" );
47         return FALSE;
48     }
49     count = sizeof(buffer);
50     if (RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count ))
51         strcpy( buffer, "x11drv" );  /* default value */
52     RegCloseKey( hkey );
53
54     if (!(graphics_driver = LoadLibraryA( buffer )))
55     {
56         MESSAGE( "Could not load graphics driver '%s'\n", buffer );
57         return FALSE;
58     }
59
60     GET_USER_FUNC(Synchronize);
61     GET_USER_FUNC(CheckFocus);
62     GET_USER_FUNC(UserRepaintDisable);
63     GET_USER_FUNC(InitKeyboard);
64     GET_USER_FUNC(VkKeyScan);
65     GET_USER_FUNC(MapVirtualKey);
66     GET_USER_FUNC(GetKeyNameText);
67     GET_USER_FUNC(ToUnicode);
68     GET_USER_FUNC(GetBeepActive);
69     GET_USER_FUNC(SetBeepActive);
70     GET_USER_FUNC(Beep);
71     GET_USER_FUNC(GetDIState);
72     GET_USER_FUNC(GetDIData);
73     GET_USER_FUNC(GetKeyboardConfig);
74     GET_USER_FUNC(SetKeyboardConfig);
75     GET_USER_FUNC(InitMouse);
76     GET_USER_FUNC(SetCursor);
77     GET_USER_FUNC(MoveCursor);
78     GET_USER_FUNC(GetScreenSaveActive);
79     GET_USER_FUNC(SetScreenSaveActive);
80     GET_USER_FUNC(GetScreenSaveTimeout);
81     GET_USER_FUNC(SetScreenSaveTimeout);
82     GET_USER_FUNC(LoadOEMResource);
83     GET_USER_FUNC(IsSingleWindow);
84     GET_USER_FUNC(AcquireClipboard);
85     GET_USER_FUNC(ReleaseClipboard);
86     GET_USER_FUNC(SetClipboardData);
87     GET_USER_FUNC(GetClipboardData);
88     GET_USER_FUNC(IsClipboardFormatAvailable);
89     GET_USER_FUNC(RegisterClipboardFormat);
90     GET_USER_FUNC(IsSelectionOwner);
91     GET_USER_FUNC(ResetSelectionOwner);
92
93     return TRUE;
94 }
95
96
97 /***********************************************************************
98  *           palette_init
99  *
100  * Patch the function pointers in GDI for SelectPalette and RealizePalette
101  */
102 static void palette_init(void)
103 {
104     void **ptr;
105     HMODULE module = GetModuleHandleA( "gdi32" );
106     if (!module)
107     {
108         ERR( "cannot get GDI32 handle\n" );
109         return;
110     }
111     if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" ))) *ptr = SelectPalette16;
112     else ERR( "cannot find pfnSelectPalette in GDI32\n" );
113     if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" ))) *ptr = UserRealizePalette;
114     else ERR( "cannot find pfnRealizePalette in GDI32\n" );
115 }
116
117
118 /***********************************************************************
119  *           USER initialisation routine
120  */
121 BOOL WINAPI USER_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
122 {
123     HINSTANCE16 instance;
124     int queueSize;
125
126     if ( USER_HeapSel ) return TRUE;
127
128     /* Create USER heap */
129     if ((instance = LoadLibrary16( "USER.EXE" )) < 32) return FALSE;
130     USER_HeapSel = GlobalHandleToSel16( instance );
131
132      /* Global atom table initialisation */
133     if (!ATOM_Init( USER_HeapSel )) return FALSE;
134
135     /* Load the graphics driver */
136     if (!load_driver()) return FALSE;
137
138     /* Initialize system colors and metrics*/
139     SYSMETRICS_Init();
140     SYSCOLOR_Init();
141
142     /* Setup palette function pointers */
143     palette_init();
144
145     /* Create the DCEs */
146     DCE_Init();
147
148     /* Initialize window procedures */
149     if (!WINPROC_Init()) return FALSE;
150
151     /* Initialize built-in window classes */
152     if (!WIDGETS_Init()) return FALSE;
153
154     /* Initialize dialog manager */
155     if (!DIALOG_Init()) return FALSE;
156
157     /* Initialize menus */
158     if (!MENU_Init()) return FALSE;
159
160     /* Initialize message spying */
161     if (!SPY_Init()) return FALSE;
162
163     /* Create system message queue */
164     queueSize = GetProfileIntA( "windows", "TypeAhead", 120 );
165     if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
166
167     /* Set double click time */
168     SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
169
170     /* Create message queue of initial thread */
171     InitThreadInput16( 0, 0 );
172
173     /* Create desktop window */
174     if (!WIN_CreateDesktopWindow()) return FALSE;
175
176     /* Initialize keyboard driver */
177     KEYBOARD_Enable( keybd_event, InputKeyStateTable );
178
179     /* Initialize mouse driver */
180     MOUSE_Enable( mouse_event );
181
182     /* Start processing X events */
183     USER_Driver.pUserRepaintDisable( FALSE );
184
185     return TRUE;
186 }