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