-
Notifications
You must be signed in to change notification settings - Fork 6
/
wxTEDMain.cpp
2889 lines (2630 loc) · 115 KB
/
wxTEDMain.cpp
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: wxTEDMain.cpp
* Purpose: Teletext editor Application Frame
* Author: Peter Kwan ([email protected])
* Created: 2014-10-30
* Copyright: Peter Kwan
* License:
*
* Copyright (C) 2014-2022, Peter Kwan
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaims all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*************************************************************************** **/
#include "wxTEDMain.h"
#include <wx/msgdlg.h>
#include "wx/wx.h"
#if defined(__WXMSW_DISABLED__)
#include <winver.h>
#endif
//(*InternalHeaders(wxTEDFrame)
#include <wx/font.h>
#include <wx/intl.h>
#include <wx/settings.h>
#include <wx/string.h>
//*)
#include <wx/dcbuffer.h>
// include <wx/filename.h>
#include <wx/stdpaths.h>
//helper functions
enum wxbuildinfoformat {
short_f, long_f };
wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);
if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif
#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}
return wxbuild;
}
//(*IdInit(wxTEDFrame)
const long wxTEDFrame::ID_PANEL1 = wxNewId();
const long wxTEDFrame::idNewPage = wxNewId();
const long wxTEDFrame::idNewFromTemplate = wxNewId();
const long wxTEDFrame::idOpenPage = wxNewId();
const long wxTEDFrame::idSavePage = wxNewId();
const long wxTEDFrame::isSavePageAs = wxNewId();
const long wxTEDFrame::idExportTTX40 = wxNewId();
const long wxTEDFrame::isExportZxnet = wxNewId();
const long wxTEDFrame::idMenuQuit = wxNewId();
const long wxTEDFrame::idNewWindow = wxNewId();
const long wxTEDFrame::idUndo = wxNewId();
const long wxTEDFrame::idCut = wxNewId();
const long wxTEDFrame::idCopy = wxNewId();
const long wxTEDFrame::idPaste = wxNewId();
const long wxTEDFrame::idSelectAll = wxNewId();
const long wxTEDFrame::isInsertLine = wxNewId();
const long wxTEDFrame::isDeleteLine = wxNewId();
const long wxTEDFrame::idInsertPage = wxNewId();
const long wxTEDFrame::idDeleteSubPage = wxNewId();
const long wxTEDFrame::idLanguageEnglish = wxNewId();
const long wxTEDFrame::idLanguageFrench = wxNewId();
const long wxTEDFrame::idLanguageSwedish = wxNewId();
const long wxTEDFrame::idLanguageCzechSlovak = wxNewId();
const long wxTEDFrame::idLanguageGerman = wxNewId();
const long wxTEDFrame::idLanguageSpanish = wxNewId();
const long wxTEDFrame::idLanguageItalian = wxNewId();
const long wxTEDFrame::idLanguageUnused = wxNewId();
const long wxTEDFrame::ID_MENUITEM1 = wxNewId();
const long wxTEDFrame::ID_REGION0 = wxNewId();
const long wxTEDFrame::ID_REGION1 = wxNewId();
const long wxTEDFrame::ID_REGION2 = wxNewId();
const long wxTEDFrame::ID_REGION3 = wxNewId();
const long wxTEDFrame::ID_REGION4 = wxNewId();
const long wxTEDFrame::ID_REGION6 = wxNewId();
const long wxTEDFrame::ID_REGION8 = wxNewId();
const long wxTEDFrame::ID_REGION10 = wxNewId();
const long wxTEDFrame::ID_REGION = wxNewId();
const long wxTEDFrame::idPageNumber = wxNewId();
const long wxTEDFrame::ID_MENUITEMSHOWHEADER = wxNewId();
const long wxTEDFrame::ID_HIDECONCEAL = wxNewId();
const long wxTEDFrame::idRun = wxNewId();
const long wxTEDFrame::idRadioMode = wxNewId();
const long wxTEDFrame::idRadioBounce = wxNewId();
const long wxTEDFrame::idRadioMode0 = wxNewId();
const long wxTEDFrame::idRadioMode1 = wxNewId();
const long wxTEDFrame::idRadioMode2 = wxNewId();
const long wxTEDFrame::idRadioMode3 = wxNewId();
const long wxTEDFrame::idRadioMode4 = wxNewId();
const long wxTEDFrame::idRadioMode5 = wxNewId();
const long wxTEDFrame::idSpecialKeys = wxNewId();
const long wxTEDFrame::idMenuAbout = wxNewId();
const long wxTEDFrame::ID_STATUSBAR1 = wxNewId();
const long wxTEDFrame::ID_TIMER1 = wxNewId();
//*)
BEGIN_EVENT_TABLE(wxTEDFrame,wxFrame)
//(*EventTable(wxTEDFrame)
EVT_PAINT(wxTEDFrame::OnPaint)
EVT_SIZE(wxTEDFrame::OnSize)
EVT_LEFT_DOWN(wxTEDFrame::OnLeftDown)
EVT_CHAR(wxTEDFrame::OnChar)
EVT_KEY_DOWN(wxTEDFrame::OnKeyDown)
EVT_KEY_UP(wxTEDFrame::OnKeyUp)
EVT_TIMER(ID_TIMER1 ,wxTEDFrame::OnTimer)
EVT_ERASE_BACKGROUND(wxTEDFrame::OnEraseBackground)
EVT_MENU_OPEN(wxTEDFrame::OnMenuOpen)
EVT_MENU_CLOSE(wxTEDFrame::OnMenuClose)
//*)
END_EVENT_TABLE()
void wxTEDFrame::OnEraseBackground(wxEraseEvent& event)
{
// NULL method!
std::cout << "Erase..." << std::endl;
}
void wxTEDFrame::OnSize(wxSizeEvent& event)
{
// std::cout << "Resize..." << std::endl;
m_resize(event.GetSize());
}
void wxTEDFrame::OnChar(wxKeyEvent& event)
{
int code=event.GetKeyCode();
int modifiers=event.GetModifiers();
// std::cout << "[OnChar]Key event..." << code << std::endl;
// We look at a few codes which apply to a page set rather than just a single page
// If none of these codes apply, we send the character to the page
TEDEvent* tev;
// Toggle invisible control codes?
if (m_escapeMode)
{
if (code=='Q' || code=='X') // Codes and Grid are combined in wxTED
{
m_ShowMarkup=!m_ShowMarkup;
code=WXK_ESCAPE;
}
}
// hack for preview mode
if (m_previewMode)
{
if (code>0) // Cancel preview mode
{
m_previewMode = false;
m_Timer1.Start(456);
}
else
{
if (PreviewNormal->IsChecked())
{
// The timing comes from the file.
int seconds = m_currentPage->GetCycleTime();
m_Timer1.Start(seconds * 1000);
}
if (m_previewForwards)
{
if (iPage>=m_iPageCount-1) // forwards loop preview wrap
{
if (m_bounceMode)
{
m_previewForwards = false; // reverse direction
}
else
{
iPage = -1; // loop to beginning
}
}
code = WXK_PAGEUP;
}
else
{
if (iPage<=0) // backwards loop preview
{
iPage = 0;
m_previewForwards = true;
}
code = WXK_PAGEDOWN;
}
}
}
switch (code)
{
case WXK_ESCAPE:
m_escapeMode=!m_escapeMode;
break;
case WXK_PAGEUP:
// std::cout << "Page up will get next page of a multiple page carousel" << std::endl;
if ( m_cursorPoint.y<1) // @todo Temporary hack to stop crash, when going up one page while on row 0.
{
m_cursorPoint.y=1;
}
m_iPageCount=m_rootPage->GetPageCount();
iPage++;
if (iPage>=m_iPageCount) iPage=m_iPageCount-1; // Check we don't go past the last page
m_currentPage=m_rootPage->GetPage(iPage);
// If the page is now off screen, scroll left to bring the right edge aligned with the window
{
auto rightEdge=(iPage+1)*m_ttxW*41; // Distance from first page to end of current page
uint32_t mappedEdge=rightEdge-m_ttxW+m_offset.x; // Edge that we want mapped to the right hand side of the client frame space
uint32_t clientWidth=GetClientSize().GetWidth();
if (mappedEdge>clientWidth)
{
m_offset.x=clientWidth-rightEdge-m_ttxW; // Scroll left to bring the right side into frame
}
}
break;
case WXK_PAGEDOWN:
// std::cout << "Page down will get previous page of a multiple page carousel" << std::endl;
m_iPageCount=m_rootPage->GetPageCount();
iPage--;
if (iPage<0) iPage=0;
m_currentPage=m_rootPage->GetPage(iPage);
// If the page is now off screen, scroll left to bring the right edge aligned with the window
{
int leftEdge=iPage*m_ttxW*41; // Distance from first page to left edge of current page
int mappedEdge=leftEdge-m_ttxW+m_offset.x; // Edge that we want mapped to client frame space
std::cout << std::dec << "iPage= " << iPage << " mappedEdge=" << mappedEdge << " leftEdge=" << leftEdge << std::endl;
if (mappedEdge<0)
{
m_offset.x=-leftEdge; // Scroll left to bring the right side into frame
}
}
break;
case WXK_F11: // Reveal concealed text
m_reveal=!m_reveal;
break;
case WXK_CONTROL_Y: // Ah. This is why we can't use CTRL-Y as a special key. This was for debugging undo.
// std::cout << "CTRL-Y test" << std::endl; // Testing
tev=m_currentPage->GetUndo();
if (tev!=NULL)
{
tev->dump();
}
break;
case WXK_CONTROL_Z:
// std::cout << "CTRL-Z undo" << std::endl;
// tev=m_currentPage->GetUndo();
m_currentPage->Undo(m_cursorPoint);
break;
case WXK_CONTROL:
break;
// Moved this to ttxpage as it acts on the page
//case WXK_TAB: // This will insert a space
// std::cout << "Insert a space TBA" << std::endl;
//break;
default:
// If the last key pressed was escape, we are doing an edit.tf style escape
if (m_escapeMode)
{
m_escapeMode=false;
// Find the key that was pressed, and map it to a native keycode
switch (code)
{
case 'r': modifiers=wxMOD_SHIFT; code=WXK_F1;break; // alpha red
case 'R': modifiers=wxMOD_CONTROL; code=WXK_F1;break; // mosaic red
case 'g': modifiers=wxMOD_SHIFT; code=WXK_F2;break; // alpha green
case 'G': modifiers=wxMOD_CONTROL; code=WXK_F2;break; // mosaic green
case 'y': modifiers=wxMOD_SHIFT; code=WXK_F3;break; // alpha yellow
case 'Y': modifiers=wxMOD_CONTROL; code=WXK_F3;break; // mosaic yellow
case 'b': modifiers=wxMOD_SHIFT; code=WXK_F4;break; // alpha blue
case 'B': modifiers=wxMOD_CONTROL; code=WXK_F4;break; // mosaic blue
case 'm': modifiers=wxMOD_SHIFT; code=WXK_F5;break; // alpha magenta
case 'M': modifiers=wxMOD_CONTROL; code=WXK_F5;break; // mosaic magenta
case 'c': modifiers=wxMOD_SHIFT; code=WXK_F6;break; // alpha cyan
case 'C': modifiers=wxMOD_CONTROL; code=WXK_F6;break; // mosaic cyan
case 'w': modifiers=wxMOD_SHIFT; code=WXK_F7;break; // alpha white
case 'W': modifiers=wxMOD_CONTROL; code=WXK_F7;break; // mosaic white
case 'k': modifiers=wxMOD_SHIFT; code=WXK_F8;break; // alpha black
case 'K': modifiers=wxMOD_CONTROL; code=WXK_F8;break; // mosaic black
case 'i': modifiers=wxMOD_SHIFT; code=WXK_F9;break; // insert line
case 'I': modifiers=wxMOD_CONTROL; code=WXK_F9;break; // delete line
case 'N': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_B; break; // new background
case 'n': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_U; break; // black background
case 'f': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_I; break; // steady
case 'F': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_H; break; // flash
case 'h': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_X; break; // release
case 'H': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_W; break; // hold
case 'd': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_L; break; // normal height
case 'D': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_M; break; // double height
case 'O': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_R; break; // conceal
case 'S': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_T; break; // separate graphics
case 's': modifiers=wxMOD_CONTROL; code=WXK_CONTROL_E; break; // contiguous
case 'J': modifiers=wxMOD_NONE; code=172; break; // hook maps to text block
// @todo Lots more codes
}
std::cout << "[wxTEDFrame::OnChar] code = " << (int)code << std::endl;
} // edit.tf escape mode
m_currentPage->SetCharAt(code, modifiers, m_cursorPoint, m_subPixelPoint, MenuItemShowHeader->IsChecked());
}
//std::cout << "Cursor = " << m_cursorPoint.x << "." << m_subPixelPoint.x << ", "
// << m_cursorPoint.y << "." << m_subPixelPoint.y << ", " << std::endl;
m_cursorIsAlpha=m_currentPage->IsAlphaMode(m_cursorPoint);
m_blinkToggle=true; // HCI: Make cursor moves immediately visible
Refresh();
event.Skip();
}
void wxTEDFrame::OnTimer(wxTimerEvent& event)
{
// Only blink while focused otherwise stay on.
// Don't show the cursor in preview mode.
// std::cout << "blink=" << m_blinkToggle << " m_focused=" << m_focused << std::endl;
if ((m_blinkToggle && m_focused) || m_previewMode)
m_blinkToggle=false;
else
m_blinkToggle=true;
if (m_previewMode)
{
wxKeyEvent pageup(wxEVT_CHAR);
//auto pageup = wxKeyEvent(WXK_PAGEUP);
OnChar(pageup);
}
wxString s=GetTitle();
if (m_currentPage)
{
Refresh(); // Paint it
}
}
bool wxTEDFrame::isMosaic(char ch)
{
ch&=0x7f;
return (ch>=0x20 && ch<0x40) || ch>=0x60;
}
/* new--old description. Don't use old codes. They no longer work in VBIT.
* %%£ mpp page number
* %d dd date, two digits
* %e date without leading 0
* %m uu month
* %y yy year
* %%a DAY day
* %%b MTH month
* %H hh hour
* %M nn minute
* %S ss second
*
* Example ARD. "mpp<cyan>ARDtext<white>Mo dd.uu.yy hh:nn:ss"
* @todo We do not yet implement two character day codes
* as is possible in German dd so you have to edit it every day!
*/
void wxTEDFrame::GenerateHeader(TTXLine* line)
{
// line->Setm_textline(std::string("Pxxx 101 TEDFAX Mon 15 Nov 21:12.38"));
// AAAAAAAAaabbbbbbbbbbccccccccccddDDDDDDDD
std::ostringstream val;
time_t rawtime;
tm * timeinfo;
rawtime=time(NULL);
timeinfo=localtime(&rawtime);
std::string str=line->GetLine();
int i;
for (i=0;i<8;i++) // First 8 characters are not taken from the header
str[i]=' ';
int k=m_rootPage->GetPageNumber()/0x100;
if (k<0x100 && k>0x8ff)
k=0x100;
val << std::hex << k;
str[0]='P';
str.replace(1,3,val.str()); // Replace the first 4 characters with the page number
// Magazine and page number
i=str.find("mpp");
if (i<=0) i=str.find("%%#");
if (i<=0) i=str.find("%%£");
if (i>0)
{
str.replace(i,3,val.str());
}
// two digit date with leading 0
i=str.find("dd");
if (i<=0) i=str.find("%d");
if (i>0)
{
val.str("");
val << std::dec << std::setw(2) << std::setfill('0') << timeinfo->tm_mday;
str.replace(i,2,val.str());
}
// Three character day name
i=str.find("DAY");
if (i<=0) i=str.find("%%a");
if (i>0)
{
char day[10];
char* p=day;
strftime(p,4,"%a",timeinfo);
str.replace(i,3,p);
}
// Three character month name
i=str.find("MTH");
if (i<=0) i=str.find("%%b");
if (i>0)
{
char month[10];
char* p=month;
strftime(p,4,"%b",timeinfo);
str.replace(i,3,p);
}
// Hours - two digits 24 hour
i=str.find("hh");
if (i<=0) i=str.find("%H");
if (i>31) // Clock hours
{
val.str("");
val << std::dec << std::setw(2) << std::setfill('0') << timeinfo->tm_hour;
str.replace(i,2,val.str());
}
// Minutes - two digits
i=str.find("nn");
if (i<=0) i=str.find("%M");
if (i>31) // Clock minutes
{
val.str("");
val << std::dec << std::setw(2) << std::setfill('0') << timeinfo->tm_min;
str.replace(i,2,val.str());
}
// Month - two digits
i=str.find("uu");
if (i<=0) i=str.find("%m");
if (i>8) // uu Month (two digits)
{
val.str("");
val << std::dec << std::setw(2) << std::setfill('0') << timeinfo->tm_mon+1;
str.replace(i,2,val.str());
}
// Seconds - two digits
i=str.find("ss");
if (i<=0) i=str.find("%S");
if (i>31) // Clock seconds
{
val.str("");
val << std::setw(2) << std::setfill('0') << std::dec << timeinfo->tm_sec;
str.replace(i,2,val.str());
}
// Year - two digits
i=str.find("yy");
if (i<=0) i=str.find("%y");
if (i>0)
{
val.str("");
val << std::dec << std::setw(2) << std::setfill('0') << timeinfo->tm_year % 100;
str.replace(i,2,val.str());
}
// std::cout << "GenerateHeader exits with str=" << str << std::endl;
line->Setm_textline(str);
}
void wxTEDFrame::m_resize(wxSize clientSize)
{
wxSize ttxSize;
// What is the target client size?
//std::cout << "Current window size " << std::dec << clientSize.GetWidth() << " " << clientSize.GetHeight() << std::endl;
// What is the current font size?
wxFont wf=GetFont();
// Iterate for best fit
int i;
for (i=8;i<100;i++)
{
//std::cout << "Current font size " << std::dec << m_fontSize[i].GetWidth() << " " << m_fontSize[i].GetHeight() << std::endl;
// Fit width
if (clientSize.GetWidth()<m_fontSize[i].GetWidth()+10) // allow 10 pixels, I think the border is included
break;
// or fit height
if (clientSize.GetHeight()<m_fontSize[i].GetHeight()*27+40)
break;
}
// Don't make it too small
if (i>6) i--;
// Set it as the system font
wf.SetPointSize(i);
SetFont(wf);
/* font metrics */
ttxSize=GetTextExtent("AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD");
m_ttxW=ttxSize.GetWidth()/40;
m_ttxH=ttxSize.GetHeight(); // 18;
Refresh();
// std::cout << "New font size (pts) " << GetFont().GetPointSize() << std::endl;
}
void wxTEDFrame::OnPaint(wxPaintEvent& event)
{
if (this->IsIconized()) return; // If Iconized we shouldn't draw anything
wxPoint offset=m_offset;
wxAutoBufferedPaintDC paintDC(this);
// redraw the whole teletext page
/* colours */
const wxColour* fg=wxWHITE;
const wxColour* bg=wxBLACK;
wxBitmap doubleHeightBitmap(m_ttxW*40,m_ttxH*2); // The image buffer for double height. (Sized for a single height plus generous fudge factor)
wxMemoryDC doubleHeightDC;
doubleHeightDC.SelectObject(doubleHeightBitmap); // The device context for double height text
// Copy the font settings over
wxFont wf=GetFont();
doubleHeightDC.SetFont(wf);
/* Fill the background */
paintDC.SetPen(*wxTRANSPARENT_PEN);
doubleHeightDC.SetPen(*wxTRANSPARENT_PEN);
//if (m_ShowMarkup)
//{
//doubleHeightDC.SetPen(*wxGREY_PEN);
//paintDC.SetPen(*wxGREY_PEN);
//}
paintDC.SetBrush(wxBrush(*wxBLACK_BRUSH));
doubleHeightDC.SetBrush(wxBrush(*wxBLACK_BRUSH));
int w,h;
paintDC.GetSize(&w, &h);
paintDC.DrawRectangle(wxPoint(0,0),wxSize(w,h));
// paintDC.DrawRectangle(wxPoint(0,0),wxSize(40*m_ttxW,24*m_ttxH));
// TODO: Black out rows if they are NULL, to avoid old text getting stuck
paintDC.SetBackgroundMode(wxSOLID); // Otherwise the background colour is transparent!
doubleHeightDC.SetBackgroundMode(wxSOLID); // Otherwise the background colour is transparent!
wxColour* magenta=new wxColour(255,0,255); // wxMagenta is not a thing
/* page */
// Assume horizontal subpages for now
for(TTXPage* p=m_rootPage;
p!=nullptr && (offset.x < this->GetClientSize().GetWidth()); // Don't bother to render pages outside of the window
p=p->Getm_SubPage())
{
// Skip frames that are completely on the left of the window
if (offset.x+(static_cast<int>(m_ttxW)*41)<0)
{
//std::cout << "Skipped drawing frame Xo=" << std::dec << offset.x << " " << m_ttxW*41 << std::endl;
offset.x+=m_ttxW*41;
continue;
}
auto addMarkup=(p==m_currentPage) && m_ShowMarkup;
if (addMarkup)
{
doubleHeightDC.SetPen(*wxGREY_PEN);
paintDC.SetPen(*wxGREY_PEN);
}
else
{
paintDC.SetPen(*wxTRANSPARENT_PEN);
doubleHeightDC.SetPen(*wxTRANSPARENT_PEN);
}
TTXLine row0;
int firstRow=1;
if (MenuItemShowHeader->IsChecked())
{
firstRow=0;
}
for (unsigned int row=firstRow;row<25;row++)
{
bool graphicsMode=false;
bool separated=false;
bool doubleHeight=false;
bool skipnextrow=false;
bool flashing=false;
bool hold=false;
char holdChar=' ';
bool concealed=false;
fg=wxWHITE;
bg=wxBLACK;
doubleHeightDC.SetBackground(*wxBLACK_BRUSH); // wxBLACK_BRUSH. Change this to GREY to track down bugs
doubleHeightDC.Clear();
// TTXPage* p=page.GetPage(0);
TTXLine* line=p->GetRow(row);
if (m_cursorPoint.y>0 && row==0) // If we are actually in the header, then edit the raw header
{
if (line==NULL)
{
p->SetRow(row,"XXXXXXXXTEEFAX %%# %%a %d %%b \x3 %H:%M.%S"); // Could put in a sample header here
// aaaaaaaaaabbbbbbbbbbccccccccccd ddddddddd
line=p->GetRow(row);
}
row0=*line; // Copy the contents of line to row
line=&row0; // Now point line to row so we don't erase the original line
GenerateHeader(line);
}
//std::cout << "Trace 4" << std::endl;
if (line!=NULL)
{
std::string str=line->GetLine();
str=str.substr(0,40);
for (int col=0;col<40;col++) // Look at each character on the line
{
// std::cout << "Trace 5" << std::endl;
char ch=' ';
wchar_t ch2=ch;
// Check the Set-before code
switch (str[col])
{
// If a case is ignored, you'll find it in the set-after section
case ttxCodeAlphaBlack :
case ttxCodeAlphaRed :
case ttxCodeAlphaGreen :
case ttxCodeAlphaYellow :
case ttxCodeAlphaBlue :
case ttxCodeAlphaMagenta :
case ttxCodeAlphaCyan :
case ttxCodeAlphaWhite :
hold=false;
break;
case ttxCodeFlash :
break;
case ttxCodeSteady :
flashing=false;
break;
case ttxCodeEndBox :
case ttxCodeStartBox :
break;
case ttxCodeNormalHeight :
doubleHeight=false;
break;
case ttxCodeDoubleHeight : // Double height
case ttxCodeGraphicsBlack : // Graphics black (level 2.5+)
case ttxCodeGraphicsRed : // Graphics red
case ttxCodeGraphicsGreen : // Graphics green
case ttxCodeGraphicsYellow : // Graphics yellow
case ttxCodeGraphicsBlue : // Graphics blue
case ttxCodeGraphicsMagenta : // Graphics magenta
case ttxCodeGraphicsCyan : // Graphics cyan
case ttxCodeGraphicsWhite : // Graphics white
break;
case ttxCodeConcealDisplay : // Conceal display
concealed=true;
break;
case ttxCodeContiguousGraphics : // Contiguous graphics
separated=false;
break;
case ttxCodeSeparatedGraphics : // Separated gfx
separated=true;
break;
case ttxCodeBlackBackground : // Background black
bg=wxBLACK;
break;
case ttxCodeNewBackground : // New background
bg=fg;
break;
case ttxCodeHoldGraphics : // Hold gfx (set at)
hold=true;
break;
case ttxCodeReleaseGraphics : // Release gfx (set after)
break;
case 14:; // Ignore shift in/shift out and avoid them falling into default
case 15:;
break;
default :
// std::cout << "Trace OL:ordinary character " << ch << std::endl;
ch=str[col] & 0x7f;
ch2=str[col];
ch2=mapTextChar(ch2);
// holdchar records the last mosaic character sent out
if (isMosaic(ch))
{
holdChar=ch; // In case we encounter hold mosaics (Space doesn't count as a mosaic)
}
}
if (concealed && !m_reveal) // Replace text with spaces
{
ch=' ';
holdChar=' '; /// @todo restore to space
ch2=' ';
}
if (graphicsMode && (isMosaic(ch) || hold) ) // Draw graphics. Either mosaic (but not capital A..Z) or in hold mode
{
int j=0x01;
// If we send a new mosaic code while in hold, it replaces the current mosaic.
if (hold)
{
ch=holdChar; // Carry on hold
}
for (int i=0;i<6;i++) // for each of the six pixels in this character
{
bool pixelSet=(ch & j) && (m_blinkToggle || !flashing);
j<<=1;
if (j==0x20) j<<=1; // Skip the alphabet exception
// Draw the full sized pixel in background colour
paintDC.SetBrush(wxBrush(*bg));
doubleHeightDC.SetBrush(wxBrush(*bg));
int k=1; // Full size pixel
if (doubleHeight)
{
doubleHeightDC.DrawRectangle(wxPoint(col*m_ttxW + (i % 2)*m_ttxW/2,
(i/2)*m_ttxH/3)+offset,
wxSize(k+m_ttxW/2,k+m_ttxH/3));
}
else
{
paintDC.DrawRectangle(wxPoint(col*m_ttxW + (i % 2)*m_ttxW/2,
row*m_ttxH+(i/2)*m_ttxH/3)+offset,
wxSize(k+m_ttxW/2,k+m_ttxH/3));
}
// Now draw the actual pixel
if (pixelSet)
{
paintDC.SetBrush(wxBrush(*fg));
if (separated) k=-2; // Thin border around the pixel
if (doubleHeight)
{
doubleHeightDC.SetBrush(wxBrush(*fg));
doubleHeightDC.DrawRectangle(wxPoint(col*m_ttxW + (i % 2)*m_ttxW/2,
(i/2)*m_ttxH/3)+offset,
wxSize(k+m_ttxW/2,k+m_ttxH/3));
}
else
{
paintDC.DrawRectangle(wxPoint(col*m_ttxW + (i % 2)*m_ttxW/2,
row*m_ttxH+(i/2)*m_ttxH/3)+offset,
wxSize(k+m_ttxW/2,k+m_ttxH/3));
}
}
}
} // Graphic block
else
{
// Foreground colour
if (m_blinkToggle || !flashing)
{
paintDC.SetTextForeground(*fg); // Normal
doubleHeightDC.SetTextForeground(*fg); // Normal
}
else
{
paintDC.SetTextForeground(*bg); // Blink off
doubleHeightDC.SetTextForeground(*bg); // blink off
}
// Background colour
doubleHeightDC.SetTextBackground(*bg);
paintDC.SetTextBackground(*bg);
if (doubleHeight)
{
doubleHeightDC.DrawText(_(ch2),wxPoint(col*m_ttxW,0)); // No offset! The device context is not the main screen
}
else // Single height
{
paintDC.DrawText(_(ch2),wxPoint(col*m_ttxW,row*m_ttxH)+offset);
if (row<23)
paintDC.DrawText(_(' '),wxPoint(col*m_ttxW,(row+1)*m_ttxH)+offset); // Draw background in case this row contains a double height
}
}
if (doubleHeight)
paintDC.StretchBlit(wxPoint(col*m_ttxW,row*m_ttxH)+offset,wxSize(m_ttxW,m_ttxH*2), // dest
&doubleHeightDC,
wxPoint(col*m_ttxW,0),wxSize(m_ttxW,m_ttxH)); //src
// Set-after codes implemented here, also the show markup
paintDC.SetTextForeground(*wxWHITE);
paintDC.SetTextBackground(*wxLIGHT_GREY);
switch (str[col])
{
case ttxCodeAlphaBlack :
fg=wxBLACK;
concealed=false; // Side effect of colour. It cancels a conceal.
graphicsMode=false;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\x03B1'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // graphic sample
}
break;
case ttxCodeAlphaRed :
fg=wxRED;
concealed=false;
graphicsMode=false;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\x03B1'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // graphic sample
}
break;
case ttxCodeAlphaGreen :
fg=wxGREEN;
concealed=false;
graphicsMode=false;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\x03B1'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // graphic sample
}
break;
case ttxCodeAlphaYellow :
fg=wxYELLOW;
concealed=false;
graphicsMode=false;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\x03B1'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // graphic sample
}
break;
case ttxCodeAlphaBlue :
fg=wxBLUE;
concealed=false;
graphicsMode=false;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\x03B1'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // graphic sample
}
break;
case ttxCodeAlphaMagenta :
fg=magenta;
concealed=false;
graphicsMode=false;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\x03B1'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // graphic sample
}
break;
case ttxCodeAlphaCyan :
fg=wxCYAN;
concealed=false;
graphicsMode=false;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\x03B1'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // graphic sample
}
break;
case ttxCodeAlphaWhite :
fg=wxWHITE;
concealed=false;
graphicsMode=false;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\x03B1'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // graphic sample
}
break;
case ttxCodeFlash :
flashing=true;
if (addMarkup)
{
paintDC.SetTextForeground(*wxWHITE);
paintDC.DrawText(_((wxChar)L'\xEFC6'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // italic f
}
break;
case ttxCodeSteady :
if (addMarkup)
{
paintDC.SetTextForeground(*wxWHITE);
paintDC.DrawText(_((wxChar)L'\xEFC9'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // italic i
}
break;
case ttxCodeEndBox :
// std::cout << "End Box not implemented" << std::endl;
if (addMarkup)
{
paintDC.SetTextForeground(*wxWHITE);
paintDC.DrawText(_((wxChar)L'\xEF57'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // down arrow
}
break;
case ttxCodeStartBox :
// std::cout << "Start box not implemented" << std::endl;
if (addMarkup)
{
paintDC.SetTextForeground(*wxWHITE);
paintDC.DrawText(_((wxChar)L'\xEF56'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // down arrow
}
break;
case ttxCodeNormalHeight : // Normal height
if (addMarkup)
{
paintDC.SetTextForeground(*wxWHITE);
paintDC.DrawText(_((wxChar)L'\xEF5E'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // down arrow
}
break;
case ttxCodeDoubleHeight : // Double height
doubleHeight=true;
skipnextrow=true; // ETSI: Don't use content from next row
if (addMarkup)
{
paintDC.SetTextForeground(*wxWHITE);
paintDC.DrawText(_((wxChar)L'\xEF5D'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // up arrow
}
break;
case ttxCodeGraphicsBlack : // Graphics black
concealed=false;
graphicsMode=true;
fg=wxBLACK;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\xE6F6'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // Show a blob where a control code is
}
break;
case ttxCodeGraphicsRed : // Graphics red
concealed=false;
graphicsMode=true;
fg=wxRED;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\xE6F6'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // Show a blob where a control code is
}
break;
case ttxCodeGraphicsGreen : // Graphics green
concealed=false;
graphicsMode=true;
fg=wxGREEN;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\xE6F6'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // Show a blob where a control code is
}
break;
case ttxCodeGraphicsYellow : // Graphics yellow
concealed=false;
graphicsMode=true;
fg=wxYELLOW;
if (addMarkup)
{
paintDC.SetTextForeground(*fg);
paintDC.DrawText(_((wxChar)L'\xE6F6'),wxPoint(col*m_ttxW,row*m_ttxH)+offset); // Show a blob where a control code is
}
break;
case ttxCodeGraphicsBlue : // Graphics blue
concealed=false;
graphicsMode=true;
fg=wxBLUE;