-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVERIDIAN.PAS
1502 lines (1398 loc) · 41.6 KB
/
VERIDIAN.PAS
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
{$I COMPILER.INC}
unit Veridian;
interface
uses
AplObj,
AplDos,
AplTypes,
AplConst,
Drawing,
Dialogs,
Lists,
AplStr,
Graphics,
Gr8Drv,
GraphIni,
GraphApp,
Colors,
MouseDrv,
MemDrv,
DateTime,
Streams,
Actions,
Controls,
Palettes,
ListView,
Views,
Events,
Menus;
const
DefaultDoubleClickDelay = 1.0;
DefaultCursorBlinkRate = 0.4;
DefaultMouseSensitivity = 4;
type
PVeridianApp = ^TVeridianApp;
PVeridianAppSettings = ^TVeridianAppSettings;
PAppState = ^TAppState;
TVeridianAppSettings = object(TPersistent)
private
public
CursorBlinkRate: double;
UpdateScrollContents: boolean;
DoubleClickDelay: TTimeSpan;
MouseSensitivity: real;
procedure Init; virtual;
procedure Assign(var ASource: TObject); virtual;
procedure SaveToStream(AStream: PStream); virtual;
procedure LoadFromStream(AStream: PStream); virtual;
end;
TAppState = object(TObject)
private
public
CursorOn: boolean;
DrawEnabled: boolean;
MouseVisible: boolean;
procedure Init; virtual;
procedure Assign(var ASource: TObject); virtual;
end;
TVeridianApp = object(TGraphApp)
private
FOffScreen: PMemoryStream;
{$IFDEF debug}
FMemAvail: longint;
FMemMaxAvail: longint;
FMemLabel: PLabel;
{$ENDIF}
FKeyEvent: TKeyEvent;
FMouseEvent: TMouseEvent;
FMouseState, FOldMouseState: TMouseState;
FCursorBlinkVisible: boolean;
FBlinkCurrentTime: TDateTime;
FBlinkElapsed: TTimeSpan;
FDoubleClickStart: TDateTime;
FDoubleClickPos: TPoint;
FSpecialControls: TObjectStack;
FNewWindowX, FNewWindowY: integer;
AltKeyDown: boolean;
SwitchingWindows: boolean;
ErrorDialog: PShowMessageDialog;
function LoadFont(const AFilename: string): PFont;
function CreateDesktop: PDesktop; virtual;
function HandleWindowSwitch: boolean;
procedure GetFocusList(AList: PObjectList; AControl: PControl);
procedure CreateObjects;
procedure LoadFonts;
procedure BeginWindowSwitch;
procedure EndWindowSwitch;
procedure SwitchWindow;
procedure HandleKeyEvent(AControl: PControl; var AEvent: TKeyEvent);
procedure HandleSpecialKeys(AControl: PControl; var AEvent: TKeyEvent);
procedure HandleActionKey(AControl: PActionControl; var AEvent: TKeyEvent);
procedure HandleMouseEvent(AControl: PControl; var AEvent: TMouseEvent);
procedure HandleMouseMove(AControl: PControl;
var AEvent: TMouseEvent); virtual;
procedure HandleMouseEnter(AControl: PControl;
var AEvent: TMouseEvent); virtual;
procedure HandleMouseWheelChanged(AControl: PControl;
var AEvent: TMouseEvent); virtual;
procedure HandleMouseUp(AControl: PControl; var AEvent: TMouseEvent;
AButton: TButtonState); virtual;
procedure HandleMouseDown(AControl: PControl; var AEvent: TMouseEvent;
AButton: TButtonState); virtual;
procedure HandleMouseCursor;
procedure HandleDoubleClick(ATime: TDateTime; AControl: PControl; var AEvent: TMouseEvent);
procedure CleanupWindows;
procedure InitMouseEvent(AControl: PControl; var AEvent: TMouseEvent);
procedure DrawCursor;
procedure HandleCursor;
procedure ApplySettings;
procedure SetMouseSensitivity(ASens: real);
procedure ParseParameters;
{$IFDEF debug}
procedure UpdateDebugInfo;
{$ENDIF}
public
State: TAppState;
StateStack: TObjectStack;
Colors: TColors;
DragRect, LastDragRect: TRect;
DragRectVisible: boolean;
DragInitialPos: TPoint;
DragInitialSize: TSize;
MenuBar: PMenubar;
Taskbar: PTaskbar;
Fonts: PFontList;
SystemFont: PFont;
SymbolFont: PFont;
EditorFont: PFont;
Settings: TVeridianAppSettings;
CursorBlinkTime: TDateTime;
Parameters: TStringList;
DoubleClickControl: PControl;
MouseOverControl: PControl;
LeftMouseDownControl: PControl;
RightMouseDownControl: PControl;
SelectingControl: PControl;
ActiveControl: PFocusControl;
ActiveWindow: PWindow;
ActiveDropDown: PDropDownList;
ActiveDialog: PDialog;
DragControl: PControl;
ScrollSlider: PControl;
constructor Create(ADriver: TGraphDrivers; AWidth: integer;
AHeight: integer; ABpp: integer);
destructor Free; virtual;
function CheckNilPtr(APtr: pointer): boolean;
function GetFont(const AId: string): PFont;
function DefaultWindowX: integer;
function DefaultWindowY: integer;
procedure Error(var ASender; ACode: word); virtual;
procedure ProcessEvents; virtual;
procedure Run; virtual;
procedure Init; virtual;
procedure CursorOn; virtual;
procedure CursorOff; virtual;
procedure PushState; virtual;
procedure PopState; virtual;
procedure SetColors(const AColors: TColors); virtual;
procedure InitActions; virtual;
procedure InitControls; virtual;
procedure Initialized; virtual;
procedure ActionExecute(ASender: PActionControl; AAction: PAction); virtual;
procedure UpdateActionControl(AControl: PActionControl); virtual;
procedure SetActiveControl(AControl: PFocusControl);
procedure CloseAllMenus;
procedure StoreSpecialControlState;
procedure RestoreSpecialControlState;
procedure ClearSpecialControlState;
procedure EnableDrawing;
procedure DisableDrawing;
procedure GetMouseState(var AMouseState: TMouseState);
procedure DrawDragRect(var ARect: TRect);
function FocusNext(AControl: PControl; AReverse: boolean): boolean;
function FocusFirst: boolean;
function FocusLast: boolean;
function GetMouseControl(AControl: PControl; var AMouseState: TMouseState): PControl;
function TaskBarHeight: integer;
function MenuBarHeight: integer;
end;
var
VeridianApp: PVeridianApp;
implementation
uses
AplUtils,
Dos,
KeyDrv;
var
PreviousExitProc: PProc;
procedure OnAllocError(ASize: word); far;
begin
with VeridianApp^ do begin
Error(VeridianApp, ecNotEnoughMemory);
end;
end;
constructor TVeridianApp.Create(ADriver: TGraphDrivers; AWidth: integer;
AHeight: integer; ABpp: integer);
var
modeId: integer;
begin
VeridianApp := @self;
inherited Create(ADriver);
if CheckReRaise(Graph) then begin
VeridianApp := nil;
exit;
end;
modeId := GetGraphicsModeId(AWidth, AHeight, ABpp);
if not SetMode(modeId) then begin
VeridianApp := nil;
Raise(ecGraphicsModeNotFound);
exit;
end;
Initialized;
end;
procedure TVeridianApp.Initialized;
var
increment: integer;
begin
inherited Initialized;
LoadFonts;
FOffScreen := nil;
Desktop := CreateDesktop;
Desktop^.Font := SystemFont;
InitActions;
InitControls;
Desktop^.Layout;
MenuBar^.Layout;
Keyboard.GetKey;
increment := 10;
if Graph^.Mode^.Width < 512 then
increment := 3;
FNewWindowX := increment;
FNewWindowY := increment;
ErrorDialog := New(PShowMessageDialog, Create('Error', '', [mbOk]));
TString.Free(ErrorDialog^.MessageLabel^.Caption);
GetMem(ErrorDialog^.MessageLabel^.Caption, 256);
FillChar(ErrorDialog^.MessageLabel^.Caption^, 256, 0);
if not (Assigned(ErrorDialog) and Assigned(ErrorDialog^.MessageLabel^.Caption)) then begin
WriteLn(ErrorMessage(ecNotEnoughMemory));
Halt(ecNotEnoughMemory);
end;
end;
destructor TVeridianApp.Free;
begin
FreeMem(ErrorDialog^.MessageLabel^.Caption, 256);
FreeAndNil(FOffScreen);
StateStack.DisposeObjects := true;
StateStack.Free;
Parameters.Free;
Settings.Free;
FSpecialControls.Free;
FreeAndNil(Fonts);
inherited Free;
end;
procedure TVeridianApp.InitActions;
begin
end;
procedure TVeridianApp.InitControls;
begin
MenuBar := New(PMenuBar, Create);
Taskbar := New(PTaskbar, Create);
{$IFDEF debug}
FMemLabel := New(PLabel, CreateParent('MemLabel', MenuBar));
FMemLabel^.TransparentBack := false;
FMemLabel^.SetForeColor(MenuBar^.ForeColor);
FMemLabel^.SetBackColor(MenuBar^.BackColor);
FMemLabel^.Font := Fonts^.GetItemById('editor');
FMemLabel^.AutoSize := true;
FMemLabel^.Layout;
{$ENDIF}
end;
function TVeridianApp.LoadFont(const AFilename: string): PFont;
var
newFont: PFont;
begin
if FileExists(AFilename) then begin
newFont := New(PProportionalFont, Create);
newFont^.LoadFromFile(AFilename);
if newFont^.HasException then begin
newFont^.ClearException;
newFont := New(PSystemFont, CreateId('System'));
end;
end
else
newFont := New(PSystemFont, CreateId('System'));
LoadFont := newFont;
Fonts^.Add(newFont);
end;
function TVeridianApp.GetFont(const AId: string): PFont;
var
index: integer;
font: PFont;
begin
font := Fonts^.GetItemById(AId);
if not Assigned(font) then
font := SystemFont;
GetFont := font;
end;
procedure TVeridianApp.LoadFonts;
var
font: PFont;
begin
Fonts := New(PFontList, Create);
if Graph^.Mode^.Width < 512 then begin
font := LoadFont('factoria.fnt');
font^.SetId('system');
SystemFont := font;
font := LoadFont('factoria.fnt');
font^.SetId('editor');
EditorFont := font;
font := LoadFont('symsmall.fnt');
font^.SetId('symbol');
SymbolFont := font;
end
else begin
font := LoadFont('olympia.fnt');
font^.SetId('system');
SystemFont := font;
font := LoadFont('seattle.fnt');
font^.SetId('editor');
EditorFont := font;
font := LoadFont('symbol.fnt');
font^.SetId('symbol');
SymbolFont := font;
end;
end;
procedure TVeridianApp.CreateObjects;
begin
FKeyEvent.Create;
FMouseEvent.Create;
FMouseState.Create;
FOldMouseState.Create;
FBlinkElapsed.Create;
FDoubleClickStart.Create;
FBlinkCurrentTime.Create;
FSpecialControls.Create;
FSpecialControls.DisposeObjects := false;
CursorBlinkTime.Create;
StateStack.Create;
Settings.Create;
DragRect.Create;
LastDragRect.Create;
Colors := LightColors;
State.Create;
DragInitialPos.Create;
DragInitialSize.Create;
Parameters.Create;
FDoubleClickPos.Create;
ParseParameters;
end;
procedure TVeridianApp.Init;
begin
inherited Init;
Memory.OnAllocError := @OnAllocError;
FCursorBlinkVisible := false;
CreateObjects;
SwitchingWindows := false;
MenuBar := nil;
Mouse.UseSystemCursor := false;
Mouse.HideMouse;
DragRectVisible := false;
ActiveControl := nil;
ActiveWindow := nil;
MouseOverControl := nil;
LeftMouseDownControl := nil;
RightMouseDownControl := nil;
DoubleClickControl := nil;
SelectingControl := nil;
DragControl := nil;
ScrollSlider := nil;
ActiveDropDown := nil;
ActiveDialog := nil;
{$IFDEF debug}
FMemAvail := MemAvail;
FMemMaxAvail := MaxAvail;
FMemLabel := nil;
{$ENDIF}
end;
function TVeridianApp.CreateDesktop: PDesktop;
begin
CreateDesktop := New(PDesktop, CreateParent('Desktop', nil, nil));
end;
procedure TVeridianApp.UpdateActionControl(AControl: PActionControl);
begin
end;
procedure TVeridianApp.ActionExecute(ASender: PActionControl; AAction: PAction);
var
event: TActionEvent;
begin
if not (Assigned(ASender) and Assigned(AAction) and AAction^.Enabled) then
exit;
UpdateActionControl(ASender);
if not (ASender^.IsVisibleAndEnabled) then
exit;
if Assigned(AAction^.OnExecute) and AAction^.Enabled then begin
event.Create;
event.Action := AAction;
event.Sender := ASender;
TActionExecuteEventProc(AAction^.OnExecute)(event);
end;
end;
procedure TVeridianApp.HandleMouseEnter(AControl: PControl; var AEvent: TMouseEvent);
var
index: integer;
control: PControl;
begin
if Assigned(DragControl) then
exit;
if Assigned(MouseOverControl) and (MouseOverControl <> AControl)
and (MouseOverControl^.IsVisibleAndEnabled) then begin
MouseOverControl^.MouseLeave(AEvent);
MouseOverControl := nil;
end;
if AControl^.IsMouseOver then
exit;
MouseOverControl := AControl;
if (MouseCursor <> AControl^.MouseCursor) then begin
EraseMouseCursor(AEvent.NewMouseState);
MouseCursor := AControl^.MouseCursor;
DrawMouseCursor(AEvent.NewMouseState);
end;
if AControl^.IsVisibleAndEnabled then
AControl^.MouseEnter(AEvent);
end;
procedure TVeridianApp.HandleMouseMove(AControl: PControl; var AEvent: TMouseEvent);
begin
AControl^.MouseMove(AEvent);
end;
procedure TVeridianApp.HandleMouseWheelChanged(AControl: PControl; var AEvent: TMouseEvent);
var
clipRect, rect: TRect;
begin
if not AControl^.IsVisibleAndEnabled then
exit;
AControl^.GetDrawRect(rect);
AControl^.GetClipRect(clipRect);
rect.Intersect(clipRect);
if rect.Contains(AEvent.NewMouseState.X, AEvent.NewMouseState.Y) then
AControl^.MouseWheelChanged(AEvent);
if (not AEvent.Handled) and Assigned(AControl^.Parent) then
HandleMouseWheelChanged(AControl^.Parent, AEvent);
end;
procedure TVeridianApp.HandleMouseUp(AControl: PControl; var AEvent: TMouseEvent;
AButton: TButtonState);
var
selecting: boolean;
dragEvent: TDragEvent;
now: TDateTime;
scrollParent: PScrollBar;
scrollEvent: TScrollEvent;
actionControl: PActionControl;
begin
if AButton in AEvent.NewMouseState.ButtonState then
exit;
if not (AButton in AEvent.OldMouseState.ButtonState) then
exit;
if Assigned(DragControl) then begin
dragEvent.Create;
dragEvent.InitialX := DragInitialPos.X;
dragEvent.InitialY := DragInitialPos.Y;
dragEvent.X := AEvent.NewMouseState.X;
dragEvent.Y := AEvent.NewMouseState.Y;
DragControl^.DragEnd(dragEvent);
end;
DragControl := nil;
selecting := false;
{ selecting := SelectingControl = AControl;
SelectingControl := nil;}
if Assigned(ScrollSlider) and Assigned(ScrollSlider^.Parent) then begin
scrollParent := PScrollBar(ScrollSlider^.Parent);
scrollEvent.Create;
scrollEvent.ScrollPosition := scrollParent^.ScrollPosition;
scrollEvent.Orientation := scrollParent^.Orientation;
scrollParent^.PositionChanged(scrollEvent);
end;
ScrollSlider := nil;
now.CreateNow;
if ((LeftMouseDownControl = AControl) and (AButton = bsLeft))
or ((RightMouseDownControl = AControl) and (AButton = bsRight)) or selecting then begin
AControl^.MouseUp(AEvent);
AControl^.MouseClick(AEvent);
HandleDoubleClick(now, AControl, AEvent);
end;
if AButton = bsLeft then
LeftMouseDownControl := nil
else
RightMouseDownControl := nil;
if AEvent.Handled then
exit;
if not AControl^.IsActionControl then
exit;
actionControl := PActionControl(AControl);
if Assigned(actionControl^.Action) and actionControl^.Action^.Enabled then begin
if Assigned(ActiveDialog) then begin
ActiveDialog^.ActionExecute(actionControl, actionControl^.Action);
exit;
end;
ActionExecute(actionControl, actionControl^.Action);
end;
end;
procedure TVeridianApp.HandleMouseDown(AControl: PControl; var AEvent: TMouseEvent;
AButton: TButtonState);
var
rect: TRect;
intersects: boolean;
container: PMenuItemContainer;
index: integer;
parent: PControl;
window: PWindow;
event: TKeyEvent;
begin
if not (AButton in AEvent.NewMouseState.ButtonState) then
exit;
if AButton in AEvent.OldMouseState.ButtonState then
exit;
if not AControl^.IsVisibleAndEnabled then
exit;
if Assigned(ActiveDropDown) then begin
ActiveDropDown^.GetDrawRect(rect);
intersects := rect.Contains(AEvent.NewMouseState.X, AEvent.NewMouseState.Y);
if not intersects then begin
event.Create;
event.Key := kyEsc;
ActiveDropDown^.KeyPress(event);
ActiveDropDown := nil;
end;
end;
intersects := false;
for index := 0 to MenuManager.OpenMenus^.Count - 1 do begin
container := MenuManager.OpenMenus^.GetItem(index);
container^.GetDrawRect(rect);
if rect.Contains(AEvent.NewMouseState.X, AEvent.NewMouseState.Y) then
intersects := true;
if Assigned(container^.ParentMenuItem) then begin
container^.ParentMenuItem^.GetDrawRect(rect);
if rect.Contains(AEvent.NewMouseState.X, AEvent.NewMouseState.Y) then
intersects := true;
end;
end;
if not intersects then
MenuManager.CloseAllMenus;
if AButton = bsLeft then
LeftMouseDownControl := AControl
else
RightMouseDownControl := AControl;
parent := AControl^.Parent;
window := nil;
while Assigned(parent) do begin
if parent^.IsWindow then
window := PWindow(parent);
parent := parent^.Parent;
end;
if Assigned(window) and (ActiveWindow <> window)
and window^.IsVisibleAndEnabled then
window^.Activate;
if Assigned(ActiveControl) and (AControl^.IsFocusControl)
and (AControl <> PControl(ActiveControl)) then begin
PFocusControl(AControl)^.Focus;
end;
AControl^.MouseDown(AEvent);
end;
procedure TVeridianApp.HandleCursor;
var
seconds: Double;
begin
if not (Assigned(ActiveControl)
and ActiveControl^.Focused
and ActiveControl^.UsesCursor
and ActiveControl^.IsVisibleAndEnabled) then
exit;
if State.CursorOn then begin
FBlinkCurrentTime.SetNow;
FBlinkElapsed.Ticks := FBlinkCurrentTime.Ticks - CursorBlinkTime.Ticks;
seconds := FBlinkElapsed.TotalSeconds;
if seconds > Settings.CursorBlinkRate then begin
FCursorBlinkVisible := not FCursorBlinkVisible;
CursorBlinkTime.SetNow;
DrawCursor;
end;
end;
end;
procedure TVeridianApp.InitMouseEvent(AControl: PControl; var AEvent: TMouseEvent);
var
rect: TRect;
begin
AEvent.Clear;
AEvent.NewMouseState.Assign(FMouseState);
AEvent.OldMouseState.Assign(FOldMouseState);
AEvent.X := AEvent.NewMouseState.X;
AEvent.Y := AEvent.NewMouseState.Y;
{ Get the state in relation to the control's coordinates }
AControl^.GetDrawRect(rect);
Dec(AEvent.X, rect.X);
Dec(AEvent.Y, rect.Y);
end;
procedure TVeridianApp.GetMouseState(var AMouseState: TMouseState);
begin
AMouseState.Create;
AMouseState.Assign(FMouseState);
end;
function TVeridianApp.GetMouseControl(AControl: PControl; var AMouseState: TMouseState): PControl;
var
index: integer;
clipRect, drawRect: TRect;
control: PControl;
begin
GetMouseControl := nil;
if not AControl^.IsVisible then
exit;
if AControl^.Controls^.Count > 0 then begin
for index := AControl^.Controls^.Count - 1 downto 0 do begin
control := AControl^.Controls^.GetItem(index);
control := GetMouseControl(control, AMouseState);
if Assigned(control) then begin
GetMouseControl := control;
exit;
end;
end;
end;
AControl^.GetClipRect(drawRect);
if drawRect.Contains(AMouseState.X, AMouseState.Y) then
GetMouseControl := AControl;
end;
procedure TVeridianApp.HandleMouseEvent(AControl: PControl; var AEvent: TMouseEvent);
var
index: integer;
control: PControl;
dragEvent: TDragEvent;
begin
if AEvent.Handled then
exit;
control := GetMouseControl(Desktop, AEvent.NewMouseState);
AEvent.Sender := control;
InitMouseEvent(control, FMouseEvent);
InitMouseEvent(control, FMouseEvent);
if (FMouseState.WheelCounter <> FOldMouseState.WheelCounter) then
HandleMouseWheelChanged(control, FMouseEvent);
if (FMouseState.ButtonState <> FOldMouseState.ButtonState) then begin
HandleMouseDown(control, FMouseEvent, bsLeft);
HandleMouseDown(control, FMouseEvent, bsRight);
HandleMouseUp(control, FMouseEvent, bsLeft);
HandleMouseUp(control, FMouseEvent, bsRight);
end;
if (FMouseState.X <> FOldMouseState.X) or (FMouseState.Y <> FOldMouseState.Y) then begin
if Assigned(ScrollSlider) then
PScrollSlider(ScrollSlider)^.MouseMove(FMouseEvent);
HandleMouseMove(control, FMouseEvent);
if Assigned(DragControl) then begin
dragEvent.Create;
dragEvent.InitialX := DragInitialPos.X;
dragEvent.InitialY := DragInitialPos.Y;
dragEvent.X := AEvent.NewMouseState.X;
dragEvent.Y := AEvent.NewMouseState.Y;
DragControl^.DragMove(dragEvent);
end;
if Assigned(LeftMouseDownControl)
and (LeftMouseDownControl^.CanDrag(AEvent))
and not Assigned(DragControl) then begin
if not LeftMouseDownControl^.IsVisibleAndEnabled then
exit;
DragControl := LeftMouseDownControl;
DragInitialPos.SetCoords(AEvent.NewMouseState.X, AEvent.NewMouseState.Y);
dragEvent.Create;
dragEvent.InitialX := DragInitialPos.X;
dragEvent.InitialY := DragInitialPos.Y;
dragEvent.X := DragInitialPos.X;
dragEvent.Y := DragInitialPos.Y;
DragInitialSize.CreateDims(DragControl^.Width, DragControl^.Height);
LeftMouseDownControl^.DragStart(dragEvent);
end;
HandleMouseEnter(control, FMouseEvent);
end;
end;
procedure TVeridianApp.HandleActionKey(AControl: PActionControl; var AEvent: TKeyEvent);
var
index: integer;
action: PAction;
begin
for index := 0 to Desktop^.ActionList^.Count - 1 do begin
action := Desktop^.ActionList^.GetItem(index);
if (action^.Shortcut <> AEvent.Key) or not action^.Enabled then
continue;
if Assigned(ActiveDialog) then
ActiveDialog^.ActionExecute(PActionControl(AControl), action)
else
ActionExecute(PActionControl(AControl), action);
AEvent.Handled := true;
break;
end;
end;
function TabOrderCompare(AItem1, AItem2: pointer): integer;
var
control1, control2: PControl;
focusControl1, focusControl2: PFocusControl;
parent1, parent2: PControl;
begin
focusControl1 := nil;
control1 := PControl(AItem1);
control2 := PControl(AItem2);
parent1 := control1^.Parent;
parent2 := control2^.Parent;
while Assigned(parent1) and not (parent1^.IsWindow or parent1^.IsDesktop) do begin
control1 := parent1;
parent1 := parent1^.Parent;
end;
while Assigned(parent2) and not (parent2^.IsWindow or parent2^.IsDesktop) do begin
control2 := parent2;
parent2 := parent2^.Parent;
end;
if control1^.IsFocusControl then
focusControl1 := PFocusControl(control1);
if control2^.IsFocusControl then
focusControl2 := PFocusControl(control2);
if parent1 = parent2 then begin
if Assigned(focusControl1) and Assigned(focusControl2) then begin
if focusControl1^.TabOrder > focusControl2^.TabOrder then
TabOrderCompare := -1
else if focusControl1^.TabOrder < focusControl2^.TabOrder then
TabOrderCompare := 1
else
TabOrderCompare := 0;
end
else if Assigned(focusControl1) then
TabOrderCompare := -1
else if Assigned(focusControl2) then
TabOrderCompare := 1
else
TabOrderCompare := 0;
end
else
TabOrderCompare := 0;
end;
procedure TVeridianApp.GetFocusList(AList: PObjectList; AControl: PControl);
var
control: PControl;
focusControl: PFocusControl;
index: integer;
result: PObjectList;
begin
if not Assigned(AList) then
AList := New(PObjectList, CreateSorted(TabOrderCompare));
for index := 0 to AControl^.Controls^.Count - 1 do begin
control := AControl^.Controls^.GetItem(index);
GetFocusList(AList, control);
if not control^.IsFocusControl then
continue;
focusControl := PFocusControl(control);
if focusControl^.IsVisibleAndEnabled and focusControl^.CanFocus then
AList^.Add(focusControl);
end;
end;
function TVeridianApp.FocusNext(AControl: PControl; AReverse: boolean): boolean;
var
parent: PControl;
current: PControl;
next: PFocusControl;
focusList: PObjectList;
controlIndex: integer;
currentIndex: integer;
begin
if not Assigned(ActiveControl) then
exit;
parent := AControl^.Parent;
current := parent;
while Assigned(current^.Parent) do
current := current^.Parent;
if not Assigned(current) then
exit;
focusList := New(PObjectList, CreateSorted(TabOrderCompare));
focusList^.DisposeObjects := false;
if Assigned(ActiveWindow) then
GetFocusList(focusList, ActiveWindow)
else
GetFocusList(focusList, Desktop);
controlIndex := focusList^.IndexOf(AControl);
if AReverse then begin
currentIndex := controlIndex - 1;
if currentIndex < 0 then
currentIndex := focusList^.Count - 1;
end
else begin
currentIndex := controlIndex + 1;
if currentIndex > focusList^.Count - 1 then
currentIndex := 0;
end;
if currentIndex <> controlIndex then begin
next := PFocusControl(focusList^.GetItem(currentIndex));
next^.Focus;
end;
FreeAndNil(focusList);
end;
function TVeridianApp.FocusFirst: boolean;
var
focusList: PControlList;
control: PControl;
begin
focusList := New(PControlList, CreateSorted(TabOrderCompare));
focusList^.DisposeObjects := false;
GetFocusList(focusList, Desktop);
if focusList^.Count >= 0 then begin
control := PControl(focusList^.GetItem(focusList^.Count - 1));
if Assigned(control) then
PFocusControl(control)^.Focus;
end;
FreeAndNil(focusList);
end;
function TVeridianApp.FocusLast: boolean;
var
focusList: PControlList;
control: PControl;
begin
focusList := New(PControlList, CreateSorted(TabOrderCompare));
focusList^.DisposeObjects := false;
GetFocusList(focusList, Desktop);
if focusList^.Count >= 0 then begin
control := PControl(focusList^.GetItem(0));
if Assigned(control) then
PFocusControl(control)^.Focus;
end;
FreeAndNil(focusList);
end;
procedure TVeridianApp.HandleSpecialKeys(AControl: PControl; var AEvent: TKeyEvent);
var
container: PMenuItemContainer;
begin
case AEvent.Key of
kyTab: begin
MenuManager.CloseAllMenus;
if Assigned(ActiveDropDown) then
ActiveDropDown^.HideList;
if Assigned(ActiveControl) then begin
if ActiveControl^.AcceptsTab or not ActiveControl^.CanFocus then
exit;
FocusNext(ActiveControl, true);
end
else begin
FocusFirst;
end;
AEvent.Handled := true;
exit;
end;
kyShiftTab: begin
MenuManager.CloseAllMenus;
if Assigned(ActiveDropDown) then
ActiveDropDown^.HideList;
if Assigned(ActiveControl) then begin
if ActiveControl^.AcceptsTab or not ActiveControl^.CanFocus then
exit;
FocusNext(ActiveControl, false);
end
else begin
FocusLast;
end;
AEvent.Handled := true;
exit;
end;
kyEsc: begin
Desktop^.BeginDrawing;
container := MenuManager.PopAndCloseMenu;
if Assigned(ActiveDropDown) then
ActiveDropDown^.HideList;
Desktop^.EndDrawing;
end;
end;
if AEvent.Handled then
exit;
if AControl^.IsActionControl then
HandleActionKey(PActionControl(AControl), AEvent);
end;
procedure TVeridianApp.HandleKeyEvent(AControl: PControl; var AEvent: TKeyEvent);
var
index: integer;
control: PControl;
controlEnabled: boolean;
begin
{$IFDEF debug}
if AEvent.Key = kyAltZ then begin
Close;
exit;
end;
{$ENDIF}
if Assigned(DragControl) then
exit;
if not Assigned(Desktop) then
exit;
if (AEvent.Key = kyAltF1) and not SwitchingWindows then begin
SwitchingWindows := true;
AEvent.Handled := true;
end;
if AEvent.Handled then
exit;
HandleSpecialKeys(AControl, AEvent);
if AEvent.Handled then
exit;
for index := AControl^.Controls^.Count - 1 downto 0 do begin
control := AControl^.Controls^.GetItem(index);
if not control^.IsVisible then
continue;
controlEnabled := control^.IsEnabled;
if controlEnabled then
HandleKeyEvent(control, AEvent);
if AEvent.Handled then
exit;
end;
if AEvent.Handled then
exit;
AEvent.Sender := AControl;
AControl^.KeyPress(AEvent);
end;
function TVeridianApp.DefaultWindowX: integer;
var
increment: integer;
begin
increment := 10;
if Graph^.Mode^.Width < 512 then
increment := 3;
if FNewWindowX > Graph^.Mode^.Width div 2 then
FNewWindowX := increment;
DefaultWindowX := FNewWindowX;
Inc(FNewWindowX, increment);
end;
function TVeridianApp.DefaultWindowY: integer;
var
increment: integer;
begin
increment := 10;
if Graph^.Mode^.Width < 512 then
increment := 3;
if FNewWindowY > Graph^.Mode^.Height div 2 then
FNewWindowY := 10;
if MenuBar^.IsVisible then
Inc(FNewWindowY, MenuBar^.Height);
DefaultWindowY := FNewWindowY;
Inc(FNewWindowY, increment);
end;
procedure TVeridianApp.CursorOn;
begin
if State.CursorOn then
exit;