-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTUISTD.CPP
1675 lines (1545 loc) · 44.8 KB
/
TUISTD.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
#include <process.h>
#include <alloc.h> // farcoreleft
#include "textio.h" // WriteXYC
#include "tuimouse.h" // GetMouseStatus
#include "tuikeys.h" // keycodes
#include "tuistr.h" // StrLen,StrCpy
#include "tuiconst.h" // constants & colors
#include "tuistd.h" // classes
// colors
char cDesktop = ccDesktop ; // desktop
char cStatus = ccStatus ; // status bar
char cStatusHi = ccStatusHi ; // status bar highlight
char cDosWindow = ccDosWindow ; // DOS color
char cShadow = ccShadow ; // window shadow
char cDialog = ccDialog ; // dialog window
char cDialogMove = ccDialogMove ; // dialog window moving
char cStaticText = ccStaticText ; // static text
char cStaticTextHi = ccStaticTextHi ; // static text highlight
char cGroup = ccGroup ; // group
char cDivider = ccDivider ; // divider
char cButton = ccButton ; // button normal
char cButtonHi = ccButtonHi ; // button normal highlight
char cButtonD = ccButtonD ; // button default
char cButtonDHi = ccButtonDHi ; // button default highlight
char cButtonA = ccButtonA ; // button selected
char cButtonAHi = ccButtonAHi ; // button selected highlight
char cButtonShadow = ccButtonShadow ; // button shadow
char cEdit = ccEdit ; // edit line
char cEditA = ccEditA ; // edit line focused
char cEditIcon = ccEditIcon ; // edit icons
char cEditIconA = ccEditIconA ; // edit icons focused
char cEditView = ccEditView ; // edit line (view mode)
char cEditViewIcon = ccEditViewIcon ; // edit icons (view mode)
char cEditDateIconE = ccEditDateIconE ; // edit date symbols (edit mode)
char cEditDateIconV = ccEditDateIconV ; // edit date symbols (view mode)
char cDateRect = ccDateRect ; // date box rect
char cDateWeek = ccDateWeek ; // date box weekday titles
char cDateWeekEnd = ccDateWeekEnd ; // date box weekend titles
char cDateDays = ccDateDays ; // date box current month days
char cDateDaysX = ccDateDaysX ; // date box non-current month days
char cDateYear = ccDateYear ; // date box year
char cDateMonth = ccDateMonth ; // date box month
char cDateCur = ccDateCur ; // date box cursor
char cCheck = ccCheck ; // check box
char cCheckHi = ccCheckHi ; // check box highlight
char cCheckA = ccCheckA ; // check box selected
char cCheckAHi = ccCheckAHi ; // check box selected highlight
char cList = ccList ; // list box
char cListDiv = ccListDiv ; // list box divider
char cListA = ccListA ; // list box: focused item
char cListS = ccListS ; // list box: selected item
char cCustomList = ccCustomList ; // custom list
char cCustomListA = ccCustomListA ; // custom list: focused item (cursor)
char cCustomListS = ccCustomListS ; // custom list: selected item
char cCustomListTitle = ccCustomListTitle; // custom list title bar
char cScroller = ccScroller ; // scroll bar
char cScrollerIcon = ccScrollerIcon ; // scroll bar icon
char cProgressWin = ccProgressWin ; // progress window
char cProgressBar = ccProgressBar ; // progress bar
char cProgressNum = ccProgressNum ; // progress percent
char cMenuListNorm = ccMenuListNorm ; // menu list item
char cMenuListNormHi = ccMenuListNormHi ; // menu list item highlight
char cMenuListFocus = ccMenuListFocus ; // menu list focused
char cMenuListFocusHi = ccMenuListFocusHi; // menu list focused highlight
char cMenuListSel = ccMenuListSel ; // menu list selected
char cMenuListSelHi = ccMenuListSelHi ; // menu list selected highlight
int TuiLng = ENGLISH; // default language is english
void DlgColor( char back, char title, char text, char high )
{
cDialog = (back<<4)+(title&0x0F);
cStaticText = (back<<4)+(text&0x0F);
cStaticTextHi = (back<<4)+(high&0x0F);
cButtonShadow = (back<<4)+(cButtonShadow&0x0F);
};
void DlgReset( void ) {
DlgColor(ccDialog>>4,ccDialog&0x0F,ccStaticText&0x0F,ccStaticTextHi&0x0F);
};
int ExecuteDialog( TDialog* dlg )
{
TMessage msg;
int xcode;
dlg->Paint();
Once:
do {
GetMessage(msg);
xcode = dlg->Message(msg);
} while ( xcode!=DLG_CANCEL && xcode!=DLG_OK );
if (xcode==DLG_OK)
if (!dlg->FlushData()) goto Once;
dlg->Hide();
DlgReset();
return xcode;
};
#define MAX_MESSAGE 16
TMessage message[ MAX_MESSAGE ];
int msg_index=-1;
int clickx,clicky;
int clicktime;
// ¥á«¨ ®ç¥à¥¤ì ¯ãáâ - ¤®¦¤ âìáï á®®¡é¥¨ï ¨ ¢¥àãâì ¥£®
// ¨ ç¥ ¢ë¡à âì ¯¥à¢®¥ á®®¡é¥¨¥ ¨§ ®ç¥à¥¤¨
void GetMessage( TMessage &msg )
{
static int prev_msx, prev_msy, prev_btns=0;
int msx, msy, btns=0;
int softimer;
msg.what=0;
msg.code=0;
softimer=0;
while ( msg_index == -1 )
{
if ( KeyPressed() )
{
// keyboard
msg.what = evKeyb;
msg.code = ReadKey();
if (msg.code==0x2D00) exit(0);
break;
} else {
// mouse
MouseGetStatus( msx, msy, btns );
if ( (msx!=prev_msx) || (msy!=prev_msy) || (btns!=prev_btns) )
{
msg.what = evMouse;
msg.code = 0;
msg.lbutton = 0;
msg.rbutton = 0;
msg.msx = msx>>3;
msg.msy = msy>>3;
// left
if ( btns & 1 ) msg.lbutton |= msIsdown;
else msg.lbutton |= msIsup;
if ( (prev_btns&1) > (btns&1) ) msg.lbutton |= msKeyup;
if ( (prev_btns&1) < (btns&1) ) msg.lbutton |= msKeydown;
// right
if ( btns & 2 ) msg.rbutton |= msIsdown;
else msg.rbutton |= msIsup;
if ( (prev_btns&2) > (btns&2) ) msg.rbutton |= msKeyup;
if ( (prev_btns&2) < (btns&2) ) msg.rbutton |= msKeydown;
if ( (msx!=prev_msx) || (msy!=prev_msy) ) msg.code |= msMove;
if (btns!=prev_btns) msg.code |= msButton;
// double click
if (msg.lbutton&msKeydown)
{
if ( ((int)GetTimer())-clicktime < 18/3 )
if ( Abs(clickx-msg.msx) < 2 && Abs(clicky-msg.msy) < 1 )
{
msg.lbutton|=msDblClick;
};
clickx = msg.msx;
clicky = msg.msy;
clicktime = (int)GetTimer();
};
prev_msx = msx;
prev_msy = msy;
prev_btns = btns;
break;
};
};
if (softimer++ > TIMER_RATE) break;
};
if ( softimer > TIMER_RATE ) msg.what |= evTimer;
if ( msg_index == -1 ) return; // keyboard/mouse message
msg = message[0];
for (msx=1; msx<=msg_index; msx++) message[msx-1] = message[msx];
msg_index--;
}
void PostMessage( int put_what, int put_code,
void* target, void* sender, void far* dataptr )
{
msg_index++;
message[msg_index].what = put_what;
message[msg_index].code = put_code;
message[msg_index].target = target;
message[msg_index].sender = sender;
message[msg_index].dataptr = dataptr;
}
// *TRect* ----------------------------------------------------
TRect::TRect( void ) { x0=0; y0=0; x1=0; y1=0; width=0; height=0; };
TRect::TRect( int ix0, int iy0, int ix1, int iy1 )
{
int tmp;
if (x1 < x0) { tmp=x0; x0=x1; x1=tmp; };
if (y1 < y0) { tmp=y0; y0=y1; y1=tmp; };
x0 = ix0; y0 = iy0;
x1 = ix1; y1 = iy1;
width = x1-x0+1;
height = y1-y0+1;
};
BOOL TRect::InRect( int x, int y )
{
if ( (x<x0) || (x>x1) || (y<y0) || (y>y1) ) return False;
return True;
};
// *TWindow* --------------------------------------------------
TWindow::TWindow( int x, int y, int w, int h, char c, char* head, BOOL shadow )
{
w+=2; h+=2;
if (x+w-1 > GetMaxCol()) x=GetMaxCol()-w+1;
if (y+h-1 > GetMaxRow()) y=GetMaxRow()-h+1;
TRect::TRect( x, y, x+w-1, y+h-1 );
RColor = c;
CColor = c;
RStyle = DOUBLE;
if (head) StrCpy(header,head); else StrCpy(header,"");
if (StrLen(header) > width-6) header[width-6]=0;
buf = 0;
bufsize = 0;
HasShadow = shadow;
Shown = False;
};
TWindow::~TWindow(void) { if (Shown) Hide(); };
void TWindow::Show(void)
{
// get current window settings
SaveWindowPos();
// save background
bufsize = GetWindowSize(width+2,height+1);
if (farcoreleft() > bufsize) {
buf = new char[bufsize+2];
MouseHide();
SaveWindow( x0,y0,width+2,height+1,buf );
MouseShow();
};
TWindow::Rect( RColor,RStyle );
if (HasShadow) TWindow::Shadow();
TWindow::Paint();
Shown = True;
};
void TWindow::Hide(void)
{
// restore window setting
RestWindowPos();
if (buf==0) return;
// restore background
MouseHide();
RestoreWindow( x0, y0, buf );
MouseShow();
delete buf;
buf=0;
Shown = False;
};
void TWindow::Rect( char c, char style )
{
MouseHide();
SetWindow( x0, y0, width, height );
SetTextColor( c & 0x0F );
SetBackColor( c >> 4 );
Rectangle( 0, 0, width, height, style );
if ( (header) && (*header) ) {
WriteXY( (width-StrLenC(header)-2)/2, 0, " " );
WriteXY( (width-StrLenC(header)-2)/2+1, 0, header );
WriteXY( (width+StrLenC(header))/2, 0, " " );
};
SetWindow( x0+1, y0+1, width-2, height-2 );
RColor = c;
RStyle = style;
MouseShow();
};
void TWindow::Shadow(void)
{
MouseHide();
SetWindow( x1+1, y0+1, 2, height );
for (int i=0; i<height; i++) AttrXY(0,i,cShadow,2);
SetWindow( x0+2, y1+1, width, 1 );
AttrXY(0,0,cShadow,width);
SetWindow( x0+1, y0+1, width-2, height-2 );
MouseShow();
};
void TWindow::Paint(void)
{
MouseHide();
SetWindow( x0+1, y0+1, width-2, height-2 );
SetTextColor( CColor & 0x0F );
SetBackColor( CColor >> 4 );
ClearWindow(' ');
MouseShow();
};
extern winoff; // graphics window!
void TWindow::Move( int dx, int dy )
{
char far* backgr, far* window;
int ix,iy,iw,ih;
int px,py;
int cx,cy;
if ( (x0+dx < 0) || (x1+dx > GetMaxCol()) ||
(y0+dy < 0) || (y1+dy > GetMaxRow()) ) return;
cx = GetCursorX();
cy = GetCursorY();
winoff += dx*2 + dy*160;
MouseHide();
if ( ( Abs(dx)>=width ) || ( Abs(dy) >= height ) )
{ // (( Full window redraw ))
window = new char[bufsize];
// save entire window
SaveWindow(x0,y0,width,height,window);
// restore background
RestoreWindow(x0,y0,buf);
x0 += dx;
x1 += dx;
y0 += dy;
y1 += dy;
// save new background
SaveWindow(x0,y0,width+2,height+1,buf);
// shadow
if (HasShadow) TWindow::Shadow();
// put a window on a new position
RestoreWindow(x0,y0,window);
delete window;
} else {
// (( Partial move ))
backgr = new char[bufsize];
window = new char[bufsize];
// clear shadow
PasteBufWindow(2,height,width,1,x0+2,y1+1,buf);
PasteBufWindow(width,1,2,height-1,x1+1,y0+1,buf);
// save new background
SaveWindow(x0+dx,y0+dy,width+2,height+1,backgr);
// save entire window
SaveWindow(x0,y0,width,height,window);
// copy intersection background area into new background buffer
ix = dx; iy = dy;
if (ix<0) ix=0;
if (iy<0) iy=0;
iw = width+2-(int)Abs(dx);
ih = height+1-(int)Abs(dy);
px = -dx;
py = -dy;
if (px<0) px=0;
if (py<0) py=0;
PasteBufBuf(ix,iy,iw,ih,buf,px,py,backgr);
// show X slice
if (dx>0) { ix=0; iy=0; iw=dx; ih=height; px=x0; py=y0; };
if (dx<0) { ix=width+dx; iy=0; iw=-dx; ih=height; px=x1+dx+1; py=y0; };
if (dx) PasteBufWindow(ix,iy,iw,ih,px,py,buf);
// show Y slice
if (dy>0) { ix=0; iy=0; iw=width; ih=dy; px=x0; py=y0; };
if (dy<0) { ix=0; iy=height+dy; iw=width; ih=-dy; px=x0; py=y1+dy+1; };
if (dy) PasteBufWindow(ix,iy,iw,ih,px,py,buf);
// apply movement
x0 += dx;
x1 += dx;
y0 += dy;
y1 += dy;
// shadow
if (HasShadow) Shadow();
// restore entire window on new position
RestoreWindow( x0, y0, window );
delete window;
// replace background buffer
delete buf;
buf = backgr;
};
SetWindow(x0+1,y0+1,width-2,height-2);
CursorXY(cx,cy);
MouseShow();
};
// *TDlgItem* -------------------------------------------------
TDlgItem::TDlgItem(void)
{
TabStop = False;
Default = False;
HasFocus = False;
Active = False;
next = 0;
prev = 0;
pData = 0;
};
TDlgItem::~TDlgItem(void) {};
void TDlgItem::Paint(void) {};
void TDlgItem::Hide(void) {};
void TDlgItem::FocusOn(void) { if (!HasFocus) { HasFocus=True; Paint(); }; };
void TDlgItem::FocusOff(void) { if (HasFocus) { HasFocus=False; Paint(); }; };
void TDlgItem::Update(void) { Paint(); };
BOOL TDlgItem::FlushData(void) { return True; };
int TDlgItem::Message( TMessage& msg ) {
if (msg.what&evBroadcast)
if (msg.code==cmUpdate)
if ( (msg.target==0) || (msg.target==this) ) Update();
return DLG_NOACTION;
};
int TDlgItem::GetXsize(void) { return 0; };
int TDlgItem::GetYsize(void) { return 0; };
void TDlgItem::MoveXY( int dx, int dy ) { x0+=dx; y0+=dy; x1+=dx; y1+=dy; };
// *TStatic* --------------------------------------------------
TStatic::TStatic( int x, int y, char* n )
{
TabStop = False;
Default = False;
StrCpy(Name,n);
pData = n;
TRect::TRect(x,y,x+StrLenC(n)-1,y);
};
void TStatic::Paint(void) { MouseHide(); SetHiAttr(cStaticTextHi); WriteXYC( x0, y0, cStaticText, Name ); MouseShow(); };
void TStatic::Update(void) { StrCpy(Name,(char*)pData); Paint(); };
int TStatic::GetXsize( void ) { return StrLenC(Name); };
int TStatic::GetYsize( void ) { return 1; };
// *TDivider* -------------------------------------------------
TDivider::TDivider( int x, int y, int len )
{
TabStop = False;
Default = False;
Len = len;
TRect::TRect(x,y,x+Len-1,y);
};
void TDivider::Paint(void) { MouseHide(); SpawnXYC(x0,y0,cDivider,'Ä',Len); MouseShow(); };
// *TButton* --------------------------------------------------
TButton::TButton( int x, int y, char *n, int code, BOOL def, int key, void far* act )
{
TabStop = True;
Default = def;
BtnLen = StrLenC(n)+2;
if ( BtnLen<5 ) BtnLen=5;
StrCpy(Name,n);
NamePos = x0 + (BtnLen-StrLenC(Name))/2;
Action = ( void(far*)() )act;
XCode = code;
hotkey = key;
Pushed = False;
TRect::TRect( x,y,x+BtnLen-1,y );
};
void TButton::Paint(void)
{
char face,hi; // colors
if (HasFocus) { SetCursor(CUR_OFF); face=cButtonA; hi=cButtonAHi; }
else if (Default) { face=cButtonD; hi=cButtonDHi; }
else { face=cButton; hi=cButtonHi; };
MouseHide();
SetHiAttr(hi);
SpawnXYC( x0, y0, cButtonShadow, ' ', Pushed );
SpawnXYC( x0+Pushed, y0, face, ' ', BtnLen );
WriteXYC( x0+NamePos+Pushed, y0, face, Name );
if (HasFocus) {
WriteXYC( x0+Pushed, y0, face, "" );
WriteXYC( x0+Pushed+BtnLen-1, y0, face, "" );
};
if (!Pushed) {
SpawnXYC( x0+1, y0+1, cButtonShadow, 'ß', BtnLen );
SpawnXYC( x0+BtnLen, y0, cButtonShadow, 'Ü', 1 );
} else
SpawnXYC( x0+1, y0+1, cButtonShadow, ' ', BtnLen );
MouseShow();
};
void TButton::Push(void) { Pushed=True; Paint(); };
void TButton::Pop(void) { Pushed=False; Paint(); };
int TButton::Message( TMessage &msg )
{
int xcode = DLG_NOACTION;
// keyboard
if ( msg.what & evKeyb )
{
switch ( msg.code )
{
case kbSpace: if (!HasFocus) break;
case kbEnter:
Push(); Delay(3); Pop();
if (Action) Action();
xcode = XCode;
break;
default:
if ( (hotkey) && ( (msg.code==hotkey) || // scan+ascii
((msg.code&0xFF)==hotkey) || // ascii
((msg.code&0xFF00)==hotkey) ) ) // scan
{
Push(); Delay(3); Pop();
if (Action) Action();
xcode = XCode;
};
};
};
// mouse
if ( msg.what&evMouse )
{
if ( Active )
{
if ( InRect(msg.msx,msg.msy) )
{
if ( (msg.lbutton&msIsdown) && (!Pushed) ) Push();
if ( msg.lbutton&msKeyup )
{
Pop();
Active = False;
if (Action) Action();
xcode = XCode;
};
} else if (Pushed) Pop();
} else {
if ( InRect(msg.msx,msg.msy) )
{
if ( msg.lbutton&msKeydown ) { Active=True; Push(); xcode = DLG_KEYUSED; };
}
};
};//evMouse
return xcode;
};
int TButton::GetXsize( void ) { return BtnLen+1; };
int TButton::GetYsize( void ) { return 2; };
// *TEdit* ----------------------------------------------------
TEdit::TEdit( int x, int y, int w, char *s, BOOL autotab,
int editmode, int maxlen, int discreet )
{
TabStop = True;
Default = False;
Len = w;
MaxLen = (maxlen==0 ? 255 : maxlen);
AutoTab = autotab;
InsMode = True;
Editable = (BOOL)( editmode & edEdit );
EditMode = (BOOL)( editmode & edInput );
Editing = (BOOL)( EditMode ? 1 : 0 );
pData = s;
StrCpy(str,s);
SPos = 0;
CPos = 1;
if (discreet) dChar = '*'; else dChar=0;
TRect::TRect( x,y,x+w,y );
};
void TEdit::ShowLine(void)
{
int i;
char s[256];
char cstr,cicon;
// colors & cursor
if (HasFocus)
{
if (Editing) { cstr=cEditA; cicon=cEditIconA; }
else { cstr=cEditView; cicon=cEditViewIcon; };
if (Editing)
{
CursorXY( x0+CPos-SPos, y0 );
if (InsMode) SetCursor(CUR_THIN); else SetCursor(CUR_BLOCK);
} else SetCursor(CUR_OFF);
} else {
cstr=cEdit; cicon=cEditIcon;
};
MouseHide();
if (SPos > 0) StrCpy(s,"\x11"); else StrCpy(s," ");
WriteXYC( x0, y0, cicon, s );
if (StrLen(str)-SPos > Len-2) StrCpy(s,"\x10"); else StrCpy(s," ");
WriteXYC( x0+Len-1, y0, cicon, s );
i = StrLen(str)-SPos;
if (i > Len-2) i=Len-2;
StrCut(s,str,SPos,i+SPos-1);
StrAdd(s," ",Len-2-StrLen(s));
if (dChar) {
SpawnXYC(x0+1,y0,cstr,dChar,StrLen(str));
SpawnXYC(x0+1+StrLen(str),y0,cstr,' ',Len-StrLen(str)); // discreet
} else WriteXYC( x0+1, y0, cstr, s ); // normal
MouseShow();
};
void TEdit::MoveLeft(void)
{
if (Editing) {
if (CPos >= 2) CPos--;
if (CPos < SPos+1) SPos=CPos-1;
if (SPos < 0) SPos=0;
} else {
if(SPos>0) SPos--;
};
};
void TEdit::MoveRight(void)
{
if (Editing) {
if (CPos <= StrLen(str)) CPos++;
if (CPos > SPos+Len-1) SPos=CPos-Len+1;
} else {
if ( SPos < StrLen(str)+1-Len+1 ) SPos++;
};
};
void TEdit::MoveHome(void) { CPos=1; SPos=0; };
void TEdit::MoveEnd(void) {
CPos = StrLen(str)+1;
SPos = CPos-Len+1;
if (SPos < 0) SPos=0;
};
void TEdit::Paint(void) { ShowLine(); };
int TEdit::Message( TMessage &msg )
{
unsigned char ch;
int xcode=DLG_NOACTION;
if ( msg.what & evBroadcast )
return TDlgItem::Message(msg);
if ( msg.what & evKeyb )
{
if (!HasFocus) return DLG_NOACTION;
xcode = DLG_KEYUSED;
switch( msg.code )
{
case kbUp: if (!Editing) xcode=DLG_PREV; break;
case kbDown: if (!Editing) xcode=DLG_NEXT; break;
case kbLeft: MoveLeft(); break;
case kbRight: MoveRight(); break;
case kbHome: MoveHome(); break;
case kbEnd: MoveEnd(); break;
case kbIns: InsMode = (BOOL)InsMode^True; break;
case kbDel: StrDel(str,str,CPos-1); break;
case kbBackSp:
StrBksp(str,str,CPos-1);
if (SPos) SPos--;
MoveLeft();
break;
case kbEnter:
if ( (Editable) && !(EditMode&edInput) )
{
Editing = (BOOL)Editing^True;
Paint();
xcode = DLG_KEYUSED;
} else {
if (AutoTab) xcode = DLG_NEXT;
else xcode = DLG_NOACTION;
};
break;
default:
if (Editing)
{
ch = msg.code & 0x00FF;
if (StartEditing) *str=0;
if ( ch>=' ' )
if ( (!MaxLen) || ( (CPos<=MaxLen) && ( !InsMode || (StrLen(str)<MaxLen) ) ) )
{
StrEnter(str,str,CPos-1,ch,InsMode);
MoveRight();
};
} else xcode=DLG_NOACTION;
break;
};//switch (code)
StartEditing=False;
};// if evKeyb
if (msg.what&evMouse)
if (msg.lbutton&msKeydown)
if (InRect(msg.msx,msg.msy))
if (!HasFocus) xcode = DLG_KEYUSED;
if (xcode!=DLG_NOACTION) Paint();
return xcode;
};
void TEdit::FocusOn(void) { if (!HasFocus) StartEditing=True; TDlgItem::FocusOn(); };
void TEdit::FocusOff(void) { CPos=1; SPos=0; TDlgItem::FocusOff(); };
BOOL TEdit::FlushData(void) { StrCpy((char*)pData,str); return True; };
void TEdit::Update(void) { StrCpy(str,(char*)pData); CPos=1; SPos=0; Paint(); };
int TEdit::GetXsize( void ) { return Len; };
int TEdit::GetYsize( void ) { return 1; };
// *TEditNum* -------------------------------------------------
TEditNum::TEditNum( int x, int y, int w, long *p, BOOL autotab, int editmode )
: TEdit( x,y,w,0,autotab,editmode,11 )
{
IntToDec(*p,str);
pData = p;
datalen=4;
};
TEditNum::TEditNum( int x, int y, int w, int *p, BOOL autotab, int editmode )
: TEdit( x,y,w,0,autotab,editmode,6 )
{
int i=*p;
IntToDec(i,str);
pData = p;
datalen=2;
};
int TEditNum::Message(TMessage& msg)
{
int code;
if ( (msg.what==evKeyb) && (HasFocus) )
{
switch( msg.code )
{
case kbLeft: case kbRight: case kbUp: case kbDown:
case kbHome: case kbEnd: case kbIns: case kbDel:
case kbBackSp: case kbEnter:
return TEdit::Message(msg);
default:
code = msg.code&0xFF;
if ( ( code>='0' && code<='9' ) || (code=='-') )
return TEdit::Message(msg);
else
return DLG_KEYUSED;
};//switch
};
return TEdit::Message(msg);
};
BOOL TEditNum::FlushData(void) {
if (datalen==2) *(unsigned int*)pData = StrToInt(str);
if (datalen==4) *(unsigned long*)pData = StrToLong(str);
return True;
};
void TEditNum::Update(void) {
if (datalen==2) IntToDec(*(int*)pData,str);
if (datalen==4) IntToDec(*(long*)pData,str);
CPos=1; SPos=0;
Paint();
};
// *TGroup* ---------------------------------------------------
TGroup::TGroup( int x, int y )
{
TabStop = True;
Xsize=0; Ysize=0;
cur = 0;
nitems = 0;
TRect::TRect(x,y,x,y);
};
TGroup::~TGroup( void )
{
TDlgItem *i;
for (int n=0; n<nitems; n++) {
i=cur->next;
delete cur;
cur=i;
};
};
void TGroup::Insert( TDlgItem* i )
{
if (!cur) {
i->next=i; i->prev=i; cur=i;
} else {
i->next=cur; i->prev=cur->prev;
cur->prev->next=i; cur->prev=i;
// i->prev=cur; i->next=cur->next;
// cur->next=i; cur->prev->prev=i;
};
if (i->x0 + i->GetXsize() > Xsize) Xsize = i->x0 + i->GetXsize();
if (i->y0 + i->GetYsize() > Ysize) Ysize = i->y0 + i->GetYsize();
nitems++;
TRect::TRect( x0,y0,x0+Xsize,y0+Ysize );
};
void TGroup::SetWin(void) {
GetWindow(grWinx,grWiny,grWinw,grWinh);
SetWindow(grWinx+x0,grWiny+y0,Xsize,Ysize);
};
void TGroup::RestWin(void) { SetWindow(grWinx,grWiny,grWinw,grWinh); };
void TGroup::FocusOn( void )
{
if (!HasFocus) {
HasFocus=True;
SetWin();
if (cur) cur->FocusOn();
RestWin();
};
};
void TGroup::FocusOff( void )
{
if (HasFocus) {
HasFocus=False;
SetWin();
if (cur) cur->FocusOff();
RestWin();
};
};
void TGroup::Paint( void )
{
int n;
TDlgItem *i=cur;
if (cur) {
MouseHide();
SetWin();
for (n=0; n<Ysize; n++) SpawnXYC( 0, n, cGroup, ' ', Xsize );
i=cur; for (n=0; n<nitems; n++) { i->Paint(); i=i->next; };
if (HasFocus) cur->FocusOn();
RestWin();
MouseShow();
};
};
int TGroup::Message( TMessage &msg )
{
int n,xcode=DLG_NOACTION;
TDlgItem* i;
if ( msg.what & evBroadcast )
return TDlgItem::Message(msg);
SetWin();
if ( msg.what & evKeyb )
{
if (HasFocus) xcode=DLG_KEYUSED; else xcode=DLG_NOACTION;
switch( msg.code )
{
case kbUp:
if (cur && HasFocus) { cur->FocusOff(); cur=cur->prev; cur->FocusOn(); };
break;
case kbDown:
if (cur && HasFocus) { cur->FocusOff(); cur=cur->next; cur->FocusOn(); };
break;
case kbRight:
if (cur && HasFocus) {
cur->FocusOff();
cur=cur->next;
for (n=1; n<Ysize; n++) cur=cur->next;
cur->FocusOn();
};
break;
case kbLeft:
if (cur && HasFocus) {
cur->FocusOff();
cur=cur->prev;
for (n=1; n<Ysize; n++) cur=cur->prev;
cur->FocusOn();
};
break;
default:
// give a message (cur)
// for all the rest items till cur
// give a message to item i
// if (keyused)
// cur->FocusOff
// i->FocusOn
// cur = i (so that loop will last till this item)
// for
if (cur) xcode = cur->Message(msg);
if (xcode==DLG_KEYUSED) cur->Paint();
i=cur->next;
while (i!=cur) {
if ( i->Message(msg)==DLG_KEYUSED ) {
cur->FocusOff();
i->FocusOn();
xcode=DLG_KEYUSED;
msg.code=DLG_KEYUSED;
cur=i;
};
i=i->next;
};
break;
};
};
if ( msg.what & evMouse )
{
if (InRect(msg.msx,msg.msy))
{
msg.msx -= x0;
msg.msy -= y0;
if (cur) xcode = cur->Message(msg);
if (xcode==DLG_KEYUSED) cur->Paint();
i=cur->next;
while (i!=cur) {
if ( i->Message(msg)==DLG_KEYUSED ) {
cur->FocusOff();
i->FocusOn();
xcode=DLG_KEYUSED;
msg.what=evKeyb;
msg.code=DLG_KEYUSED;
cur=i;
};
i=i->next;
};
msg.msx -= x0;
msg.msy -= y0;
};
};
RestWin();
return xcode;
};
BOOL TGroup::FlushData(void) {
TDlgItem* i;
i=cur;
for (int n=0; n<nitems; n++) {
if ( ! i->FlushData() ) return False;
i=i->next;
};
return True;
};
void TGroup::Update(void) {
TDlgItem* i;
int n;
i=cur;
MouseHide();
SetWin();
for (n=0; n<Ysize; n++) SpawnXYC( 0, n, cGroup, ' ', Xsize );
for (n=0; n<nitems; n++) {
i->Update();
i=i->next;
};
RestWin();
MouseShow();
if (HasFocus) cur->FocusOn();
};
// *TCheckBox* ------------------------------------------------
TCheckBox::TCheckBox( int x, int y, char *n, int* data, int key )
{
TabStop = True;
Default = False;
HasFocus = False;
Name = new char[128];
StrCpy(Name,n);
pData = data;
checked = *data;
hotkey = key;
TRect::TRect(x,y,x+StrLenC(n)+6-1,y);
};
TCheckBox::~TCheckBox(void) { delete Name; };
void TCheckBox::Paint(void)
{
char a,hi;
char s[128];
MouseHide();
if (HasFocus) { a=cCheckA; hi=cCheckAHi; }
else { a=cCheck; hi=cCheckHi; };
if (checked) StrCpy(s," [X] "); else StrCpy(s," [ ] ");
StrAdd(s,Name,1);
SetHiAttr(hi);
WriteXYC( x0, y0, a, s );
if (HasFocus) { SetCursor(CUR_THIN); CursorXY( x0+2, y0 ); };
MouseShow();
};
int TCheckBox::Message( TMessage &msg )
{
int code=msg.code;
if ( msg.what & evBroadcast )
return TDlgItem::Message(msg);
if ( msg.what & evKeyb )
{
if ( (hotkey) && ( (code==hotkey) ||
((code&0xFF)==hotkey) ||
((code&0xFF00)==hotkey) ) )
{
if (checked) checked=0; else checked=1;
Paint();
msg.code=DLG_KEYUSED;
return DLG_KEYUSED;
};
if( (HasFocus) && (code==kbSpace) )
{
if (checked) checked=0; else checked=1;
Paint();
msg.code=DLG_KEYUSED;
return DLG_KEYUSED;
} else return DLG_NOACTION;
};//if evKeyb
if (msg.what&evMouse)
if (msg.lbutton&msKeydown)
if (InRect(msg.msx,msg.msy))
{
if (checked) checked=0; else checked=1;
Paint();
msg.what=evKeyb;