Merged clipboard driver into USER driver.
[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
11 #include "dce.h"
12 #include "dialog.h"
13 #include "global.h"
14 #include "input.h"
15 #include "keyboard.h"
16 #include "menu.h"
17 #include "message.h"
18 #include "queue.h"
19 #include "spy.h"
20 #include "sysmetrics.h"
21 #include "user.h"
22 #include "win.h"
23 #include "debugtools.h"
24
25 DEFAULT_DEBUG_CHANNEL(graphics);
26
27 USER_DRIVER USER_Driver;
28
29 static HMODULE graphics_driver;
30
31 #define GET_USER_FUNC(name) \
32    if (!(USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name ))) \
33       FIXME("%s not found in graphics driver\n", #name)
34
35 /* load the graphics driver */
36 static BOOL load_driver(void)
37 {
38     char buffer[MAX_PATH];
39     HKEY hkey;
40     DWORD type, count;
41
42     if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", 0, NULL,
43                          REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
44     {
45         MESSAGE("load_driver: Cannot create config registry key\n" );
46         return FALSE;
47     }
48     count = sizeof(buffer);
49     if (RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count ))
50         strcpy( buffer, "x11drv" );  /* default value */
51     RegCloseKey( hkey );
52
53     if (!(graphics_driver = LoadLibraryA( buffer )))
54     {
55         MESSAGE( "Could not load graphics driver '%s'\n", buffer );
56         return FALSE;
57     }
58
59     GET_USER_FUNC(Synchronize);
60     GET_USER_FUNC(CheckFocus);
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(ToAscii);
67     GET_USER_FUNC(GetBeepActive);
68     GET_USER_FUNC(SetBeepActive);
69     GET_USER_FUNC(Beep);
70     GET_USER_FUNC(GetDIState);
71     GET_USER_FUNC(GetDIData);
72     GET_USER_FUNC(GetKeyboardConfig);
73     GET_USER_FUNC(SetKeyboardConfig);
74     GET_USER_FUNC(InitMouse);
75     GET_USER_FUNC(SetCursor);
76     GET_USER_FUNC(MoveCursor);
77     GET_USER_FUNC(GetScreenSaveActive);
78     GET_USER_FUNC(SetScreenSaveActive);
79     GET_USER_FUNC(GetScreenSaveTimeout);
80     GET_USER_FUNC(SetScreenSaveTimeout);
81     GET_USER_FUNC(LoadOEMResource);
82     GET_USER_FUNC(IsSingleWindow);
83     GET_USER_FUNC(AcquireClipboard);
84     GET_USER_FUNC(ReleaseClipboard);
85     GET_USER_FUNC(SetClipboardData);
86     GET_USER_FUNC(GetClipboardData);
87     GET_USER_FUNC(IsClipboardFormatAvailable);
88     GET_USER_FUNC(RegisterClipboardFormat);
89     GET_USER_FUNC(IsSelectionOwner);
90     GET_USER_FUNC(ResetSelectionOwner);
91
92     return TRUE;
93 }
94
95
96 /***********************************************************************
97  *           USER initialisation routine
98  */
99 BOOL WINAPI USER_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
100 {
101     HINSTANCE16 instance;
102     int queueSize;
103
104     if ( USER_HeapSel ) return TRUE;
105
106     /* Create USER heap */
107     if ((instance = LoadLibrary16( "USER.EXE" )) < 32) return FALSE;
108     USER_HeapSel = GlobalHandleToSel16( instance );
109
110      /* Global atom table initialisation */
111     if (!ATOM_Init( USER_HeapSel )) return FALSE;
112
113     /* Load the graphics driver */
114     if (!load_driver()) return FALSE;
115
116     /* Initialize window handling (critical section) */
117     WIN_Init();
118
119     /* Initialize system colors and metrics*/
120     SYSMETRICS_Init();
121     SYSCOLOR_Init();
122
123     /* Create the DCEs */
124     DCE_Init();
125
126     /* Initialize window procedures */
127     if (!WINPROC_Init()) return FALSE;
128
129     /* Initialize built-in window classes */
130     if (!WIDGETS_Init()) return FALSE;
131
132     /* Initialize dialog manager */
133     if (!DIALOG_Init()) return FALSE;
134
135     /* Initialize menus */
136     if (!MENU_Init()) return FALSE;
137
138     /* Initialize message spying */
139     if (!SPY_Init()) return FALSE;
140
141     /* Create system message queue */
142     queueSize = GetProfileIntA( "windows", "TypeAhead", 120 );
143     if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
144
145     /* Set double click time */
146     SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
147
148     /* Create message queue of initial thread */
149     InitThreadInput16( 0, 0 );
150
151     /* Create desktop window */
152     if (!WIN_CreateDesktopWindow()) return FALSE;
153
154     /* Initialize keyboard driver */
155     KEYBOARD_Enable( keybd_event, InputKeyStateTable );
156
157     /* Initialize mouse driver */
158     MOUSE_Enable( mouse_event );
159
160     /* Start processing X events */
161     USER_Driver.pUserRepaintDisable( FALSE );
162
163     return TRUE;
164 }