-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsuix_gui.js
378 lines (331 loc) · 9.71 KB
/
jsuix_gui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
// JS/UIX v0.44
// (c) mass:werk (N.Landsteiner) 2003
// all rights reserved
// term gui
var conf_term_x=102;
var conf_term_y=34;
var conf_kbd_offset=34;
var termImgPath='jsuix_support/';
var termDiv='termDiv';
var termBgColor='#181818';
var termFrameColor='#555555';
var termPageColor='#222222';
var conf_repeat_delay1=320;
var conf_repeat_delay2=170;
var termKbdDiv='termKbdDiv';
var termKbdBgColor='#222222';
var keycapspath='jsuix_support/keycaps/';
var termSubDivs=false;
var termLayers=false;
var termDocNS4=null;
var termStringStart='';
var termStringEnd='';
var termKbdDocNS4=null;
var termKbdOn=false;
var keycapsShift=false;
var keycapsCpslk=false;
var keycapsShiftRef=new Array();
var keycapsCpslkRef=new Array();
var termSpecials=new Array();
termSpecials[0]=' ';
termSpecials[1]='$';
termSpecials[2]=' ';
termSpecials[3]='?';
termSpecials[4]='#';
termSpecials[32]=' ';
termSpecials[34]='"';
termSpecials[38]='&';
termSpecials[60]='<';
termSpecials[62]='>';
termSpecials[127]='◊';
var termStyles=new Array(1,2,4,8);
var termStyleOpen=new Array();
var termStyleClose=new Array();
termStyleOpen[1]='<SPAN CLASS="termReverse">';
termStyleClose[1]='<\/SPAN>';
termStyleOpen[2]='<U>';
termStyleClose[2]='<\/U>';
termStyleOpen[4]='<I>';
termStyleClose[4]='<\/I>';
termStyleOpen[8]='<STRIKE>';
termStyleClose[8]='<\/STRIKE>';
// buttons UI
var termImgNames=new Array('left_lo', 'left_hi', 'right_lo', 'right_hi', 'delete_lo', 'delete_hi', 'esc_lo', 'esc_hi', 'kbd_show_lo', 'kbd_show_hi', 'kbd_hide_lo', 'kbd_hide_hi');
var termImages=new Array();
function termImgPreload(path,imgnames) {
for (var i=0; i<imgnames.length; i++) {
var n=imgnames[i];
termImages[n]=new Image();
termImages[n].src=path+n+'.gif'
}
}
if (document.images) termImgPreload(termImgPath,termImgNames);
function termSetImg(n,v) {
if (document.images) {
var img=(termLayers)? termDocNS4.images['term_'+n] : document.images['term_'+n];
var stat=(v)? '_hi' : '_lo';
img.src=termImages[n+stat].src
}
}
// UI keyboard
// key maps (200=left shift, 202=right shift, 204=CpsLock)
var termKeyMap= [
[96,49,50,51,52,53,54,55,56,57,48,45,61,8],
[27,113,119,101,114,116,121,117,105,111,112,91,93,13],
[204,97,115,100,102,103,104,106,107,108,59,39,35],
[200,92,122,120,99,118,98,110,109,44,46,47,30,202],
[32,28,31,29]
];
var termKeyMapShift=[
[126,33,34,35,36,37,94,38,42,40,41,95,43,8],
[27,81,87,69,82,84,89,85,73,79,80,123,125,13],
[204,65,83,68,70,71,72,74,75,76,58,34,64],
[200,124,90,88,67,86,66,78,77,60,62,63,30,202],
[32,28,31,29]
];
var termKeyMapCpslk=[
[96,49,50,51,52,53,54,55,56,57,48,45,61,8],
[27,81,87,69,82,84,89,85,73,79,80,91,93,13],
[204,65,83,68,70,71,72,74,75,76,59,39,35],
[200,92,90,88,67,86,66,78,77,44,46,47,30,202],
[32,28,31,29]
];
var termKeyWdth=[
[35,35,35,35,35,35,35,35,35,35,35,35,35,69],
[55,35,35,35,35,35,35,35,35,35,35,35,35,0],
[65,35,35,35,35,35,35,35,35,35,35,35,35],
[49,35,35,35,35,35,35,35,35,35,35,35,35,54],
[252,35,35,35]
];
var keycapsImgNames=new Array(200,201,202,203,204,205);
function termKeyCaps(k) {
if ((k<28) && (k>=32) && (repeatTimer)) clearTimeout(repeatTimer);
if (k==204) {
keycapsCpslk=(!keycapsCpslk);
var cnr=(keycapsCpslk)? 205:204;
termKbdSetImg(204,cnr)
}
else if ((k==200) || (k==202)) {
keycapsShift=(!keycapsShift);
var m=(keycapsShift)? 1:0;
termKbdSetImg(200,200+m);
termKbdSetImg(202,202+m)
}
else {
var ch=0;
if (keycapsShift) {
ch=keycapsShiftRef[k]
keycapsShift=false;
termKbdSetImg(200,200);
termKbdSetImg(202,202)
}
else if (keycapsCpslk) ch=keycapsCpslkRef[k]
else ch=k;
keyHandler({which:ch,jsuix_remapped:true})
}
}
function termKbdSetImg(n,v) {
if (document.images) {
var img=(termLayers)? termKbdDocNS4.images['key'+n] : document.images['key'+n];
img.src=termImages[v].src
}
}
function termSetKbdButton(v) {
if (document.images) {
var img=(termLayers)? termDocNS4.images.term_kbd_show : document.images.term_kbd_show;
var n=(termKbdOn)? 'kbd_hide' : 'kbd_show';
var stat=(v)? '_hi' : '_lo';
img.src=termImages[n+stat].src
}
}
function termKbdShow() {
if (termKbdOn) {
setDivVisibility(termKbdDiv,0);
termKbdOn=false;
termSetKbdButton(0)
}
else {
termImgPreload(keycapspath,keycapsImgNames);
keycapsShift=false;
keycapsCpslk=false;
var s='';
writeElement(termKbdDiv,s);
setDivXY(termKbdDiv,conf_term_x,conf_term_y+conf_kbd_offset+conf_rows*conf_rowheigt);
if (termLayers) termKbdDocNS4=document.layers[termKbdDiv].document;
termKbdOn=true;
setDivVisibility(termKbdDiv,1);
termSetKbdButton(0)
}
}
function termMakeKbd() {
var s='';
return s
}
// term UI
function termHide() {
if (repeatTimer) clearTimeout(repeatTimer);
if (termKbdOn) termKbdShow();
setDivVisibility(termDiv,0)
}
function makeTerm() {
window.status='Building terminal ...';
termLayers=(document.layers)? true:false;
termSubDivs=(navigator.userAgent.indexOf('Gecko')<0);
var s='';
s+='<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">\n';
s+='<TR><TD BGCOLOR="'+termFrameColor+'" COLSPAN="2"><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="2"><TR><TD BGCOLOR="'+termBgColor+'"><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">\n';
var rstr='';
for (var c=0; c<conf_cols; c++) rstr+=' ';
for (var r=0; r<conf_rows; r++) {
var id=((termLayers) || (termSubDivs))? '' : ' ID="term_'+r+'"';
s+='<TR><TD NOWRAP HEIGHT="'+conf_rowheigt+'"'+id+' CLASS="term">'+rstr+'<\/TD><\/TR>\n';
};
if (termLayers) {
for (var r=0; r<conf_rows; r++) {
s+='<LAYER NAME="term_'+r+'" TOP="'+(3+r*conf_rowheigt)+'" LEFT="3" CLASS="term"><\/LAYER>\n'
};
termDocNS4=document.layers[termDiv].document;
termStringStart='<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD NOWRAP HEIGHT="'+conf_rowheigt+'" CLASS="term">';
termStringEnd='<\/TD><\/TR><\/TABLE>';
}
else if (termSubDivs) {
for (var r=0; r<conf_rows; r++) {
s+='<DIV ID="term_'+r+'" STYLE="position:absolute; top:'+(3+r*conf_rowheigt)+'px; left: 3px;" CLASS="term"><\/DIV>\n'
};
termStringStart='<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD NOWRAP HEIGHT="'+conf_rowheigt+'" CLASS="term">';
termStringEnd='<\/TD><\/TR><\/TABLE>';
};
writeElement(termDiv,s);
setDivXY(termDiv,conf_term_x,conf_term_y);
setDivVisibility(termDiv,1);
window.status=''
}
function termDisplay(r) {
var s=termStringStart;
var curStyle=0;
for (var i=0; i<conf_cols; i++) {
var c=term[r][i];
var cs=termStyle[r][i];
if (cs!=curStyle) {
if (curStyle) {
for (var k=termStyles.length-1; k>=0; k--) {
var st=termStyles[k];
if (curStyle&st) s+=termStyleClose[st];
}
};
curStyle=cs;
for (var k=0; k<termStyles.length; k++) {
var st=termStyles[k];
if (curStyle&st) s+=termStyleOpen[st];
}
};
s+= (termSpecials[c])? termSpecials[c] : String.fromCharCode(c);
};
if (curStyle>0) {
for (var k=termStyles.length-1; k>=0; k--) {
var st=termStyles[k];
if (curStyle&st) s+=termStyleClose[st];
}
};
s+=termStringEnd;
writeElement('term_'+r,s,termDocNS4)
}
function termGuiReady() {
ready=true;
if (termGuiElementReady(termDiv, self.document)) {
for (var r=0; r<conf_rows; r++) {
if (termGuiElementReady('term_'+r,termDocNS4)==false) {
ready=false;
break
}
}
}
else ready=false;
return ready
}
function cursorKbdLeft() {
keyHandler({which:28})
}
function cursorKbdRight() {
keyHandler({which:29})
}
function termKbdBackspace() {
keyHandler({which:8})
}
function termKbdEsc() {
keyHandler({which:27})
}
function termKbdClear() {
if ((!cnslLock) && (!cnslRawMode)) cnslReset();
}
// UI-button repeat
function repeatSet(cmd,on) {
if (repeatTimer) clearTimeout(repeatTimer);
repeatTimer=setTimeout('repeatDo("'+cmd+'")',conf_repeat_delay1);
}
function repeatClear() {
if (repeatTimer) clearTimeout(repeatTimer);
}
function repeatDo(cmd) {
if (repeatTimer) clearTimeout(repeatTimer);
if (cmd=='left') cursorKbdLeft()
else if (cmd=='right') cursorKbdRight()
else if (cmd=='backspace') termKbdBackspace();
repeatTimer=setTimeout('repeatDo("'+cmd+'")',conf_repeat_delay2);
}
// basic dynamics
function writeElement(e,t,d) {
if (document.layers) {
var doc=(d)? d : self.document;
doc.layers[e].document.open();
doc.layers[e].document.write(t);
doc.layers[e].document.close()
}
else if (document.getElementById) {
var obj=document.getElementById(e);
obj.innerHTML=t
}
else if (document.all) {
document.all[e].innerHTML=t
}
}
function setDivXY(d,x,y) {
if (document.layers) {
document.layers[d].moveTo(x,y)
}
else if (document.getElementById) {
var obj=document.getElementById(d);
obj.style.left=x+'px';
obj.style.top=y+'px'
}
else if (document.all) {
document.all[d].style.left=x+'px';
document.all[d].style.top=y+'px'
}
}
function setDivVisibility(d,v) {
if (document.layers) {
document.layers[d].visibility= (v)? 'show':'hide';
}
else if (document.getElementById) {
var obj=document.getElementById(d);
obj.style.visibility= (v)? 'visible':'hidden';
}
else if (document.all) {
document.all[d].style.visibility= (v)? 'visible':'hidden';
}
}
function termGuiElementReady(e,d) {
if (document.layers) {//specific to Netscape
var doc=(d)? d : self.document;
return ((doc) && (doc.layers[e]))? true:false
}
else if (document.getElementById) {//all
return (document.getElementById(e))? true:false
}
else if (document.all) {//specific to Internet Explorer
return (document.all[e])? true:false
}
else return false
}
//eof