1 // This may look like C code, but it is really -*- C++ -*-
2
3 // ------------------------------------------------------------------
4 // The Goldware Library
5 // Copyright (C) 1990-1999 Odinn Sorensen
6 // Copyright (C) 1999-2000 Alexander S. Aganichev
7 // ------------------------------------------------------------------
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public
19 // License along with this program; if not, write to the Free
20 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 // MA 02111-1307, USA
22 // ------------------------------------------------------------------
23 // $Id: gkbdbase.h,v 1.2 2015/11/28 07:03:46 spanevin Exp $
24 // ------------------------------------------------------------------
25 // GCUI: Golded+ Character-oriented User Interface.
26 // Keyboard functions (declarations).
27 // ------------------------------------------------------------------
28
29 #ifndef __gkbdbase_h
30 #define __gkbdbase_h
31
32
33 // ------------------------------------------------------------------
34
35 #include <gtimall.h>
36
37
38 // ------------------------------------------------------------------
39 // Simple types
40
41 typedef word gkey;
42
43
44 // ------------------------------------------------------------------
45 // Keycode object
46
KCodKey(gkey & key)47 inline gkey& KCodKey(gkey &key) { return key; }
KCodAsc(gkey & key)48 inline byte& KCodAsc(gkey &key) { return *(((byte *)&key)+0); }
KCodScn(gkey & key)49 inline byte& KCodScn(gkey &key) { return *(((byte *)&key)+1); }
50
51
52 // ------------------------------------------------------------------
53 // Definition of kbuf record
54
55 struct KBuf {
56 KBuf* prev; // previous record
57 KBuf* next; // next record
58 gkey xch; // keypress
59 };
60
61
62 // ------------------------------------------------------------------
63 // Definition of onkey record
64
65 struct KBnd {
66 KBnd* prev; // pointer to previous record
67 KBnd* next; // pointer to next record
68 gkey keycode; // Scan/ASCII code of trap key
69 VfvCP func; // address of onkey function
70 gkey pass; // key to pass back, 0=don't pass
71 };
72
73
74 // ------------------------------------------------------------------
75 // Definition of keyboard info record
76
77 class GKbd {
78
79 public:
80
81 KBuf* kbuf; // Pointer to head record in key buffer
82 KBnd* onkey; // Pointer to head record in onkey list
83 KBnd* curronkey; // Pointer to current onkey record
84 int inmenu; // In-menu flag used by menuing functions
85 int source; // Source of keypress 0=kb, 1=kbuf, 2=mouse
86 int extkbd; // Extended keyboard 0=none, 1=yes
87 int polling; // Keyboard polling enabled
88 Clock tickinterval; // Minimum interval between ticks
89 Clock tickvalue; // Value from last tick
90 VfvCP tickfunc; // Function to call when a tick is generated
91 Clock tickpress; // Tick value at last keypress
92 bool inidle; // In-idle flag used by tickfunc
93 bool quitall; // Quit-all flag for menus etc.
94
95 void Init();
96 GKbd();
97 ~GKbd();
98 };
99
100 extern GKbd gkbd;
101
102
103 // ------------------------------------------------------------------
104 // Keyboard status codes returned from kbstat()
105
106 #define RSHIFT 1 // right shift pressed
107 #define LSHIFT 2 // left shift pressed
108 #define GCTRL 4 // [Ctrl] pressed
109 #define ALT 8 // [Alt] pressed
110 #define SCRLOCK 16 // [Scroll Lock] toggled
111 #define NUMLOCK 32 // [Num Lock] toggled
112 #define CAPSLOCK 64 // [Caps Lock] toggled
113 #define INS 128 // [Ins] toggled
114
115
116 // ------------------------------------------------------------------
117
118 extern gkey scancode_table[];
119 extern bool right_alt_same_as_left;
120
121
122 // ------------------------------------------------------------------
123 // Function prototypes
124
125 KBnd* chgonkey (KBnd* kblist);
126 void clearkeys ();
127 void freonkey ();
128 int setonkey (gkey keycode, VfvCP func, gkey pass);
129 gkey getxch (int __tick=false);
130 void kbclear ();
131 gkey kbmhit ();
132 gkey kbxget (int mode=0);
133 gkey kbxhit ();
134 int kbput (gkey xch);
135 word kbput_ (gkey xch);
136 void kbputs_ (char* str);
137 byte scancode (gkey ch);
138 gkey waitkey ();
139 gkey waitkeyt (int duration);
140
141 gkey key_tolower(gkey __keycode);
142
143 gkey keyscanxlat(gkey k);
144
145 gkey __kbxget(int __mode=0, long __ticks=0, VfvCP __idlefunc=NULL);
146
147 void gkbdtickpressreset();
148 void gkbdtickvaluereset();
149
150
151 // ------------------------------------------------------------------
152 // Inline functions
153
getxchtick()154 inline gkey getxchtick() { return getxch(true); }
kbdsettickfunc(VfvCP func)155 inline void kbdsettickfunc(VfvCP func) { gkbd.tickfunc = func; }
156
157
158 // ------------------------------------------------------------------
159 // Shorthand definitions of keyboard scancodes
160
161 #define KEY_BRK 0xFFFF // ^Break return from _KeyHit()/_KeyGet()
162
163
164 // ------------------------------------------------------------------
165
166
167 #if defined(__USE_NCURSES__)
168 // TODO: move L_KEY_BASE то KEY_MAX-9,
169 // TODO: change array gkbd_curstable to std::map
170 #define L_KEY_BASE (KEY_RESIZE+12)
171 #define L_KEY_AUP (L_KEY_BASE+0)
172 #define L_KEY_ADOWN (L_KEY_BASE+1)
173 #define L_KEY_ARIGHT (L_KEY_BASE+2)
174 #define L_KEY_ALEFT (L_KEY_BASE+3)
175 #define L_KEY_CUP (L_KEY_BASE+4)
176 #define L_KEY_CDOWN (L_KEY_BASE+5)
177 #define L_KEY_CRIGHT (L_KEY_BASE+6)
178 #define L_KEY_CLEFT (L_KEY_BASE+7)
179 #define L_KEY_UNUSED (L_KEY_BASE+8)
180 #endif
181
182 #endif
183
184 // ------------------------------------------------------------------
185