Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2010, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
/******************************************************************************
37
*
38
* keyin.c:
39
*
40
* Copyright The Numerical Algorithms Group Limited 1991, 1992, 1993.
41
*
42
****************************************************************************/
43
44
#include <X11/keysym.h>
45
#include "openaxiom-c-macros.h"
46
#include "debug.h"
47
#include "halloc.h"
48
#include "sockio.h"
49
#include "hyper.h"
50
#include "keyin.h"
51
#include "event.h"
52
#include "parse.h"
53
#include "scrollbar.h"
54
55
56
#define min(x,y) ( (x<y)?(x):(y))
57
58
int in_cursor_height;
59
int in_cursor_width;
60
int out_cursor_height;
61
int out_cursor_width;
62
int in_cursor_y;
63
int out_cursor_y;
64
int start_x;
65
int start_y;
66
int simple_box_width;
67
int gInInsertMode = 0;
68
69
unsigned int ModifiersMask = ShiftMask | LockMask | ControlMask
70
| Mod1Mask | Mod2Mask | Mod3Mask
71
| Mod4Mask | Mod5Mask;
72
73
unsigned int UnsupportedModMask = LockMask | ControlMask
74
| Mod1Mask | Mod2Mask | Mod3Mask
75
| Mod4Mask | Mod5Mask;
76
77
/*
78
* This routine returns the modifier mask associated
79
* to a key symbol.
80
*/
81
82
static unsigned int
83
get_modifier_mask(KeySym sym)
84
{
85
unsigned int i, mask;
86
XModifierKeymap *mod;
87
KeyCode kcode;
88
const int masks[8] = {
89
ShiftMask, LockMask, ControlMask,
90
Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
91
};
92
93
mod = XGetModifierMapping(gXDisplay);
94
kcode = XKeysymToKeycode(gXDisplay,sym);
95
96
if (mod) {
97
for (i = 0; i < (8 * mod->max_keypermod); i++){
98
if (!mod->modifiermap[i]) continue;
99
else if (kcode == mod->modifiermap[i]){
100
mask = masks[i / mod->max_keypermod];
101
XFreeModifiermap(mod);
102
return mask;
103
}
104
}
105
XFreeModifiermap(mod);
106
}
107
return 0;
108
}
109
110
/*
111
* Since the user can't tell me directly what name to use here, I am going to
112
* let it be a default property. This way the user can link to whatever page
113
* he/she wants. If it is a link right to the quit page, then I will just
114
* quit right away. Otherwise I will try to find the page, and display it.
115
*/
116
117
static char *protected_quit;
118
119
HyperLink *quitLink; /** the global link to the quit page ***/
120
121
void
122
handle_key(XEvent *event)
123
{
124
char key_buffer[20];
125
int key_buffer_size = 20;
126
KeySym keysym;
127
XComposeStatus compstatus;
128
int charcount;
129
int display_again = 0;
130
const char *name;
131
char *filename;
132
/*char *head = "echo htadd -l ";*/
133
/*char *blank1 = " ";*/
134
/*char *blank2 = " \n";*/
135
char buffer[180];
136
FILE *filehandle;
137
138
charcount = XLookupString((XKeyEvent *)event, key_buffer, key_buffer_size, &keysym ,&compstatus); /* 5 args */
139
140
key_buffer[charcount] = '\0';
141
switch (keysym) {
142
case XK_Prior:
143
case XK_F29:
144
scrollUpPage();
145
break;
146
case XK_Next:
147
case XK_F35:
148
scrollDownPage();
149
break;
150
case XK_F3:
151
case XK_F12:
152
quitHyperDoc();
153
break;
154
case XK_F5:
155
if (event->xkey.state & ShiftMask) {
156
name = gWindow->page->name;
157
filename = gWindow->page->filename;
158
sprintf(buffer, "htadd -l %s\n", filename);
159
system(buffer);
160
filehandle = (FILE *) hash_find(&gFileHashTable, filename);
161
fclose(filehandle);
162
hash_delete(&gFileHashTable, filename);
163
gWindow->fMacroHashTable =
164
(HashTable *) halloc(sizeof(HashTable), "macro hash");
165
hash_init(
166
gWindow->fMacroHashTable,
167
MacroHashSize,
168
(EqualFunction ) string_equal,
169
(HashcodeFunction) string_hash);
170
gWindow->fPatchHashTable = (HashTable *) halloc(sizeof(HashTable), "patch hash");
171
hash_init(
172
gWindow->fPatchHashTable,
173
PatchHashSize,
174
(EqualFunction ) string_equal,
175
(HashcodeFunction) string_hash);
176
gWindow->fPasteHashTable = (HashTable *) halloc(sizeof(HashTable), "paste hash");
177
hash_init(gWindow->fPasteHashTable,
178
PasteHashSize,
179
(EqualFunction ) string_equal,
180
(HashcodeFunction) string_hash);
181
gWindow->fCondHashTable = (HashTable *) halloc(sizeof(HashTable), "cond hash");
182
hash_init(
183
gWindow->fCondHashTable,
184
CondHashSize,
185
(EqualFunction ) string_equal,
186
(HashcodeFunction) string_hash);
187
gWindow->fPageHashTable = (HashTable *) halloc(sizeof(HashTable), "page hash");
188
hash_init(
189
gWindow->fPageHashTable,
190
PageHashSize,
191
(EqualFunction ) string_equal,
192
(HashcodeFunction) string_hash);
193
make_special_pages(gWindow->fPageHashTable);
194
read_ht_db(
195
gWindow->fPageHashTable,
196
gWindow->fMacroHashTable,
197
gWindow->fPatchHashTable);
198
gWindow->page = (HyperDocPage *) hash_find(gWindow->fPageHashTable, name);
199
if (gWindow->page == NULL) {
200
fprintf(stderr, "lose...gWindow->page for %s is null\n", name);
201
exit(-1);
202
}
203
display_again = 1;
204
}
205
break;
206
case XK_F9:
207
make_window_link(KeyDefsHelpPage);
208
break;
209
case XK_Tab:
210
if (event->xkey.state & ShiftMask)
211
prev_input_focus();
212
else if (event->xkey.state & ModifiersMask)
213
BeepAtTheUser();
214
else
215
next_input_focus();
216
break;
217
case XK_Return:
218
if (!(event->xkey.state & ShiftMask)) {
219
next_input_focus();
220
break;
221
}
222
223
/* next ones fall through to input area handling */
224
225
case XK_Escape:
226
if (!gWindow->page->current_item)
227
break;
228
case XK_F1:
229
if (!gWindow->page->current_item) {
230
gWindow->page->helppage = alloc_string(NoMoreHelpPage);
231
helpForHyperDoc();
232
break;
233
}
234
case XK_Home:
235
if (!gWindow->page->current_item) {
236
scrollToFirstPage();
237
break;
238
}
239
case XK_Up:
240
if (!gWindow->page->current_item) {
241
scrollUp();
242
break;
243
}
244
case XK_Down:
245
if (!gWindow->page->current_item) {
246
scrollDown();
247
break;
248
}
249
250
default:
251
display_again = 0;
252
dialog(event, keysym, key_buffer);
253
XFlush(gXDisplay);
254
break;
255
}
256
257
if (display_again) {
258
display_page(gWindow->page);
259
gWindow->fWindowHashTable = gWindow->page->fLinkHashTable;
260
}
261
}
262
263
264
/*
265
* This routine initializes some of the variables needed by the input
266
* strings, and boxes.
267
*/
268
269
void
270
init_keyin()
271
{
272
char *prop;
273
unsigned nlm = get_modifier_mask(XK_Num_Lock);
274
UnsupportedModMask &= ~nlm;
275
ModifiersMask &= ~nlm;
276
277
/*
278
* First set all the values for when the active cursor is in the window
279
*/
280
281
in_cursor_height = 2;
282
in_cursor_y = gInputFont->max_bounds.ascent +
283
gInputFont->max_bounds.descent;
284
in_cursor_width = gInputFont->max_bounds.width;
285
286
/*
287
* Now for when the cursor is empty
288
*/
289
290
out_cursor_height = gInputFont->max_bounds.ascent +
291
gInputFont->max_bounds.descent;
292
out_cursor_y = 2;
293
out_cursor_width = in_cursor_width;
294
295
start_x = 5;
296
297
start_y = gInputFont->max_bounds.ascent;
298
299
/*
300
* Find out How big I should make the simple boxes
301
*/
302
303
simple_box_width = XTextWidth(gInputFont, "X", 1) + 5;
304
305
prop = XGetDefault(gXDisplay, gArgv[0], "ProtectedQuit");
306
307
if (prop == NULL) {
308
protected_quit = (char *) halloc(strlen("ProtectedPage") + 1,
309
"protected_quit");
310
strcpy(protected_quit, "ProtectedPage");
311
}
312
else {
313
protected_quit = (char *) halloc(strlen(prop) + 1, "protected_quit");
314
strcpy(protected_quit, prop);
315
}
316
317
318
}
319
320