-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFrameCanvas.cpp
More file actions
7980 lines (7256 loc) · 248 KB
/
FrameCanvas.cpp
File metadata and controls
7980 lines (7256 loc) · 248 KB
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
////////////////////////////////////////////////////////////////////////////
// Name: FrameCanvas.cpp
// Purpose: Implmentation of Frame and Canvas
// Authors: Paul Koning, Joe Stanton, Bill Galcher, Steve Zoppi, Dale Sinder
// Created: 03/26/2005
// Copyright: (c) Paul Koning, Joe Stanton, Dale Sinder
// Licence: see pterm-license.txt
/////////////////////////////////////////////////////////////////////////////
#include "CommonHeader.h"
#include "PtermFrame.h"
#include "PtermCanvas.h"
#include "PtermConnDialog.h"
#include "DebugPterm.h"
#include "PtermConnFailDialog.h"
#include "PtermPrefDialog.h"
/*
The key of the Pterm V5 design is that it just uses a 512x512 bitmap with
raw pixel access to construct most of the screen content, then it displays
that bitmap on the window. Similarly, it displays that bitmap on the
printout, or processes it for save-screen, etc. Display transformations
like stretch and 2x scale are done when that bitmap is displayed, not
by making the bitmap itself different.
*/
// ptermkeytabs.h is generated by composed.py. It defines a number of
// character mapping tables:
// asciiToPlato maps ASCII (7 bit) keyboard character values to the
// corresponding PLATO key code(s). Each entry is either None (ignored)
// or the KEY macro specifying up to four PLATO key codes, with None as
// filler if less than four are needed. Note that this table only has
// entries for keystrokes whose shift handling is the same as in a
// conventional ASCII keyboard. For example, SPACE is not listed here
// (it is handled explicitly elsewhere in the code) because shift-SPACE
// is backspace.
// pastedAsciiToPlato -- same as asciiToPlato except that this one is
// used to map ASCII character codes found in paste strings. Most
// control characters are unused here, and SPACE is a normal entry.
// unicodeToPlato -- a lookup table consisting of pairs; each entry is a
// Unicode character code and the corresponding PLATO key sequence.
// The entries are in ascending order to allow for binary search, if
// desired. There are entries here for precomposed characters (like
// O with umlaut) as well as for the separate accent marks (like
// combining umlaut).
// autobsmap -- a lookup table of autobsentry items. Each entry maps
// a sequence of up to 3 Unicode characters to a replacement Unicode
// character. The inputs correspond to entries in the screen text map:
// characters plotted, including any autobackspaced bits like accents
// or parts of composite characters. The output is the Unicode character
// we want to use for that sequence.
#include "ptermkeytabs.h"
// the application icon (under Windows and OS/2 it is in resources)
#if defined (__WXGTK__) || defined (__WXMOTIF__) || defined (__WXMAC__) || defined (__WXMGL__) || defined (__WXX11__)
#include "pterm_32.xpm"
#endif
// Keycode translation for ALT-keypress. -1 means not valid. Note that as
// a general rule, ALT and Control produce the same outcome (if control key
// accelerators are disabled).
const i8 altKeyToPlato[128] =
{
/* */
/* 000- */ -1, -1, -1, -1, -1, -1, -1, -1,
/* */
/* 010- */ -1, -1, -1, -1, -1, -1, -1, -1,
/* */
/* 020- */ -1, -1, -1, -1, -1, -1, -1, -1,
/* */
/* 030- */ -1, -1, -1, -1, -1, -1, -1, -1,
/* space ! " # $ % & ' */
/* 040- */ -1, -1, -1, -1, -1, -1, -1, -1,
/* ( ) * + , - . / */
/* 050- */ -1, -1, -1, 0056, -1, 0057, -1, -1,
/* 0 1 2 3 4 5 6 7 */
/* 060- */ -1, -1, -1, -1, -1, -1, -1, -1,
/* 8 9 : ; < = > ? */
/* 070- */ -1, -1, -1, -1, -1, 0015, -1, -1,
/* @ A B C D E F G */
/* 100- */ -1, 0062, 0070, 0073, 0071, 0067, 0064, 0053,
/* H I J K L M N O */
/* 110- */ 0065, -1, -1, -1, 0075, 0064, 0066, -1,
/* P Q R S T U V W */
/* 120- */ 0060, 0074, 0063, 0072, 0062, -1, -1, -1,
/* X Y Z [ \ ] ^ _ */
/* 130- */ 0052, 0061, -1, -1, -1, -1, -1, -1,
/* ` a b c d e f g */
/* 140- */ -1, 0022, 0030, 0033, 0031, 0027, 0064, 0013,
/* h i j k l m n o */
/* 150- */ 0025, -1, -1, -1, 0035, 0024, 0026, -1,
/* p q r s t u v w */
/* 160- */ 0020, 0034, 0023, 0032, 0062, -1, -1, -1,
/* x y z { | } ~ */
/* 170- */ 0012, 0021, -1, -1, -1, -1, -1, -1
};
/*
** This table is for translating PLATO text as it would appear in a
** upper case only printout. Shift shows up as a separate character (')
** and has to be handled specially, and some other punctuation characters
** have unexpected meanings:
** " multiply
** # divide
** & super
** ! sub
** ? cr
** \ font
** ^ access
** @ backspace
** _ assign
** In this table, the unshifted code values appear. -1 means no
** translation, -2 marks Shift.
*/
const int printoutToPlato[128] =
{
/* */
/* 000- */ -1, -1, -1, -1, -1, -1, -1, -1,
/* */
/* 010- */ -1, 014, 026, -1, -1, -1, -1, -1,
/* */
/* 020- */ -1, -1, -1, -1, -1, -1, -1, -1,
/* */
/* 030- */ -1, -1, -1, -1, -1, -1, -1, -1,
/* space ! " # $ % & ' */
/* 040- */ 0100, 0021, 0012, 0013, 0044, 0045, 0020, -2,
/* ( ) * + , - . / */
/* 050- */ 0051, 0173, 0050, 0016, 0137, 0017, 0136, 0135,
/* 0 1 2 3 4 5 6 7 */
/* 060- */ 0000, 0001, 0002, 0003, 0004, 0005, 0006, 0007,
/* 8 9 : ; < = > ? */
/* 070- */ 0010, 0011, 0174, 0134, 0040, 0133, 0041, 0175,
/* @ A B C D E F G */
/* 100- */ 0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
/* H I J K L M N O */
/* 110- */ 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
/* P Q R S T U V W */
/* 120- */ 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
/* X Y Z [ \ ] ^ _ */
/* 130- */ 0130, 0131, 0132, 0042, 0064, 0043, 0074, 0015,
/* ` a b c d e f g */
/* 140- */ -1, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
/* h i j k l m n o */
/* 150- */ 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
/* p q r s t u v w */
/* 160- */ 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
/* x y z { | } ~ */
/* 170- */ 0130, 0131, 0132, -1, -1, -1, -1, -1,
};
// A bunch of these characters are outside the ASCII set, so they are
// written as Unicode escapes. Too bad C doesn't accept plain Unicode
// text inside quoted strings, as Python does. Comments say what characters
// those escapes reference.
// The first 64 characters are for the set 0 codes; the rest are for
// the set 1 codes. Codes past offset 64 in set 1 correspond to the
// "special" characters in ASCII mode, which are essentially built-in
// composites that on a Classic terminal would be made by the formatter.
// Here we just treat them as extra characters for simplicity.
static const wxChar rom01char[] =
L":abcdefg"
L"hijklmno"
L"pqrstuvw"
L"xyz01234"
L"56789+-*"
L"/()$= ,."
L"\u00F7[]%\u00D7\u21E6'\"" // divide, multiply, left arrow (assign)
L"!;<>_?\u2AA2 " // double greater than (plato "arrow")
L"#ABCDEFG"
L"HIJKLMNO"
L"PQRSTUVW"
L"XYZ\u02DC\u00A8^\u00B4`" // small tilde, dieresis, acute
L"\u2191\u2192\u2193\u2190" // up, right, down, left arrow
L"~\u03A3\u0394\u222A" // Sigma, Delta, union
L"\u2229{}&\u2260 |\u00B0" // intersection, not-equal, degree
L"\u2263\u03B1\u03B2\u03B4" // equiv, alpha, beta, delta
L"\u03BB\u03BC\u03C0\u03C1" // lambda, mu, pi, rho
L"\u03C3\u03C9\u2264\u2265" // sigma, omega, less/equal, grt/equal
L"\u0398@\\ " // Theta
L"\u2993\u2994\u00A9\u25AB" // embed left, right, copyright, box
L"\u25C6\u2715\u02C7\u2195" // diamond, cross prod, hacek, up/down
L"\u25CB\u00B8"; // dot product, cedilla
// Tables to map ASCII characters to the correct character image. There
// are two tables, one for the M0 set, one for the M1 set. Note that
// these sets do not directly correspond to the classic terminal sets.
// Each table is indexed by the ASCII character code (7 bit value).
//
// The value found in the table is the classic ROM character index for
// this character, in the low 7 bits. The top bit selects M0 vs. M1
// in the classic ROM. 0xff means unused code.
//
// Codes 0xc0 and up are specials (ASCII only extra character codes); in
// the classic terminal these are instead formatted as sequences or codes
// with displayed Y position, but in ASCII they are directly coded as
// additional characters. We simply handle these as additional character
// shapes, stored in the M1 character ROM data beyond the usual 64 entries.
//
// 0xc0: embed left
// 0xc1: embed right
// 0xc2: copyright body
// 0xc3: box
// 0xc4: diamond
// 0xc5: cross product
// 0xc6: hacek
// 0xc7: universal delimiter
// 0xc8: dot product
// 0xc9: cedilla
static const u8 asciiM0[] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x2d, 0x38, 0x37, 0x80, 0x2b, 0x33, 0xab, 0x36,
0x29, 0x2a, 0x27, 0x25, 0x2e, 0x26, 0x2f, 0x28,
0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22,
0x23, 0x24, 0x00, 0x39, 0x3a, 0x2c, 0x3b, 0x3d,
0xbd, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x31, 0xbe, 0x32, 0x9d, 0x3c,
0x9f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0xa9, 0xae, 0xaa, 0xa4, 0xff
};
static const u8 asciiM1[] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x2d, 0x28, 0xb0, 0x9b, 0x35, 0xac, 0xa0, 0xa1,
0xa2, 0xa3, 0x34, 0xa5, 0xa6, 0xa7, 0xa8, 0x30,
0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8,
0xb9, 0xba, 0xbb, 0xbc, 0xc0, 0xaf, 0xc1, 0x3e,
0xc2, 0x9c, 0xc3, 0xc8, 0xc4, 0xc5, 0x9e, 0xc9,
0xc6, 0xc7, 0xae, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
static const u8 asciiKeycodes[] =
{ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x26, 0x60, 0x0a, 0x5e, 0x2b, 0x2d,
0x13, 0x04, 0x07, 0x08, 0x7b, 0x0b, 0x0d, 0x1a,
0x02, 0x12, 0x01, 0x03, 0x7d, 0x0c, 0xff, 0xff,
0x3c, 0x3e, 0x5b, 0x5d, 0x24, 0x25, 0x5f, 0x7c,
0x2a, 0x28, 0x40, 0x27, 0x1c, 0x5c, 0x23, 0x7e,
0x17, 0x05, 0x14, 0x19, 0x7f, 0x09, 0x1e, 0x18,
0x0e, 0x1d, 0x11, 0x16, 0x00, 0x0f, 0xff, 0xff,
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x3d, 0x3b, 0x2f, 0x2e, 0x2c,
0x1f, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x29, 0x3a, 0x3f, 0x21, 0x22
};
// Conversion from ascii mode codes to classic codes
static const u8 ascmode[] = { 0, 3, 2, 1 };
/* data for plato font, set 0. */
const unsigned short plato_m0[] = {
0x0000, 0x0000, 0x0330, 0x0330, 0x0000, 0x0000, 0x0000, 0x0000, // :
0x0060, 0x0290, 0x0290, 0x0290, 0x0290, 0x01e0, 0x0010, 0x0000, // a
0x1ff0, 0x0120, 0x0210, 0x0210, 0x0210, 0x0120, 0x00c0, 0x0000, // b
0x00c0, 0x0120, 0x0210, 0x0210, 0x0210, 0x0210, 0x0120, 0x0000, // c
0x00c0, 0x0120, 0x0210, 0x0210, 0x0210, 0x0120, 0x1ff0, 0x0000, // d
0x00c0, 0x01a0, 0x0290, 0x0290, 0x0290, 0x0290, 0x0190, 0x0000, // e
0x0000, 0x0000, 0x0210, 0x0ff0, 0x1210, 0x1000, 0x0800, 0x0000, // f
0x01a8, 0x0254, 0x0254, 0x0254, 0x0254, 0x0194, 0x0208, 0x0000, // g
0x1000, 0x1ff0, 0x0100, 0x0200, 0x0200, 0x0200, 0x01f0, 0x0000, // h
0x0000, 0x0000, 0x0210, 0x13f0, 0x0010, 0x0000, 0x0000, 0x0000, // i
0x0000, 0x0002, 0x0202, 0x13fc, 0x0000, 0x0000, 0x0000, 0x0000, // j
0x1010, 0x1ff0, 0x0080, 0x0140, 0x0220, 0x0210, 0x0010, 0x0000, // k
0x0000, 0x0000, 0x1010, 0x1ff0, 0x0010, 0x0000, 0x0000, 0x0000, // l
0x03f0, 0x0200, 0x0200, 0x01f0, 0x0200, 0x0200, 0x01f0, 0x0000, // m
0x0200, 0x03f0, 0x0100, 0x0200, 0x0200, 0x0200, 0x01f0, 0x0000, // n
0x00c0, 0x0120, 0x0210, 0x0210, 0x0210, 0x0120, 0x00c0, 0x0000, // o
0x03fe, 0x0120, 0x0210, 0x0210, 0x0210, 0x0120, 0x00c0, 0x0000, // p
0x00c0, 0x0120, 0x0210, 0x0210, 0x0210, 0x0120, 0x03fe, 0x0000, // q
0x0200, 0x03f0, 0x0100, 0x0200, 0x0200, 0x0200, 0x0100, 0x0000, // r
0x0120, 0x0290, 0x0290, 0x0290, 0x0290, 0x0290, 0x0060, 0x0000, // s
0x0200, 0x0200, 0x1fe0, 0x0210, 0x0210, 0x0210, 0x0000, 0x0000, // t
0x03e0, 0x0010, 0x0010, 0x0010, 0x0010, 0x03e0, 0x0010, 0x0000, // u
0x0200, 0x0300, 0x00c0, 0x0030, 0x00c0, 0x0300, 0x0200, 0x0000, // v
0x03e0, 0x0010, 0x0020, 0x01c0, 0x0020, 0x0010, 0x03e0, 0x0000, // w
0x0200, 0x0210, 0x0120, 0x00c0, 0x00c0, 0x0120, 0x0210, 0x0000, // x
0x0382, 0x0044, 0x0028, 0x0010, 0x0020, 0x0040, 0x0380, 0x0000, // y
0x0310, 0x0230, 0x0250, 0x0290, 0x0310, 0x0230, 0x0000, 0x0000, // z
0x0010, 0x07e0, 0x0850, 0x0990, 0x0a10, 0x07e0, 0x0800, 0x0000, // 0
0x0000, 0x0000, 0x0410, 0x0ff0, 0x0010, 0x0000, 0x0000, 0x0000, // 1
0x0000, 0x0430, 0x0850, 0x0890, 0x0910, 0x0610, 0x0000, 0x0000, // 2
0x0000, 0x0420, 0x0810, 0x0910, 0x0910, 0x06e0, 0x0000, 0x0000, // 3
0x0000, 0x0080, 0x0180, 0x0280, 0x0480, 0x0ff0, 0x0080, 0x0000, // 4
0x0000, 0x0f10, 0x0910, 0x0910, 0x0920, 0x08c0, 0x0000, 0x0000, // 5
0x0000, 0x03e0, 0x0510, 0x0910, 0x0910, 0x00e0, 0x0000, 0x0000, // 6
0x0000, 0x0800, 0x0830, 0x08c0, 0x0b00, 0x0c00, 0x0000, 0x0000, // 7
0x0000, 0x06e0, 0x0910, 0x0910, 0x0910, 0x06e0, 0x0000, 0x0000, // 8
0x0000, 0x0700, 0x0890, 0x0890, 0x08a0, 0x07c0, 0x0000, 0x0000, // 9
0x0000, 0x0080, 0x0080, 0x03e0, 0x0080, 0x0080, 0x0000, 0x0000, // +
0x0000, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0000, 0x0000, // -
0x0000, 0x0240, 0x0180, 0x0660, 0x0180, 0x0240, 0x0000, 0x0000, // *
0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0000, // /
0x0000, 0x0000, 0x0000, 0x0000, 0x07e0, 0x0810, 0x1008, 0x0000, // (
0x1008, 0x0810, 0x07e0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // )
0x0640, 0x0920, 0x0920, 0x1ff0, 0x0920, 0x0920, 0x04c0, 0x0000, // $
0x0000, 0x0140, 0x0140, 0x0140, 0x0140, 0x0140, 0x0000, 0x0000, // =
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // space
0x0000, 0x0000, 0x0034, 0x0038, 0x0000, 0x0000, 0x0000, 0x0000, // ,
0x0000, 0x0000, 0x0030, 0x0030, 0x0000, 0x0000, 0x0000, 0x0000, // .
0x0000, 0x0080, 0x0080, 0x02a0, 0x0080, 0x0080, 0x0000, 0x0000, // divide
0x0000, 0x0000, 0x0000, 0x0000, 0x1ff8, 0x1008, 0x1008, 0x0000, // [
0x1008, 0x1008, 0x1ff8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ]
0x0c20, 0x1240, 0x0c80, 0x0100, 0x0260, 0x0490, 0x0860, 0x0000, // %
0x0000, 0x0000, 0x0240, 0x0180, 0x0180, 0x0240, 0x0000, 0x0000, // multiply
0x0080, 0x0140, 0x0220, 0x0770, 0x0140, 0x0140, 0x0140, 0x0000, // assign
0x0000, 0x0000, 0x0000, 0x1c00, 0x0000, 0x0000, 0x0000, 0x0000, // '
0x0000, 0x0000, 0x1c00, 0x0000, 0x1c00, 0x0000, 0x0000, 0x0000, // "
0x0000, 0x0000, 0x0000, 0x1f90, 0x0000, 0x0000, 0x0000, 0x0000, // !
0x0000, 0x0000, 0x0334, 0x0338, 0x0000, 0x0000, 0x0000, 0x0000, // ;
0x0000, 0x0080, 0x0140, 0x0220, 0x0410, 0x0000, 0x0000, 0x0000, // <
0x0000, 0x0000, 0x0410, 0x0220, 0x0140, 0x0080, 0x0000, 0x0000, // >
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, // _
0x0000, 0x0c00, 0x1000, 0x10d0, 0x1100, 0x0e00, 0x0000, 0x0000, // ?
0x1c1c, 0x1224, 0x0948, 0x0490, 0x0220, 0x0140, 0x0080, 0x0000, // arrow
0x0000, 0x0000, 0x0000, 0x000a, 0x0006, 0x0000, 0x0000, 0x0000, // cedilla
};
/* data for plato font, set 1. */
const unsigned short plato_m1[] = {
0x0500, 0x0500, 0x1fc0, 0x0500, 0x1fc0, 0x0500, 0x0500, 0x0000, // #
0x07f0, 0x0900, 0x1100, 0x1100, 0x1100, 0x0900, 0x07f0, 0x0000, // A
0x1ff0, 0x1210, 0x1210, 0x1210, 0x1210, 0x0e10, 0x01e0, 0x0000, // B
0x07c0, 0x0820, 0x1010, 0x1010, 0x1010, 0x1010, 0x0820, 0x0000, // C
0x1ff0, 0x1010, 0x1010, 0x1010, 0x1010, 0x0820, 0x07c0, 0x0000, // D
0x1ff0, 0x1110, 0x1110, 0x1110, 0x1010, 0x1010, 0x1010, 0x0000, // E
0x1ff0, 0x1100, 0x1100, 0x1100, 0x1000, 0x1000, 0x1000, 0x0000, // F
0x07c0, 0x0820, 0x1010, 0x1010, 0x1090, 0x1090, 0x08e0, 0x0000, // G
0x1ff0, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x1ff0, 0x0000, // H
0x0000, 0x1010, 0x1010, 0x1ff0, 0x1010, 0x1010, 0x0000, 0x0000, // I
0x0020, 0x0010, 0x1010, 0x1010, 0x1fe0, 0x1000, 0x1000, 0x0000, // J
0x1ff0, 0x0080, 0x0100, 0x0280, 0x0440, 0x0820, 0x1010, 0x0000, // K
0x1ff0, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0000, // L
0x1ff0, 0x0800, 0x0400, 0x0200, 0x0400, 0x0800, 0x1ff0, 0x0000, // M
0x1ff0, 0x0800, 0x0600, 0x0100, 0x00c0, 0x0020, 0x1ff0, 0x0000, // N
0x07c0, 0x0820, 0x1010, 0x1010, 0x1010, 0x0820, 0x07c0, 0x0000, // O
0x1ff0, 0x1100, 0x1100, 0x1100, 0x1100, 0x1100, 0x0e00, 0x0000, // P
0x07c0, 0x0820, 0x1010, 0x1018, 0x1014, 0x0824, 0x07c0, 0x0000, // Q
0x1ff0, 0x1100, 0x1100, 0x1180, 0x1140, 0x1120, 0x0e10, 0x0000, // R
0x0e20, 0x1110, 0x1110, 0x1110, 0x1110, 0x1110, 0x08e0, 0x0000, // S
0x1000, 0x1000, 0x1000, 0x1ff0, 0x1000, 0x1000, 0x1000, 0x0000, // T
0x1fe0, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x1fe0, 0x0000, // U
0x1800, 0x0700, 0x00c0, 0x0030, 0x00c0, 0x0700, 0x1800, 0x0000, // V
0x1fe0, 0x0010, 0x0020, 0x03c0, 0x0020, 0x0010, 0x1fe0, 0x0000, // W
0x1830, 0x0440, 0x0280, 0x0100, 0x0280, 0x0440, 0x1830, 0x0000, // X
0x1800, 0x0400, 0x0200, 0x01f0, 0x0200, 0x0400, 0x1800, 0x0000, // Y
0x1830, 0x1050, 0x1090, 0x1110, 0x1210, 0x1410, 0x1830, 0x0000, // Z
0x0000, 0x1000, 0x2000, 0x2000, 0x1000, 0x1000, 0x2000, 0x0000, // ~
0x0000, 0x0000, 0x1000, 0x0000, 0x1000, 0x0000, 0x0000, 0x0000, // dieresis
0x0000, 0x1000, 0x2000, 0x4000, 0x2000, 0x1000, 0x0000, 0x0000, // circumflex
0x0000, 0x0000, 0x0000, 0x1000, 0x2000, 0x4000, 0x0000, 0x0000, // acute
0x0000, 0x4000, 0x2000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, // grave
0x0000, 0x0100, 0x0300, 0x07f0, 0x0300, 0x0100, 0x0000, 0x0000, // uparrow
0x0080, 0x0080, 0x0080, 0x0080, 0x03e0, 0x01c0, 0x0080, 0x0000, // rtarrow
0x0000, 0x0040, 0x0060, 0x07f0, 0x0060, 0x0040, 0x0000, 0x0000, // downarrow
0x0080, 0x01c0, 0x03e0, 0x0080, 0x0080, 0x0080, 0x0080, 0x0000, // leftarrow
0x0000, 0x0080, 0x0100, 0x0100, 0x0080, 0x0080, 0x0100, 0x0000, // low tilde
0x1010, 0x1830, 0x1450, 0x1290, 0x1110, 0x1010, 0x1010, 0x0000, // Sigma
0x0030, 0x00d0, 0x0310, 0x0c10, 0x0310, 0x00d0, 0x0030, 0x0000, // Delta
0x0000, 0x0380, 0x0040, 0x0040, 0x0040, 0x0380, 0x0000, 0x0000, // union
0x0000, 0x01c0, 0x0200, 0x0200, 0x0200, 0x01c0, 0x0000, 0x0000, // intersect
0x0000, 0x0000, 0x0000, 0x0080, 0x0f78, 0x1004, 0x1004, 0x0000, // {
0x1004, 0x1004, 0x0f78, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000, // }
0x00e0, 0x0d10, 0x1310, 0x0c90, 0x0060, 0x0060, 0x0190, 0x0000, // &
0x0150, 0x0160, 0x0140, 0x01c0, 0x0140, 0x0340, 0x0540, 0x0000, // not equal
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // space
0x0000, 0x0000, 0x0000, 0x1ff0, 0x0000, 0x0000, 0x0000, 0x0000, // |
0x0000, 0x0c00, 0x1200, 0x1200, 0x0c00, 0x0000, 0x0000, 0x0000, // degree
0x0000, 0x02a0, 0x02a0, 0x02a0, 0x02a0, 0x02a0, 0x0000, 0x0000, // equiv
0x01e0, 0x0210, 0x0210, 0x01a0, 0x0060, 0x0090, 0x0310, 0x0000, // alpha
0x0002, 0x03fc, 0x0510, 0x0910, 0x0910, 0x0690, 0x0060, 0x0000, // beta
0x0000, 0x0ce0, 0x1310, 0x1110, 0x0890, 0x0460, 0x0000, 0x0000, // delta
0x0000, 0x1030, 0x0cc0, 0x0300, 0x00c0, 0x0030, 0x0000, 0x0000, // lambda
0x0002, 0x0002, 0x03fc, 0x0010, 0x0010, 0x03e0, 0x0010, 0x0000, // mu
0x0100, 0x0200, 0x03f0, 0x0200, 0x03f0, 0x0200, 0x0400, 0x0000, // pi
0x0006, 0x0038, 0x00e0, 0x0110, 0x0210, 0x0220, 0x01c0, 0x0000, // rho
0x00e0, 0x0110, 0x0210, 0x0310, 0x02e0, 0x0200, 0x0200, 0x0000, // sigma
0x01e0, 0x0210, 0x0010, 0x00e0, 0x0010, 0x0210, 0x01e0, 0x0000, // omega
0x0220, 0x0220, 0x0520, 0x0520, 0x08a0, 0x08a0, 0x0000, 0x0000, // less/equal
0x0000, 0x08a0, 0x08a0, 0x0520, 0x0520, 0x0220, 0x0220, 0x0000, // greater/equal
0x07c0, 0x0920, 0x1110, 0x1110, 0x1110, 0x0920, 0x07c0, 0x0000, // theta
0x01e0, 0x0210, 0x04c8, 0x0528, 0x05e8, 0x0220, 0x01c0, 0x0000, // @
0x0400, 0x0200, 0x0100, 0x0080, 0x0040, 0x0020, 0x0010, 0x0000, /* \ */
0x01e0, 0x0210, 0x0210, 0x01e0, 0x0290, 0x0290, 0x01a0, 0x0000, // oe
// "Special" character patterns: these are beyond the regular
// 6-bit character indices, and are used when "special" ASCII
// mode characters are encountered. Rather than display them
// from pieces, we just treat them as additional character
// patterns.
0x0000, 0x0080, 0x0140, 0x0220, 0x07f0, 0x0810, 0x1008, 0x0000, // l-embed
0x1008, 0x0810, 0x07f0, 0x0220, 0x0140, 0x0080, 0x0000, 0x0000, // r-embed
0x2184, 0x2244, 0x2424, 0x2424, 0x2424, 0x2424, 0x2244, 0x2004, // copyright
0x0000, 0x03c0, 0x0240, 0x0240, 0x0240, 0x03c0, 0x0000, 0x0000, // box
0x0080, 0x01c0, 0x03e0, 0x07f0, 0x03e0, 0x01c0, 0x0080, 0x0000, // diamond
0x0410, 0x0220, 0x0140, 0x0080, 0x0140, 0x0220, 0x0410, 0x0000, // cross
0x0000, 0x4000, 0x2000, 0x1000, 0x2000, 0x4000, 0x0000, 0x0000, // hacek
0x0000, 0x0140, 0x0360, 0x07f0, 0x0360, 0x0140, 0x0000, 0x0000, // delim
0x0000, 0x0180, 0x0240, 0x0240, 0x0180, 0x0000, 0x0000, 0x0000, // dot prod
0x0000, 0x0000, 0x0000, 0x0002, 0x0004, 0x0008, 0x0000, 0x0000, // cedilla
};
// On Mac, Arial is not a standard font, so you get warnings about
// partial matches. Helvetica is, though (and besides, that's what
// Arial really is) so use that name on Mac.
#if defined (__WXMAC__)
#define SSFONT "Helvetica"
#else
#define SSFONT "Arial"
#endif
// ----------------------------------------------------------------------------
// event tables and other macros for wxWindows
// ----------------------------------------------------------------------------
// the event tables connect the wxWindows events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE (PtermFrame, wxFrame)
EVT_IDLE (PtermFrame::OnIdle)
EVT_CLOSE (PtermFrame::OnClose)
EVT_TIMER (Pterm_Timer, PtermFrame::OnTimer)
EVT_TIMER (Pterm_Mclock, PtermFrame::OnMclock)
EVT_TIMER (Pterm_Dclock, PtermFrame::OnDclock)
EVT_TIMER (Pterm_Mz80, PtermFrame::OnMz80)
EVT_TIMER (Pterm_PasteTimer, PtermFrame::OnPasteTimer)
EVT_ACTIVATE (PtermFrame::OnActivate)
EVT_MENU (Pterm_ConnectAgain, PtermFrame::OnConnectAgain)
EVT_MENU (Pterm_Close, PtermFrame::OnQuit)
#if !defined (__WXMAC__)
EVT_MENU (Pterm_ToggleMenuBar, PtermFrame::OnToggleMenuBar)
#endif
EVT_MENU (Pterm_ToggleStatusBar, PtermFrame::OnToggleStatusBar)
// The scale handler is set dynamically when the view menu is built
//EVT_MENU (Pterm_SetScaleEntry, PtermFrame::OnSetScaleEntry)
EVT_MENU (Pterm_ToggleStretchMode, PtermFrame::OnSetStretchMode)
EVT_MENU (Pterm_ToggleAspectMode, PtermFrame::OnSetAspectMode)
EVT_MENU (Pterm_CopyScreen, PtermFrame::OnCopyScreen)
EVT_MENU (Pterm_ToggleLock, PtermFrame::OnLockPosition)
EVT_MENU (Pterm_RestoreLocation, PtermFrame::OnRestorePosition)
EVT_MENU (Pterm_Copy, PtermFrame::OnCopy)
EVT_MENU (Pterm_Exec, PtermFrame::OnExec)
EVT_MENU (Pterm_MailTo, PtermFrame::OnMailTo)
EVT_MENU (Pterm_SearchThis, PtermFrame::OnSearchThis)
EVT_MENU (Pterm_Macro0, PtermFrame::OnMacro0)
EVT_MENU (Pterm_Macro1, PtermFrame::OnMacro1)
EVT_MENU (Pterm_Macro2, PtermFrame::OnMacro2)
EVT_MENU (Pterm_Macro3, PtermFrame::OnMacro3)
EVT_MENU (Pterm_Macro4, PtermFrame::OnMacro4)
EVT_MENU (Pterm_Macro5, PtermFrame::OnMacro5)
EVT_MENU (Pterm_Macro6, PtermFrame::OnMacro6)
EVT_MENU (Pterm_Macro7, PtermFrame::OnMacro7)
EVT_MENU (Pterm_Macro8, PtermFrame::OnMacro8)
EVT_MENU (Pterm_Macro9, PtermFrame::OnMacro9)
EVT_MENU (Pterm_Paste, PtermFrame::OnPaste)
EVT_MENU (Pterm_PastePrint, PtermFrame::OnPaste)
EVT_UPDATE_UI (Pterm_Paste, PtermFrame::OnUpdateUIPaste)
EVT_MENU (Pterm_SaveScreen, PtermFrame::OnSaveScreen)
EVT_MENU (Pterm_SaveAudio, PtermFrame::OnSaveAudio)
EVT_MENU (Pterm_Print, PtermFrame::OnPrint)
EVT_MENU (Pterm_ResetMtutor, PtermFrame::OnReset)
EVT_MENU (Pterm_SessionSettings, PtermFrame::OnSessionSettings)
EVT_MENU (Pterm_Preview, PtermFrame::OnPrintPreview)
EVT_MENU (Pterm_Page_Setup, PtermFrame::OnPageSetup)
EVT_MENU (Pterm_FullScreen, PtermFrame::OnFullScreen)
EVT_SIZE (PtermFrame::OnResize)
#if defined (__WXMSW__)
EVT_ICONIZE (PtermFrame::OnIconize)
#endif
END_EVENT_TABLE ();
// ----------------------------------------------------------------------------
// PtermCanvas
// ----------------------------------------------------------------------------
// For Retina display support on the Mac, the set of available scale
// values is different than elsewhere; specifically, half-integer values
// make sense because each display unit is actually two pixels.
const double scaleList_Retina[] = { 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, -1. };
const double scaleList_std[] = { 1.0, 2.0, 3.0, 4.0, -1 };
const double *scaleList;
// the event tables connect the wxWindows events with the functions (event
// handlers) which process them.
BEGIN_EVENT_TABLE (PtermCanvas, wxScrolledCanvas)
EVT_CHAR (PtermCanvas::OnChar)
EVT_CHAR_HOOK (PtermCanvas::OnCharHook)
EVT_LEFT_DOWN (PtermCanvas::OnMouseDown)
EVT_LEFT_UP (PtermCanvas::OnMouseUp)
EVT_RIGHT_UP (PtermCanvas::OnMouseContextMenu)
EVT_MOTION (PtermCanvas::OnMouseMotion)
EVT_MOUSEWHEEL (PtermCanvas::OnMouseWheel)
END_EVENT_TABLE ();
PtermCanvas::PtermCanvas (PtermFrame *parent)
: wxScrolledCanvas (parent, -1, wxDefaultPosition,
wxDefaultSize,
wxHSCROLL | wxVSCROLL | wxWANTS_CHARS
/* , "Default Name" */),
m_mouseX (-1),
m_mouseY (-1),
m_owner (parent),
m_touchEnabled (false)
{
wxClientDC dc (this);
DisableKeyboardScrolling ();
SetBackgroundColour (m_owner->m_bgColor);
}
// Convert device x/y (on the scrolled canvas) to PLATO x/y. This
// takes into account the current scroll position as well as scaling.
void PtermCanvas::Unadjust (int x, int y, int *xx, int *yy) const
{
int xu, yu;
CalcUnscrolledPosition (x, y, &xu, &yu);
debug ("scrolled %d, %d maps to %d %d", x, y, xu, yu);
*xx = xu / m_owner->m_xscale - m_owner->m_xmargin;
*yy = 511 - (yu / m_owner->m_yscale - m_owner->m_ymargin);
}
void PtermCanvas::OnDraw (wxDC &dc)
{
const int rh = m_owner->m_regionHeight;
const int rw = m_owner->m_regionWidth;
const int PScale = m_owner->GetContentScaleFactor ();
dc.DestroyClippingRegion ();
if (PScale == 1 || m_owner->m_xscale < 1 ||
m_owner->m_yscale < 1)
{
// simple scaling
if (!m_owner->m_FancyScaling ||
((m_owner->m_xscale == 1 && m_owner->m_yscale == 1) ||
(m_owner->m_xscale == 2 && m_owner->m_yscale == 2) ||
(m_owner->m_xscale == 3 && m_owner->m_yscale == 3))
)
{
dc.SetUserScale (m_owner->m_xscale, m_owner->m_yscale);
if (!m_owner->m_fullScreen)
{
dc.SetClippingRegion (m_owner->m_xmargin,
m_owner->m_ymargin, 512, 512);
}
dc.DrawBitmap (*m_owner->m_bitmap, m_owner->m_xmargin,
m_owner->m_ymargin, false);
}
// BILINEAR scaling
else
{
int x1 = m_owner->m_xmargin + (m_owner->m_xscale - 1)*m_owner->m_xmargin;
int y1 = m_owner->m_ymargin + (m_owner->m_yscale - 1)*m_owner->m_ymargin;
wxImage scaleImage = m_owner->m_bitmap->ConvertToImage ();
wxImage rescaledImage = scaleImage.Scale (m_owner->m_xscale * 512,
m_owner->m_yscale * 512,
wxIMAGE_QUALITY_BILINEAR);
if (!m_owner->m_fullScreen)
{
dc.SetClippingRegion (x1, y1,
m_owner->m_xscale * 512, m_owner->m_yscale * 512);
}
dc.DrawBitmap (rescaledImage, x1, y1, false);
}
}
else
{
PixelData pixmap (*m_owner->m_bitmap);
PixelData pixmap2 (*m_owner->m_bitmap2);
PixelData::Iterator p (pixmap);
PixelData::Iterator p2 (pixmap2);
PixelData::Iterator p2b (pixmap2);
u32 *pmap, *pmap2;
u32 pd;
int i, j;
for (i = 0; i < 512; i++)
{
for (j = 0; j < 512; j++)
{
p.MoveTo (pixmap, j, i);
p2.MoveTo (pixmap2, j * 2, i * 2);
pd = *(u32 *) (p.m_ptr);
pmap2 = (u32 *) (p2.m_ptr);
*pmap2++ = pd;
*pmap2 = pd;
}
p2.MoveTo (pixmap2, 0, i * 2);
p2b.MoveTo (pixmap2, 0, i * 2 + 1);
pmap = (u32 *) (p2.m_ptr);
pmap2 = (u32 *) (p2b.m_ptr);
memcpy (pmap2, pmap, 2 * 512 * sizeof (u32));
}
dc.SetUserScale (m_owner->m_xscale / PScale,
m_owner->m_yscale / PScale);
if (!m_owner->m_fullScreen)
{
dc.SetClippingRegion (m_owner->m_xmargin * PScale,
m_owner->m_ymargin * PScale,
512 * PScale, 512 * PScale);
}
dc.DrawBitmap (*m_owner->m_bitmap2,
m_owner->m_xmargin * PScale,
m_owner->m_ymargin * PScale, false);
}
debug ("Drawing bitmap onto the window canvas");
if (rh != 0 && rw != 0)
{
dc.SetUserScale (m_owner->m_xscale, m_owner->m_yscale);
dc.SetClippingRegion (m_owner->m_xmargin + (8 * m_owner->m_regionX),
m_owner->m_ymargin + 511 -
(16 * (m_owner->m_regionY + rh)),
rw * 8, rh * 16);
dc.DrawBitmap (*m_owner->m_selmap, m_owner->m_xmargin,
m_owner->m_ymargin, false);
dc.DestroyClippingRegion ();
debug ("Drawing selection region, top %d %d, size %d %d",
m_owner->m_regionX, m_owner->m_regionY, rw, rh);
}
}
void PtermCanvas::OnCharHook (wxKeyEvent &event)
{
unsigned int key;
int shift = 0;
u32 pc = None;
bool ctrl;
// Most keyboard inputs are handled here, because if we defer them to
// a later stage, wrong things happen on Mac.
//
// The one thing we do defer until EVT_CHAR is plain old characters, i.e.,
// keystrokes that aren't function keys or other special keys, and
// neither Ctrl nor Alt are active.
if (m_owner->m_bPasteActive)
{
// If pasting is active, this key is NOT passed on to the application
// until the paste operation is properly canceled
m_owner->m_bCancelPaste = true;
return;
}
ctrl = event.RawControlDown ();
if (event.ShiftDown ())
{
shift = 040;
}
key = event.GetKeyCode ();
#if defined (__WXMAC__)
if (event.ControlDown ())
{
// Command is in effect, that's a Mac keyboard shortcut,
// let Mac sort it out.
if (key == 'M')
{
// One exception: Cmd-M (minimize window) isn't handled in the
// external machinery so I guess it has to be done here.
if (event.AltDown ())
{
// Cmd-Option-M: minimize all
for (PtermFrame *frame = ptermApp->m_firstFrame;
frame != NULL;
frame = frame->m_nextFrame)
{
frame->Iconize ();
}
if (ptermApp->m_helpFrame != NULL)
{
ptermApp->m_helpFrame->Iconize ();
}
}
else
{
m_owner->Iconize ();
}
return;
}
event.Skip ();
return;
}
#endif
if (m_owner->IgnoreKeys() ||
key == WXK_ALT ||
key == WXK_SHIFT ||
key == WXK_CONTROL ||
key == WXK_RAW_CONTROL)
{
// We don't take any action on the modifier key keydown events,
// but we do want to make sure they are seen by the rest of
// the system.
// The same applies to keys sent to the help window (which has
// no connection on which to send them).
//
// Note that wxWidgets V3 maps the Mac Command key to WXK_CONTROL,
// "to improve compatibility with other systems". Gah. But
// fortunately, WXK_RAW_CONTROL means the real control key.
event.Skip ();
return;
}
if (key < 0200 && isalpha (key))
{
key = tolower (key);
}
#if 0
tracex ("oncharhook: ctrl %d shift %d alt %d key %d\n",
event.RawControlDown (), event.ShiftDown (),
event.AltDown (), key);
#endif
if (event.ShiftDown ())
{
shift = 040;
}
// Special case: ALT-left or Ctrl-left is assignment arrow
if ((event.AltDown () || event.RawControlDown ()) && key == WXK_LEFT)
{
m_owner->ptermSendKey1 (015 | shift);
return;
}
if ((key < sizeof (altKeyToPlato) / sizeof (altKeyToPlato[0]) &&
event.AltDown ()))
{
if (shift != 0 && key == '=')
{
key = '+';
}
if (altKeyToPlato[key] != -1)
{
m_owner->ptermSendKey1 (altKeyToPlato[key] | shift);
return;
}
}
else if (event.AltDown ())
{
// All ALT cases are handled above, so if we haven't handled
// it yet and it's an Alt, let someone else see it.
event.Skip ();
return;
}
if (ctrl && key == ']') // control-] : trace
{
m_owner->ptermSetTrace (!m_owner->tracePterm);
return;
}
#if 0
if (ctrl && key == '\\') // Reset Mtutor
{
if (m_owner->m_mtutorBoot)
{
m_owner->BootMtutor();
}
return;
}
if (ctrl && key == '[') // control-[ : turn mtutor/ppt keys off
{
m_owner->mt_ksw &= 0xfe;
tracex("mtutor off key");
return;
}
#endif
// Special case:user has disabled Shift-Space, which means to treat
// it as a space
if (m_owner->m_DisableShiftSpace && key == WXK_SPACE)
{
shift = 0;
}
if (key < sizeof (asciiToPlato) / sizeof (asciiToPlato[0]))
{
if (ctrl && key >= 040)
{
// Control key is active. There are several possibilities:
//
// Control plus letter: look up the translate table entry
// for the matching control code.
// Control plus non-letter: look up the translate table entry
// for that character, and set the "shift" bit.
// Control plus control code or function key: don't pay attention
// to the control key being active, and don't do a table lookup
// on the keycode. Instead, those are handled later, in a switch.
#if !defined (__WXMAC__)
// Another complication is that it may be an accelerator (if not Mac).
// Those are handled at different spots in the event chain on
// Windows vs. Linux. So the only feasible way to deal with
// them seems to be to check for them explicitly. Note that
// we currently only have unshifted accelerators in Pterm.
// Any character that is an accelerator (listed as such with the
// ACCELERATOR macro in menu definitions) needs to be accounted
// for in the checks below.
if (m_owner->m_useAccel && !shift)
{
bool acc = false;
if (m_owner->m_TutorColor && !m_owner->IgnoreKeys ())
{
acc = (key >= '0' && key <= '9');
}
switch (key)
{
case 'n':
case 's':
case 'p':
case 'w':
#if !defined (__WXMSW__)
// "Quit" has its accelerator supplied automatically
// by wxWidgets, on Unix that is.
case 'q':
#endif
case 'c':
case 'v':
case 'x':
case 'm':
case 'g':
case 'u':
acc = true;
}
// If we conclude it's an accelerator, exit CharHook processing
// and let the wx machinery handle it.
if (acc)
{
event.Skip ();
return;
}
}
#endif
if (isalpha (key))
{
// Control letter -- do a lookup for the matching control code.
pc = asciiToPlato[key & 037];
}
else
{
// control but not a letter or ASCII control code --
// translate to what a PLATO keyboard
// would have on the shifted position for that key
// but only if it's a simple key (not a sequence of
// access and other stuff)
if (shift != 0 && key == '=')
{
key = '+';
}
pc = asciiToPlato[key];
if (pc != KEY1 (pc))
{
// If this entry is for more than one keycode,
// ignore the keystroke.
pc = (u32)-1;
}
shift = 040;
}
if (pc == None)
{
// Unknown control key, skip it
event.Skip ();
}
else
{
m_owner->ptermSendKey (pc | shift);
}
return;
}
}
// If we get down to this point, then the following is true:
// 1. It wasn't an ALT-key entry.
// 2. If Control was active, it was with a non-printable key (where we
// ignore the Control flag).
// At this point, we're going to look for function keys. If it isn't
// one of those, then it was a regular printable character code, possibly
// shifted. Those are handled in the EVT_CHAR handler because the
// unshifted to shifted translation is keyboard specific (at least for
// non-letters) and we want to let the system deal with that.
pc = None;
if (m_owner->m_platoKb)
{
#if defined (_WIN32)
// This is a workaround for a Windows keyboard mapping bug
if (key == '+')
{
pc = 0133; // =
}
#endif
}
else if (m_owner->m_numpadArrows)
{
// Check the numeric keypad keys separately and turn them
// into the 8-way arrow keys of the PLATO main keyboard.
switch (key)
{
case WXK_NUMPAD7:
case WXK_NUMPAD_HOME:
pc = 0121; // up left (q)
break;
case WXK_NUMPAD8:
case WXK_NUMPAD_UP:
pc = 0127; // up arrow (w)
break;
case WXK_NUMPAD9:
case WXK_NUMPAD_PAGEUP:
pc = 0105; // up right (e)
break;
case WXK_NUMPAD4:
case WXK_NUMPAD_LEFT:
pc = 0101; // left arrow (a)
break;
case WXK_NUMPAD6:
case WXK_NUMPAD_RIGHT:
pc = 0104; // right arrow (d)
break;
case WXK_NUMPAD1:
case WXK_NUMPAD_END:
pc = 0132; // down left (z)
break;
case WXK_NUMPAD2:
case WXK_NUMPAD_DOWN:
pc = 0130; // down arrow (x)
break;
case WXK_NUMPAD3:
case WXK_NUMPAD_PAGEDOWN:
pc = 0103; // down right (c)
break;
}
pc = KEY1 (pc);
}
if (pc == None)
{
switch (key)
{
case WXK_SPACE:
case WXK_NUMPAD_SPACE:
pc = 0100; // space
break;
case WXK_BACK:
pc = 023; // erase
break;
case WXK_RETURN:
case WXK_NUMPAD_ENTER:
pc = 026; // next
break;
case WXK_HOME:
case WXK_NUMPAD_HOME:
case WXK_F8:
pc = 030; // back
break;
case WXK_PAUSE:
case WXK_F10:
pc = 032; // stop
break;
case WXK_TAB:
pc = 014; // tab
break;
case WXK_ESCAPE:
pc = 015; // assign
break;
case WXK_ADD:
case WXK_NUMPAD_ADD: