Fixed some issues found by winapi_check.
[wine] / dlls / ttydrv / ttydrv_main.c
1 /*
2  * TTYDRV initialization code
3  */
4
5 #include "config.h"
6
7 #include <stdio.h>
8
9 #include "winbase.h"
10 #include "wine/winbase16.h"
11 #include "clipboard.h"
12 #include "gdi.h"
13 #include "message.h"
14 #include "monitor.h"
15 #include "user.h"
16 #include "win.h"
17 #include "debugtools.h"
18 #include "ttydrv.h"
19
20 DEFAULT_DEBUG_CHANNEL(ttydrv);
21
22 static USER_DRIVER user_driver =
23 {
24     /* event functions */
25     TTYDRV_EVENT_Synchronize,
26     TTYDRV_EVENT_CheckFocus,
27     TTYDRV_EVENT_UserRepaintDisable,
28     /* keyboard functions */
29     TTYDRV_KEYBOARD_Init,
30     TTYDRV_KEYBOARD_VkKeyScan,
31     TTYDRV_KEYBOARD_MapVirtualKey,
32     TTYDRV_KEYBOARD_GetKeyNameText,
33     TTYDRV_KEYBOARD_ToAscii,
34     TTYDRV_KEYBOARD_GetBeepActive,
35     TTYDRV_KEYBOARD_SetBeepActive,
36     TTYDRV_KEYBOARD_Beep,
37     TTYDRV_KEYBOARD_GetDIState,
38     TTYDRV_KEYBOARD_GetDIData,
39     TTYDRV_KEYBOARD_GetKeyboardConfig,
40     TTYDRV_KEYBOARD_SetKeyboardConfig,
41     /* mouse functions */
42     TTYDRV_MOUSE_Init,
43     TTYDRV_MOUSE_SetCursor,
44     TTYDRV_MOUSE_MoveCursor,
45     /* screen saver functions */
46     TTYDRV_GetScreenSaveActive,
47     TTYDRV_SetScreenSaveActive,
48     TTYDRV_GetScreenSaveTimeout,
49     TTYDRV_SetScreenSaveTimeout,
50     /* windowing functions */
51     TTYDRV_IsSingleWindow
52 };
53
54 int cell_width = 8;
55 int cell_height = 8;
56 WINDOW *root_window;
57
58
59 /***********************************************************************
60  *           TTYDRV process initialisation routine
61  */
62 static void process_attach(void)
63 {
64     int rows, cols;
65
66     USER_Driver      = &user_driver;
67     CLIPBOARD_Driver = &TTYDRV_CLIPBOARD_Driver;
68     WND_Driver       = &TTYDRV_WND_Driver;
69
70 #ifdef WINE_CURSES
71     if ((root_window = initscr()))
72     {
73         werase(root_window);
74         wrefresh(root_window);
75     }
76     getmaxyx(root_window, rows, cols);
77 #else  /* WINE_CURSES */
78     rows = 60; /* FIXME: Hardcoded */
79     cols = 80; /* FIXME: Hardcoded */
80 #endif  /* WINE_CURSES */
81
82     MONITOR_PrimaryMonitor.rect.left   = 0;
83     MONITOR_PrimaryMonitor.rect.top    = 0;
84     MONITOR_PrimaryMonitor.rect.right  = cell_width * cols;
85     MONITOR_PrimaryMonitor.rect.bottom = cell_height * rows;
86     MONITOR_PrimaryMonitor.depth       = 1;
87
88     TTYDRV_GDI_Initialize();
89
90     /* load display.dll */
91     LoadLibrary16( "display" );
92 }
93
94
95 /***********************************************************************
96  *           TTYDRV process termination routine
97  */
98 static void process_detach(void)
99 {
100     TTYDRV_GDI_Finalize();
101
102 #ifdef WINE_CURSES
103     if (root_window) endwin();
104 #endif  /* WINE_CURSES */
105
106     USER_Driver      = NULL;
107     CLIPBOARD_Driver = NULL;
108     WND_Driver       = NULL;
109 }
110
111
112 /***********************************************************************
113  *           TTYDRV initialisation routine
114  */
115 BOOL WINAPI TTYDRV_Init( HINSTANCE hinst, DWORD reason, LPVOID reserved )
116 {
117     static int process_count;
118
119     switch(reason)
120     {
121     case DLL_PROCESS_ATTACH:
122         if (!process_count++) process_attach();
123         break;
124
125     case DLL_PROCESS_DETACH:
126         if (!--process_count) process_detach();
127         break;
128     }
129     return TRUE;
130 }
131
132
133 /***********************************************************************
134  *              TTYDRV_GetScreenSaveActive
135  *
136  * Returns the active status of the screen saver
137  */
138 BOOL TTYDRV_GetScreenSaveActive(void)
139 {
140     return FALSE;
141 }
142
143 /***********************************************************************
144  *              TTYDRV_SetScreenSaveActive
145  *
146  * Activate/Deactivate the screen saver
147  */
148 void TTYDRV_SetScreenSaveActive(BOOL bActivate)
149 {
150     FIXME("(%d): stub\n", bActivate);
151 }
152
153 /***********************************************************************
154  *              TTYDRV_GetScreenSaveTimeout
155  *
156  * Return the screen saver timeout
157  */
158 int TTYDRV_GetScreenSaveTimeout(void)
159 {
160     return 0;
161 }
162
163 /***********************************************************************
164  *              TTYDRV_SetScreenSaveTimeout
165  *
166  * Set the screen saver timeout
167  */
168 void TTYDRV_SetScreenSaveTimeout(int nTimeout)
169 {
170     FIXME("(%d): stub\n", nTimeout);
171 }
172
173 /***********************************************************************
174  *              TTYDRV_IsSingleWindow
175  */
176 BOOL TTYDRV_IsSingleWindow(void)
177 {
178     return TRUE;
179 }