1 /*    console.h
2  *
3  *    Copyright (c) 1994-1996, Marko Macek
4  *
5  *    You may distribute under the terms of either the GNU General Public
6  *    License or the Artistic License, as specified in the README file.
7  *
8  */
9 
10 #ifndef CONSOLE_H
11 #define CONSOLE_H
12 
13 #include "fte.h"
14 
15 /* don't change these, used as index */
16 enum {
17     DCH_C1,	/// upper left corner
18     DCH_C2,	/// upper right corner
19     DCH_C3,	/// lower left corner
20     DCH_C4,	/// lower right corner
21     DCH_H,	/// horizontal line
22     DCH_V,	/// vertical line
23     DCH_M1,	/// tee pointing down
24     DCH_M2,	/// tee pointing right
25     DCH_M3,	/// tee pointing left
26     DCH_M4,	/// tee pointing up
27     DCH_X,	/// crossover  10
28     DCH_RPTR,	/// arrow pointing right
29     DCH_EOL,	/// usually print as bullet
30     DCH_EOF,	/// usually print as diamond
31     DCH_END,	///
32     DCH_AUP,	/// arrow pointing up
33     DCH_ADOWN,	/// arrow pointing down
34     DCH_HFORE,	/// full square block
35     DCH_HBACK,	/// checker board (stipple)
36     DCH_ALEFT,	/// arrow pointing left
37     DCH_ARIGHT	/// arrow pointing right
38 };
39 
40 #define ConMaxCols 256
41 #define ConMaxRows 128
42 
43 enum TEventScroll {
44     csUp,
45     csDown,
46     csLeft,
47     csRight
48 };
49 
50 #define evNone             0
51 #define evKeyDown     0x0001
52 #define evKeyUp       0x0002
53 #define evMouseDown   0x0010
54 #define evMouseUp     0x0020
55 #define evMouseMove   0x0040
56 #define evMouseAuto   0x0080
57 #define evCommand     0x0100
58 #define evBroadcast   0x0200
59 #define evNotify      0x0400
60 
61 #define evKeyboard    (evKeyDown | evKeyUp)
62 #define evMouse       (evMouseDown | evMouseUp | evMouseMove | evMouseAuto)
63 #define evMessage     (evCommand | evBroadcast)
64 
65 #include "conkbd.h"
66 
67 enum TEventCommands {
68     cmRefresh = 1,
69     cmResize,
70     cmClose,
71     cmPipeRead,
72     cmMainMenu,
73     cmPopupMenu, // 6
74 
75     /* vertical scroll */
76 
77     cmVScrollUp, // 10
78     cmVScrollDown,
79     cmVScrollPgUp,
80     cmVScrollPgDn,
81     cmVScrollMove, // 14
82 
83 /* horizontal scroll */
84 
85     cmHScrollLeft, // 15
86     cmHScrollRight,
87     cmHScrollPgLt,
88     cmHScrollPgRt,
89     cmHScrollMove, // 19
90 
91     cmDroppedFile = 30,
92     cmRenameFile   /* TODO: in-place editing of titlebar */
93 };
94 
95 typedef unsigned char TAttr;
96 typedef unsigned char TChar;
97 
98 // we need to use class instead of casting to short
99 // otherwice we would need to resolve CPU ordering issues
100 #ifdef NTCONSOLE
101 #define WIN32_LEAN_AND_MEAN
102 #include <windows.h>
103 class TCell : public CHAR_INFO {
104 public:
105     TCell(char c = ' ', TAttr a = 0x07) {
106         Char.AsciiChar = c;
107         Attributes = a;
108     }
GetChar()109     char GetChar() const { return Char.AsciiChar; }
GetAttr()110     TAttr GetAttr() const { return Attributes; }
SetChar(char c)111     void SetChar(char c) { Char.AsciiChar = c; }
SetAttr(TAttr a)112     void SetAttr(TAttr a) { Attributes = a; }
Set(char c,TAttr a)113     void Set(char c, TAttr a) { SetChar(c); SetAttr(a); }
114     bool operator==(const TCell &c) const {
115 	return (Char.AsciiChar == c.Char.AsciiChar
116 		&& Attributes == c.Attributes);
117     }
118 };
119 #else
120 class TCell {
121     TChar Char;
122     TAttr Attr;
123     operator const char*();
124     operator const unsigned char*();
125     operator unsigned char*();
126     operator char*();
127 public:
Char(c)128     TCell(TChar c = ' ', TAttr a = 0x07) : Char(c), Attr(a) {}
GetChar()129     TChar GetChar() const { return Char; }
GetAttr()130     TAttr GetAttr() const { return Attr; }
SetChar(TChar c)131     void SetChar(TChar c) { Char = c; }
SetAttr(TAttr a)132     void SetAttr(TAttr a) { Attr = a; }
Set(TChar c,TAttr a)133     void Set(TChar c, TAttr a) { SetChar(c); SetAttr(a); }
134     bool operator==(const TCell &c) const {
135 	return (Char == c.Char && Attr == c.Attr);
136     }
137 };
138 #endif
139 
140 typedef TCell *PCell;
141 typedef TCell TDrawBuffer[ConMaxCols];
142 typedef TDrawBuffer *PDrawBuffer;
143 typedef unsigned long TEventMask;
144 typedef unsigned long TKeyCode;
145 typedef unsigned long TCommand;
146 
147 class EModel; // forward
148 class GView;
149 
150 struct TKeyEvent {
151     TEventMask What;
152     GView* View;
153     TKeyCode Code;
154 };
155 
156 struct TMouseEvent {
157     TEventMask What;
158     GView* View;
159     int X;
160     int Y;
161     unsigned short Buttons;
162     unsigned short Count;
163     TKeyCode KeyMask;
164 };
165 
166 struct TMsgEvent {
167     TEventMask What;
168     GView *View;
169     EModel *Model;
170     TCommand Command;
171     long Param1;
172     void *Param2;
173 };
174 
175 union TEvent {
176     TEventMask What;
177     TKeyEvent Key;
178     TMouseEvent Mouse;
179     TMsgEvent Msg;
180     char fill[32];
181 };
182 
183 #define SUBMENU_NORMAL      (-1)
184 #define SUBMENU_CONDITIONAL (-2)
185 
186 struct mItem {
187     char *Name;
188     char *Arg;
189     int SubMenu;
190     int Cmd;
191 };
192 
193 struct mMenu {
194     char *Name;
195     unsigned Count;
196     mItem *Items;
197 };
198 
199 extern int MenuCount;
200 extern mMenu *Menus;
201 
202 int ConInit(int XSize, int YSize);
203 int ConDone();
204 int ConSuspend();
205 int ConContinue();
206 int ConSetTitle(const char *Title, const char *STitle);
207 int ConGetTitle(char *Title, size_t MaxLen, char *STitle, size_t SMaxLen);
208 
209 int ConClear();
210 int ConPutBox(int X, int Y, int W, int H, PCell Cell);
211 int ConGetBox(int X, int Y, int W, int H, PCell Cell);
212 int ConPutLine(int X, int Y, int W, int H, PCell Cell);
213 int ConSetBox(int X, int Y, int W, int H, TCell Cell);
214 int ConScroll(int Way, int X, int Y, int W, int H, TAttr Fill, int Count);
215 
216 int ConSetSize(int X, int Y);
217 int ConQuerySize(int *X, int *Y);
218 
219 int ConSetCursorPos(int X, int Y);
220 int ConQueryCursorPos(int *X, int *Y);
221 int ConShowCursor();
222 int ConHideCursor();
223 int ConCursorVisible();
224 int ConSetCursorSize(int Start, int End);
225 
226 #ifdef CONFIG_MOUSE
227 int ConSetMousePos(int X, int Y);
228 int ConQueryMousePos(int *X, int *Y);
229 int ConShowMouse();
230 int ConHideMouse();
231 int ConMouseVisible();
232 int ConQueryMouseButtons(int *ButtonCount);
233 #endif
234 
235 int ConGetEvent(TEventMask EventMask, TEvent* Event, int WaitTime, int Delete);
236 int ConPutEvent(const TEvent& Event);
237 
238 void MoveCh(PCell B, char Ch, TAttr Attr, size_t Count);
239 void MoveChar(PCell B, int Pos, int Width, const char Ch, TAttr Attr, size_t Count);
240 void MoveMem(PCell B, int Pos, int Width, const char* Ch, TAttr Attr, size_t Count);
241 void MoveStr(PCell B, int Pos, int Width, const char* Ch, TAttr Attr, size_t MaxCount);
242 void MoveCStr(PCell B, int Pos, int Width, const  char* Ch, TAttr A0, TAttr A1, size_t MaxCount);
243 void MoveAttr(PCell B, int Pos, int Width, TAttr Attr, size_t Count);
244 void MoveBgAttr(PCell B, int Pos, int Width, TAttr Attr, size_t Count);
245 
246 size_t CStrLen(const char *s);
247 
248 int NewMenu(const char *Name);
249 int NewItem(int menu, const char *Name);
250 int NewSubMenu(int menu, const char *Name, int submenu, int type);
251 int GetMenuId(const char *Name);
252 
253 char ConGetDrawChar(unsigned int index);
254 
255 extern char WindowFont[64];
256 
257 struct TRGBColor {
258     unsigned char r, g, b;
259 };
260 
261 extern TRGBColor RGBColor[16];
262 extern bool RGBColorValid[16];
263 
264 #endif // CONSOLE_H
265