Cleaned up internal types definition.
[wine] / console / generic.c
1 /* generic.c */
2 /* Copyright 1999 - Joseph Pranevich */
3
4 /* This is a driver to implement, when possible, "high-level"
5    routines using only low level calls. This is to make it possible
6    to have accelerated functions for the individual drivers...
7    or to simply not bother with them. */
8
9 /* When creating new drivers, you need to assign all the functions that
10    that driver supports into the driver struct. If it is a supplementary
11    driver, it should make sure to perserve the old values. */
12
13 #include <stdio.h>
14
15 #include "console.h"
16 #include "config.h"
17 #include "debugtools.h"
18
19 DEFAULT_DEBUG_CHANNEL(console);
20
21 static void GENERIC_MoveLine(char row1, char row2, char col1, char col2);
22 static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
23    int attribute);
24 void GENERIC_Start(void)
25 {
26    /* Here, we only want to add a driver if there is not one already
27       defined. */
28
29    TRACE("GENERIC_Start\n");
30
31    if (!driver.clearWindow)
32       driver.clearWindow = GENERIC_ClearWindow;
33
34    if (!driver.scrollUpWindow)
35       driver.scrollUpWindow = GENERIC_ScrollUpWindow;
36
37    if (!driver.scrollDownWindow)
38       driver.scrollDownWindow = GENERIC_ScrollDownWindow;
39
40    if (!driver.getCharacter)
41       driver.getCharacter = GENERIC_GetCharacter;
42 }
43
44 void GENERIC_ClearWindow(char row1, char col1, char row2, char col2, 
45    int bg_color, int attribute)
46 {
47    char trow, tcol, x;
48    int old_refresh;
49
50    /* Abort if we have only partial functionality */
51    if (!(driver.getCursorPosition && driver.moveCursor && driver.write))
52       return;
53
54    old_refresh = CONSOLE_GetRefresh();
55    CONSOLE_SetRefresh(FALSE);
56
57    CONSOLE_GetCursorPosition(&trow, &tcol);
58    
59    for (x = row1; x <= row2; x++)
60       GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
61
62    CONSOLE_MoveCursor(trow, tcol);
63
64    CONSOLE_SetRefresh(old_refresh);
65 }      
66
67 void GENERIC_ScrollUpWindow(char row1, char col1, char row2, char col2, 
68    char lines, int bg_color, int attribute)
69 {
70    /* Scroll Up Window: Characters go down */
71
72    char trow, tcol, x;
73    int old_refresh;
74
75    TRACE("Scroll Up %d lines from %d to %d.\n", lines, row1,
76       row2);
77
78    /* Abort if we have only partial functionality */
79    if (!(driver.getCursorPosition && driver.moveCursor && driver.write
80       && driver.getCharacterAtCursor && driver.clearWindow))
81       return;
82    
83    /* Save initial state... */
84    old_refresh = CONSOLE_GetRefresh();
85    CONSOLE_SetRefresh(FALSE);
86    CONSOLE_GetCursorPosition(&trow, &tcol);
87
88    for (x = row1 + lines; x <= row2; x++)
89    {
90       GENERIC_MoveLine(x, x - lines, col1, col2);
91       GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
92    }
93
94    /* Restore State */
95    CONSOLE_MoveCursor(trow, tcol); 
96    CONSOLE_SetRefresh(old_refresh);
97 }
98
99 void GENERIC_ScrollDownWindow(char row1, char col1, char row2, char col2, 
100    char lines, int bg_color, int attribute)
101 {
102    /* Scroll Down Window: Characters go up */
103
104    char trow, tcol, x;
105    int old_refresh;
106
107    /* Abort if we have only partial functionality */
108    if (!(driver.getCursorPosition && driver.moveCursor && driver.write
109       && driver.getCharacterAtCursor && driver.clearWindow))
110       return;
111    
112    /* Save initial state... */
113    old_refresh = CONSOLE_GetRefresh();
114    CONSOLE_SetRefresh(FALSE);
115    CONSOLE_GetCursorPosition(&trow, &tcol);
116
117    for (x = row2; x >= row1 + lines; x--)
118    {
119       GENERIC_MoveLine(x, x + lines, col1, col2);
120       GENERIC_ClearLine(x, col1, col1, bg_color, attribute);
121    }
122
123    /* Restore State */
124    CONSOLE_MoveCursor(trow, tcol); 
125    CONSOLE_SetRefresh(old_refresh);
126 }
127
128 char GENERIC_GetCharacter()
129 {
130    /* Keep getting keys until we get one with a char value */
131    char ch = (char) 0, scan;
132    
133    while (!ch)
134    {
135       CONSOLE_GetKeystroke(&scan, &ch);
136    }
137    return ch;
138 }
139
140 static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
141    int attribute)
142 {
143    /* This function is here to simplify the logic of the scroll and clear
144       functions but may be useful elsewhere. If it can be used from
145       outside here, it should be made non-static */
146
147    char x;
148
149    TRACE("Clear Line: %d from %d to %d (unused: bgcolor %d, attrib %d).\n", row, col1, col2, bgcolor, attribute);
150
151    for (x = col1; x <= col2; x++)
152    {
153       CONSOLE_MoveCursor(row, x);
154       CONSOLE_Write(' ', 0, 0, 0);
155    }
156
157    /* Assume that the calling function will make sure that the cursor is
158    repositioned properly. If this becomes non-static, that will need to be
159    changed. */
160 }
161    
162 static void GENERIC_MoveLine(char row1, char row2, char col1, char col2)
163 {
164    /* This function is here to simplify the logic of the scroll and clear
165       functions but may be useful elsewhere. If it can be used from
166       outside here, it should be made non-static */
167
168    char x;
169    int bg_color, fg_color, attribute;
170    char ch;
171
172    TRACE("Move Line: Move %d to %d.\n", row1, row2);
173
174    for (x = col1; x <= col2; x++)
175    {
176       CONSOLE_MoveCursor(row1, x);
177       CONSOLE_GetCharacterAtCursor(&ch, &fg_color, &bg_color, &attribute);
178       CONSOLE_MoveCursor(row2, x);
179       CONSOLE_Write(ch, fg_color, bg_color, attribute);
180    }
181
182    /* Assume that the calling function will make sure that the cursor is
183    repositioned properly. If this becomes non-static, that will need to be
184    changed. */
185 }