-revert janderwalds change until because it breaks the gcc 4.x build
[reactos.git] / reactos / base / applications / network / telnet / src / tconsole.h
1 #ifndef __TNPARSER_H
2 #define __TNPARSER_H
3
4 #include "tnconfig.h"
5
6 /* A diagram of the following values:
7 *
8 * (0,0)
9 * +----------------------------------------+
10 * | |
11 * | |
12 * | |
13 * | |
14 * | |
15 * | |
16 * | |
17 * | |
18 * | |
19 * | |
20 * | |
21 * | |
22 * | |
23 * | CON_TOP |
24 * +---------------------------+.....?......| ---
25 * | . | | |
26 * | . | <-- OR --> | |
27 * | . | | |
28 * CON_LEFT | . | CON_RIGHT |
29 * (=0) | . | (=CON_ | CON_LINES
30 * |..............* | WIDTH) |
31 * | (CON_CUR_X, | | |
32 * | CON_CUR_Y) | | |
33 * | | | |
34 * | | | |
35 * | | | |
36 * +---------------------------+------------+ ---
37 * CON_BOTTOM (=CON_TOP + CON_HEIGHT)
38 *
39 * |--------- CON_COLS --------|
40 *
41 * Keep in mind that CON_TOP, CON_BOTTOM, CON_LEFT, and CON_RIGHT are relative
42 * to zero, but CON_CUR_X, CON_CUR_Y, CON_WIDTH, and CON_HEIGHT are relative to
43 * CON_TOP and CON_LEFT
44 */
45
46 #define CON_TOP ConsoleInfo.srWindow.Top
47 #define CON_BOTTOM ConsoleInfo.srWindow.Bottom
48
49 #define CON_LEFT 0
50 #define CON_RIGHT (ConsoleInfo.dwSize.X - 1)
51
52 #define CON_HEIGHT (CON_BOTTOM - CON_TOP)
53 #define CON_WIDTH (CON_RIGHT - CON_LEFT)
54 #define CON_LINES (CON_HEIGHT + 1)
55 #define CON_COLS (CON_WIDTH + 1)
56
57 #define CON_CUR_X (ConsoleInfo.dwCursorPosition.X - CON_LEFT)
58 #define CON_CUR_Y (ConsoleInfo.dwCursorPosition.Y - CON_TOP)
59
60
61 class TConsole {
62 public:
63 TConsole(HANDLE hConsole);
64 ~TConsole();
65 void sync();
66
67 // Cursor movement routines
68 int GetRawCursorX() {return CON_CUR_X;}
69 int GetRawCursorY() {return CON_CUR_Y;}
70 int GetCursorX() {return CON_CUR_X;}
71 int GetCursorY() {
72 if(iScrollStart != -1)
73 return CON_CUR_Y - iScrollStart;
74 return GetRawCursorY();
75 }
76 void SetRawCursorPosition(int x, int y);
77 void SetCursorPosition(int x, int y);
78 void SetCursorSize(int pct);
79 void MoveCursorPosition(int x, int y);
80
81 // Screen mode/size routines
82 int GetWidth() {return CON_COLS;}
83 int GetHeight() {return CON_LINES;}
84 void SetExtendedMode(int iFunction, BOOL bEnable);
85 void SetWindowSize(int width, int height); // Set the size of the window,
86 // but not the buffer
87
88 // Color/attribute routines
89 void SetAttrib(unsigned char wAttr) {wAttributes = wAttr;}
90 unsigned char GetAttrib() {return wAttributes;}
91 void Normal(); // Reset all attributes
92 void HighVideo(); // Aka "bold"
93 void LowVideo();
94 void SetForeground(unsigned char wAttrib); // Set the foreground directly
95 void SetBackground(unsigned char wAttrib);
96 void BlinkOn(); // Blink on/off
97 void BlinkOff();
98 void UnderlineOn(); // Underline on/off
99 void UnderlineOff();
100 void UlBlinkOn(); // Blink+Underline on/off
101 void UlBlinkOff();
102 void ReverseOn(); // Reverse on/off
103 void ReverseOff();
104 void Lightbg(); // High-intensity background
105 void Darkbg(); // Low-intensity background
106 void setDefaultFg(unsigned char u) {defaultfg = u;}
107 void setDefaultBg(unsigned char u) {defaultbg = u;}
108
109 // Text output routines
110 unsigned long WriteText(const char *pszString, unsigned long cbString);
111 unsigned long WriteString(const char* pszString, unsigned long cbString);
112 unsigned long WriteStringFast(const char *pszString, unsigned long cbString);
113 unsigned long WriteCtrlString(const char* pszString, unsigned long cbString);
114 unsigned long WriteCtrlChar(char c);
115 unsigned long NetWriteString(const char* pszString, unsigned long cbString);
116
117 // Clear screen/screen area functions
118 void ClearScreen(char c = ' ');
119 void ClearWindow(int start, int end, char c = ' ');
120 void ClearEOScreen(char c = ' ');
121 void ClearBOScreen(char c = ' ');
122 void ClearLine(char c = ' ');
123 void ClearEOLine(char c = ' ');
124 void ClearBOLine(char c = ' ');
125
126 // Scrolling and text output control functions
127 void SetScroll(int start, int end);
128 void ScrollDown(int iStartRow , int iEndRow, int bUp);
129 void ScrollAll(int bUp) {ScrollDown(iScrollStart, iScrollEnd, bUp);}
130 void index();
131 void reverse_index();
132 void setLineWrap(bool bEnabled){
133 if(!ini.get_lock_linewrap())
134 ini.set_value("Wrap_Line", bEnabled ? "true" : "false");
135 }
136 bool getLineWrap() {return ini.get_wrapline();}
137
138 // Insert/delete characters/lines
139 void InsertLine(int numlines); // Added by Titus von Boxberg 30/3/97
140 void InsertCharacter(int numchar); // "
141 void DeleteCharacter(int numchar); // "
142 void InsertMode(int i) {insert_mode = i;}
143
144 // Miscellaneous functions
145 void Beep();
146
147 protected:
148 HANDLE hConsole;
149
150 CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
151
152 unsigned char wAttributes;
153 unsigned char fg, bg;
154 unsigned char defaultfg, defaultbg;
155 unsigned char origfg, origbg;
156
157 bool blink;
158 bool underline;
159 bool reverse;
160
161 int iScrollStart;
162 int iScrollEnd;
163 int insert_mode;
164 };
165
166 // Non-member functions for saving state -- used by the scrollback buffer viewer
167 void saveScreen(CHAR_INFO* chiBuffer);
168 void restoreScreen(CHAR_INFO* chiBuffer);
169 CHAR_INFO* newBuffer();
170 void deleteBuffer(CHAR_INFO* chiBuffer);
171
172 #endif