-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCONTROLS.PAS
2654 lines (2400 loc) · 66.9 KB
/
CONTROLS.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}
{
TODO:
TGroupBox
TImage
Taskbar menu
Alt-Tab
Window Arrangement
Screen edge snap
Undo
Redo
Edit menu options
Later:
TMemo?
}
unit Controls;
interface
uses
AplObj,
AplApps,
AplTypes,
AplConst,
Drawing,
MouseDrv,
Graphics,
GraphApp,
Lists,
Streams,
Actions,
KeyDrv,
Events,
VeriType,
VeriCons,
Colors;
type
PControl = ^TControl;
PControlList = ^TControlList;
PDesktopControlList = ^TDesktopControlList;
PButtonList = ^TButtonList;
PDesktop = ^TDesktop;
PCaptionControl = ^TCaptionControl;
PActionControl = ^TActionControl;
PFocusControl = ^TFocusControl;
PPopUp = ^TPopUp;
PLabel = ^TLabel;
PButton = ^TButton;
PPanel = ^TPanel;
PContentControl = ^TContentControl;
PTextControl = ^TTextControl;
PVisualControl = ^TVisualControl;
TControlPredicate = function(AItem: PControl): boolean;
TControlOption = (
coClipping,
coStayOnTop
);
TControlOptions = set of TControlOption;
TControlList = object(TIdentifiableList)
private
public
Owner: PControl;
constructor Create(AOwner: PControl);
function GetItemById(const AId: string): PControl;
function GetItem(AIndex: integer): PControl;
function Add(AItem: PControl): integer;
procedure SetItem(AIndex: integer; AItem: PControl);
procedure Insert(AIndex: integer; AItem: PControl);
procedure Init; virtual;
end;
TDesktopControlList = object(TControlList)
private
public
constructor Create(AOwner: PControl);
end;
TButtonList = object(TIdentifiableList)
private
public
function GetItemById(const AId: string): PButton;
function GetItem(AIndex: integer): PButton;
function Add(AItem: PButton): integer;
procedure SetItem(AIndex: integer; AItem: PButton);
procedure Insert(AIndex: integer; AItem: PButton);
end;
TControl = object(TEventObject)
private
procedure InternalPaintRegion(ARect: TRect; AExclude: PControl);
public
X, Y: integer;
Width, Height: integer;
MouseCursor: PMouseCursor;
Parent: PControl;
Controls: PControlList;
Align: TAlign;
Tag: integer;
Margins: TSpacing;
Padding: TSpacing;
{ Defines what the control's bounds are in relation to. Valid value are:
rpAbsolute - Bounds are relative to absolute screen coordinates.
rpParentClient - Bounds are relative to the parent's client area, usually
the area inside the parents's borders and bevels.
rpParentContent - Bounds are relative to the parent's content area,
usually the client area adjusted for additional parent controls such as
scroll bars. For views, this is the area that scrolls within the view.
This is the default value.
rpParentRelative - Bounds are relative to the parent's bounds, not
including any borders, bevels, padding or other controls. }
Position: TRelativePosition;
Visible: boolean;
Enabled: boolean;
OnKeyPress: PKeyEventProc;
OnMouseDown: PMouseEventProc;
OnMouseMove: PMouseEventProc;
OnMouseUp: PMouseEventProc;
OnMouseClick: PMouseEventProc;
OnMouseDoubleClick: PMouseEventProc;
OnMouseEnter: PMouseEventProc;
OnMouseLeave: PMouseEventProc;
OnMouseWheelChanged: PMouseEventProc;
OnDragStart: PMouseEventProc;
OnDragMove: PMouseEventProc;
OnDragEnd: PMouseEventProc;
OnEnter: PEventProc;
OnExit: PEventProc;
OnRun: PEventProc;
ControlOptions: TControlOptions;
destructor Free; virtual;
function BorderWidth: byte; virtual;
function BevelWidth: byte; virtual;
function OuterWidth: byte;
function SpacingWidth: integer;
function SpacingHeight: integer;
function CreateControlList: PControlList; virtual;
function GetSize: word;
function ScaleX(APercent: real): integer;
function ScaleY(APercent: real): integer;
function FindControl(const AId: string): PControl;
function ContainsControl(AControl: PControl): boolean;
function FindControlThat(AFunc: TControlPredicate): PControl;
function BringToFront: boolean;
function SendToBack: boolean;
function CanDrag(var AEvent: TMouseEvent): boolean; virtual;
function CanUndo: boolean;
function IsMouseOver: boolean;
function IsVisible: boolean;
function IsEnabled: boolean;
function IsVisibleAndEnabled: boolean;
function IsActionControl: boolean; virtual;
function IsFocusControl: boolean; virtual;
function IsView: boolean; virtual;
function IsWindow: boolean; virtual;
function IsDesktop: boolean; virtual;
function IsContentControl: boolean; virtual;
function IsTextControl: boolean; virtual;
function IsDialogButton: boolean; virtual;
function IsButton: boolean; virtual;
function IsVisualControl: boolean; virtual;
function IsTaskButton: boolean; virtual;
function IsMenuItemContainer: boolean; virtual;
function IsMenuItem: boolean; virtual;
function IsMainMenuItem: boolean; virtual;
function IsCheckBox: boolean; virtual;
function IsRadioButton: boolean; virtual;
{ Returns X position of the control's client area. This is usually the area
inside the control's borders, bevels, padding, etc. }
function ClientX: integer; virtual;
{ Returns Y position of the control's client area. This is usually the area
inside the control's borders, bevels, padding, etc. }
function ClientY: integer; virtual;
{ Returns width of the control's client area. This is usually the area
inside the control's borders, bevels, padding, etc. }
function ClientWidth: integer; virtual;
{ Returns height of the control's client area. This is usually the area
inside the control's borders, bevels, padding, etc. }
function ClientHeight: integer; virtual;
{ Returns X position of the control's content area. This is usually the
area inside the control's borders, bevels, padding, etc, adjusted for
other controls such as scroll bars. }
function ContentX: integer; virtual;
{ Returns Y position of the control's content area. This is usually the
area inside the control's borders, bevels, padding, etc, adjusted for
other controls such as scroll bars. }
function ContentY: integer; virtual;
{ Returns the X offset of the control's content area. For Views, this
is defined by the View's scroll position. }
function ContentOffsetX: integer; virtual;
{ Returns the Y offset of the control's content area. For Views, this
is defined by the View's scroll position. }
function ContentOffsetY: integer; virtual;
{ Returns width of the control's content area. This is usually the area
inside the control's borders, bevels, padding, etc, adjusted for other
controls such as scroll bars. }
function ContentWidth: integer; virtual;
{ Returns height of the control's content area. This is usually the area
inside the control's borders, bevels, padding, etc, adjusted for other
controls such as scroll bars. }
function ContentHeight: integer; virtual;
{ Returns the X position of the control in absolute screen coordinates. }
function ScreenX: integer;
{ Returns the Y position of the control in absolute screen coordinates. }
function ScreenY: integer;
{ Returns the X position of the control based on the control's Position
value. }
function CalculatedX: integer;
{ Returns the Y position of the control based on the control's Position
value. }
function CalculatedY: integer;
{ Gets a rectangle set to the control's X, Y, Width, and Height values. }
procedure GetBounds(var ARect: TRect);
{ Gets the bounds of the control based on the control's Position value. }
procedure GetCalculatedBounds(var ARect: TRect);
{ Gets the area defined as the client area of the control. This is usually
the area inside the control's borders, bevels, padding, etc. }
procedure GetClientRect(var ARect: TRect);
{ Gets the area defined as the content area of the control. This is usually
the client area adjusted for other parent controls such as scroll bars. }
procedure GetContentRect(var ARect: TRect);
{ Gets the content area of the control in absolute screen coordinates. }
procedure GetContentScreenRect(var ARect: TRect);
{ Gets the content area of the control in absolute screen coordinates,
adjusted by the control's ContentOffsetX and Y. For Views, the offsets
are set based on the View's scroll position. }
procedure GetContentDrawRect(var ARect: TRect);
{ Equivalent to GetClientRect in absolute screen coordinates. }
procedure GetClientScreenRect(var ARect: TRect);
{ Gets the area of the screen that the control occupies. }
procedure GetScreenBounds(var ARect: TRect);
{ Gets the clipping area of the control in screen coordinates. If clipping
is enabled in the control's ControlOptions, then the graphics viewport is
set to this value automatically in BeginDrawing. }
procedure GetClipRect(var ARect: TRect);
{ Gets the area of the screen that the control occupies, adjusted by the
control's ContentOffsetX and Y. This area is passed into the Paint method
when the control's Draw or DrawControl method is called, with the graphics
viewport set to the value of GetClipRect. }
procedure GetDrawRect(var ARect: TRect);
{ Adjusts the specified rectangle by a control's ContentOffsetX and Y, and
by the offsets of any parent controls that have a Position value of
rpParentContent. }
constructor Create(AId: string);
constructor CreateParent(AId: string; AParent: PControl);
procedure OffsetRect(AControl: PControl; var ARect: TRect);
procedure KeyPress(var AEvent: TKeyEvent); virtual;
procedure MouseDown(var AEvent: TMouseEvent); virtual;
procedure MouseUp(var AEvent: TMouseEvent); virtual;
procedure MouseMove(var AEvent: TMouseEvent); virtual;
procedure MouseEnter(var AEvent: TMouseEvent); virtual;
procedure MouseLeave(var AEvent: TMouseEvent); virtual;
procedure MouseClick(var AEvent: TMouseEvent); virtual;
procedure MouseDoubleClick(var AEvent: TMouseEvent); virtual;
procedure MouseWheelChanged(var AEvent: TMouseEvent); virtual;
procedure DragStart(var AEvent: TDragEvent); virtual;
procedure DragMove(var AEvent: TDragEvent); virtual;
procedure DragEnd(var AEvent: TDragEvent); virtual;
procedure Init; virtual;
procedure Layout; virtual;
procedure AlignControl;
procedure SetWidthHeight(AWidth, AHeight: word); virtual;
procedure SetWidth(AWidth: word); virtual;
procedure SetHeight(AHeight: word); virtual;
procedure SetBounds(APX, APY: integer; AWidth, AHeight: integer); virtual;
procedure SetBoundsRect(var ARect: TRect); virtual;
procedure SetSize(AWidth, AHeight: integer); virtual;
procedure SetXY(APX, APY: integer); virtual;
procedure SetEnabled(AEnabled: boolean); virtual;
procedure SetStayOnTop(AStayOnTop: boolean);
procedure DrawControl(ADrawControls: boolean); virtual;
procedure Draw; virtual;
procedure DrawSelf;
procedure DrawDoubleBuffered;
procedure DrawControls; virtual;
procedure Hide; virtual;
procedure HideEx(var AStart, AEnd: TRect); virtual;
procedure Show; virtual;
procedure Run; virtual;
procedure BeginDrawing; virtual;
procedure EndDrawing; virtual;
procedure Paint(ARect: TRect); virtual;
procedure PaintRegion(var ARect: TRect; AExclude: PControl); virtual;
end;
TVisualControl = object(TControl)
private
public
ForeColor: byte;
BackColor: byte;
FillPattern: PFillPattern;
LinePattern: PLinePattern;
Font: PFont;
function IsVisualControl: boolean; virtual;
procedure Init; virtual;
procedure SetForeColor(AForeColor: byte);
procedure SetBackColor(ABackColor: byte);
procedure SetFillPattern(AFillPattern: PFillPattern);
procedure SetLinePattern(ALinePattern: PLinePattern);
end;
TPanel = object(TVisualControl)
private
public
TransparentBack: boolean;
BorderColor: byte;
BorderStyle: TBorderStyle;
BevelStyle: TBevelStyle;
ShadowColor: byte;
LightColor: byte;
function BorderWidth: byte; virtual;
function BevelWidth: byte; virtual;
procedure Init; virtual;
procedure SetBorderColor(AColor: byte);
procedure SetBorderStyle(AStyle: TBorderStyle);
procedure Paint(ARect: TRect); virtual;
end;
TContentControl = object(TPanel)
private
public
HorzAlign: THorzAlign;
VertAlign: TVertAlign;
AutoSize: boolean;
function IsContentControl: boolean; virtual;
procedure GetAlign(var ABounds: TRect; var ASize: TSize;
var AResult: TPoint);
procedure Init; virtual;
procedure Layout; virtual;
procedure SetHorzAlign(AHorzAlign: THorzAlign);
procedure SetVertAlign(AVertAlign: TVertAlign);
procedure SetAutoSize(AAutoSize: boolean);
procedure SetXY(APX, APY: integer); virtual;
end;
TCaptionControl = object(TContentControl)
private
public
Caption: PChar;
Wrap: boolean;
constructor CreateCaption(const AId, ACaption: string; AParent: PControl);
function ContentHeight: integer; virtual;
function ContentWidth: integer; virtual;
procedure Init; virtual;
procedure Paint(ARect: TRect); virtual;
procedure SetCaption(ACaption: string);
procedure SetWrap(AWrap: boolean);
procedure GetTextAlign(var ABounds: TRect; var AResult: TPoint);
function TrueTextWidth(const AText: string): integer;
function GetCaption: string; virtual;
destructor Free; virtual;
end;
TActionControl = object(TCaptionControl)
private
public
Action: PAction;
ShowShortcut: boolean;
ShortcutDisplayName: PChar;
Shortcut: word;
ShortcutColor: byte;
ShortcutSpacing: integer;
DisabledColor, DisabledBackColor: byte;
constructor CreateId(AId: string; AAction: PAction);
constructor CreateParent(AId: string; AAction: PAction; AParent: PControl);
destructor Free; virtual;
procedure Init; virtual;
procedure Paint(ARect: TRect); virtual;
procedure Enable;
procedure Disable;
function ContentWidth: integer; virtual;
function ContentHeight: integer; virtual;
function GetAltHotKey: word; virtual;
function GetHotKey: word; virtual;
function IsActionControl: boolean; virtual;
function GetCaption: string; virtual;
function GetShortcut: word; virtual;
function GetShortcutDesc: string; virtual;
procedure SetAction(AAction: PAction);
procedure SetForeColorEnabled(AColor: byte);
end;
TDesktop = object(TActionControl)
private
public
ActionList: PActionList;
procedure Init; virtual;
procedure Layout; virtual;
function ContentX: integer; virtual;
function ContentY: integer; virtual;
function ContentWidth: integer; virtual;
function ContentHeight: integer; virtual;
function CreateControlList: PControlList; virtual;
function IsDesktop: boolean; virtual;
destructor Free; virtual;
end;
TFocusControl = object(TActionControl)
private
FCursorX: integer;
FCursorY: integer;
public
UsesCursor: boolean;
AcceptsTab: boolean;
AcceptsEnter: boolean;
FocusedColor, FocusedBackColor: byte;
FocusRectColor: byte;
FocusRectWidth: byte;
CanFocus: boolean;
TabOrder: integer;
constructor CreateId(AId: string);
constructor CreateParent(AId: string; AParent: PControl);
function CursorX: integer;
function CursorY: integer;
function Focused: boolean;
function IsFocusControl: boolean; virtual;
procedure Init; virtual;
procedure Focus; virtual;
procedure UnFocus; virtual;
procedure SetFocus(AFocus, ARedraw: boolean); virtual;
procedure MouseDown(var AEvent: TMouseEvent); virtual;
procedure Paint(ARect: TRect); virtual;
end;
TPopUp = object(TPanel)
private
FBackBuffer: PMemoryStream;
public
procedure Init; virtual;
procedure Show; virtual;
procedure Hide; virtual;
destructor Free; virtual;
end;
TLabel = Object(TCaptionControl)
private
public
procedure Init; virtual;
procedure Paint(ARect: TRect); virtual;
procedure Clear; virtual;
procedure Layout; virtual;
destructor Free; virtual;
end;
TButton = object(TFocusControl)
private
public
Down: boolean;
Toggle: boolean;
DownBackColor: byte;
HighlightColor: byte;
Clickable: boolean;
function IsButton: boolean; virtual;
procedure Init; virtual;
procedure Paint(ARect: TRect); virtual;
procedure Draw; virtual;
procedure MouseDown(var AEvent: TMouseEvent); virtual;
procedure MouseClick(var AEvent: TMouseEvent); virtual;
procedure MouseEnter(var AEvent: TMouseEvent); virtual;
procedure MouseLeave(var AEvent: TMouseEvent); virtual;
end;
TTextControl = object(TFocusControl)
private
public
Text: PChar;
TextAlign: THorzAlign;
HighlightColor: byte;
TextOffsetX: shortint;
TextOffsetY: shortint;
constructor CreateText(const AId, AText: string; AParent: PControl);
destructor Free; virtual;
function GetText: string; virtual;
function GetCursorForeColor: byte; virtual;
function GetCursorBackColor: byte; virtual;
function IsTextControl: boolean; virtual;
procedure GetCursorRect(var ARect: TRect); virtual;
procedure Init; virtual;
procedure SetText(const AText: string); virtual;
procedure Paint(ARect: TRect); virtual;
end;
var
Desktop: PDesktop;
implementation
uses
AplStr,
AplUtils,
Veridian,
Gr8Drv,
Strings;
function TControl.IsVisualControl: boolean;
begin
IsVisualControl := false;
end;
function TControl.IsMenuItemContainer: boolean;
begin
IsMenuItemContainer := false;
end;
function TControl.IsMenuItem: boolean;
begin
IsMenuItem := false;
end;
function TControl.IsMainMenuItem: boolean;
begin
IsMainMenuItem := false;
end;
function TControl.IsCheckBox: boolean;
begin
IsCheckBox := false;
end;
function TControl.IsRadioButton: boolean;
begin
IsRadioButton := false;
end;
function TControl.IsTaskButton: boolean;
begin
IsTaskButton := false;
end;
function TControl.IsButton: boolean;
begin
IsButton := false;
end;
function TControl.IsActionControl: boolean;
begin
IsActionControl := false;
end;
function TControl.IsFocusControl: boolean;
begin
IsFocusControl := false;
end;
function TControl.IsTextControl: boolean;
begin
IsTextControl := false;
end;
function TControl.IsDialogButton: boolean;
begin
IsDialogButton := false;
end;
function TControl.IsView: boolean;
begin
IsView := false;
end;
function TControl.IsWindow: boolean;
begin
IsWindow := false;
end;
function TControl.IsDesktop: boolean;
begin
IsDesktop := false;
end;
function TControl.IsContentControl: boolean;
begin
IsContentControl := false;
end;
constructor TControl.Create(AId: string);
begin
inherited CreateId(AId);
end;
constructor TControl.CreateParent(AId: string; AParent: PControl);
begin
inherited CreateId(AId);
Parent := AParent;
if Assigned(Parent) then
AParent^.Controls^.Add(@self);
end;
procedure TControl.OffsetRect(AControl: PControl; var ARect: TRect);
begin
if Assigned(AControl^.Parent) then begin
if AControl^.Position = rpParentContent then
ARect.Translate(AControl^.Parent^.ContentOffsetX, AControl^.Parent^.ContentOffsetY);
OffsetRect(AControl^.Parent, ARect);
end;
end;
function TControl.IsMouseOver: boolean;
begin
IsMouseOver := VeridianApp^.MouseOverControl = @self;
end;
function TControl.IsEnabled: boolean;
var
parentControl: PControl;
result: boolean;
function ControlEnabled(AControl: PControl): boolean;
var
actionControl: PActionControl;
begin
ControlEnabled := AControl^.Enabled;
if not AControl^.IsActionControl then
exit;
actionControl := PActionControl(AControl);
if Assigned(actionControl^.Action) then
ControlEnabled := actionControl^.Action^.Enabled;
end;
begin
IsEnabled := false;
result := ControlEnabled(@self);
if result and (VeridianApp^.ActiveDialog = @self) then begin
IsEnabled := true;
exit;
end;
parentControl := Parent;
while Assigned(parentControl) do begin
if Assigned(VeridianApp^.ActiveDialog) and (parentControl = PControl(VeridianApp^.ActiveDialog)) then
break;
if not ControlEnabled(parentControl) then begin
result := false;
break;
end;
parentControl := parentControl^.Parent;
end;
IsEnabled := result;
end;
function TControl.IsVisibleAndEnabled: boolean;
begin
IsVisibleAndEnabled := IsVisible and IsEnabled;
end;
function TControl.IsVisible: boolean;
var
par: PControl;
begin
IsVisible := Visible;
if not Visible then
exit;
par := Parent;
while Assigned(par) do begin
if not par^.Visible then begin
IsVisible := false;
exit;
end;
par := par^.Parent;
end;
end;
function TControl.CanDrag(var AEvent: TMouseEvent): boolean;
begin
CanDrag := false;
end;
function TControl.CanUndo: boolean;
begin
CanUndo := false;
end;
function TControl.ContentX: integer;
var
result: integer;
begin
result := ClientX;
ContentX := result;
end;
function TControl.ContentY: integer;
var
result: integer;
begin
result := ClientY;
ContentY := result;
end;
function TControl.ContentWidth: integer;
begin
ContentWidth := ClientWidth;
end;
function TControl.ContentHeight: integer;
begin
ContentHeight := ClientHeight;
end;
procedure TControl.GetBounds(var ARect: TRect);
begin
ARect.CreateDims(X, Y, Width, Height);
end;
procedure TControl.GetCalculatedBounds(var ARect: TRect);
begin
ARect.CreateDims(CalculatedX, CalculatedY, Width, Height);
end;
procedure TControl.GetClientRect(var ARect: TRect);
begin
ARect.CreateDims(ClientX, ClientY, ClientWidth, ClientHeight);
end;
procedure TControl.GetContentRect(var ARect: TRect);
begin
ARect.CreateDims(ContentX, ContentY, ContentWidth, ContentHeight);
end;
procedure TControl.GetContentScreenRect(var ARect: TRect);
begin
GetContentRect(ARect);
ARect.Translate(ScreenX, ScreenY);
end;
procedure TControl.GetClientScreenRect(var ARect: TRect);
begin
GetClientRect(ARect);
ARect.Translate(ScreenX, ScreenY);
end;
function TControl.ScreenX: integer;
var
result: integer;
begin
result := CalculatedX;
ScreenX := result;
if Position = rpAbsolute then
exit;
if not Assigned(Parent) then
exit;
Inc(result, Parent^.ScreenX);
ScreenX := result;
end;
function TControl.ScreenY: integer;
var
result: integer;
begin
result := CalculatedY;
ScreenY := result;
if Position = rpAbsolute then
exit;
if not Assigned(Parent) then
exit;
Inc(result, Parent^.ScreenY);
ScreenY := result;
end;
function TControl.ContentOffsetX: integer;
begin
ContentOffsetX := 0;
end;
function TControl.ContentOffsetY: integer;
begin
ContentOffsetY := 0;
end;
procedure TControl.GetScreenBounds(var ARect: TRect);
begin
ARect.CreateDims(ScreenX, ScreenY, Width, Height);
end;
procedure TControl.GetContentDrawRect(var ARect: TRect);
begin
GetContentScreenRect(ARect);
OffsetRect(@self, ARect);
end;
procedure TControl.GetDrawRect(var ARect: TRect);
begin
GetScreenBounds(ARect);
OffsetRect(@self, ARect);
end;
procedure TControl.GetClipRect(var ARect: TRect);
var
parentRect: TRect;
par: PControl;
current: PControl;
begin
GetDrawRect(ARect);
if not Assigned(Parent) then
exit;
case Position of
rpParentContent: Parent^.GetContentScreenRect(parentRect);
rpParentClient: Parent^.GetClientScreenRect(parentRect);
rpParentRelative: Parent^.GetScreenBounds(parentRect);
rpAbsolute: exit;
end;
Parent^.OffsetRect(Parent, parentRect);
ARect.Intersect(parentRect);
par := Parent;
while Assigned(par) do begin
par^.GetClipRect(parentRect);
ARect.Intersect(parentRect);
if par^.Position = rpAbsolute then
break;
par := par^.Parent;
end;
end;
procedure TControl.Init;
begin
inherited Init;
Parent := nil;
Controls := CreateControlList;
X := 0;
Y := 0;
Width := 0;
Height := 0;
Include(ControlOptions, coClipping);
Visible := true;
Enabled := true;
Align := alNone;
Position := rpParentContent;
Margins.Create;
Padding.Create;
Tag := 0;
ControlOptions := [coClipping];
OnDragEnd := nil;
OnDragMove := nil;
OnDragStart := nil;
OnEnter := nil;
OnExit := nil;
OnKeyPress := nil;
OnMouseDown := nil;
OnMouseMove := nil;
OnMouseUp := nil;
OnMouseDown := nil;
OnMouseClick := nil;
OnMouseDoubleClick := nil;
OnMouseEnter := nil;
OnMouseLeave := nil;
OnMouseWheelChanged := nil;
OnEnter := nil;
OnExit := nil;
OnRun := nil;
MouseCursor := VeridianApp^.MouseCursors^.GetItemById('Default');
end;
function TControl.CreateControlList: PControlList;
begin
CreateControlList := New(PControlList, Create(@Self));
end;
procedure TControl.SetWidthHeight(AWidth, AHeight: word);
begin
Width := AWidth;
Height := AHeight;
Draw;
end;
procedure TControl.SetWidth(AWidth: word);
begin
Width := AWidth;
Draw;
end;
procedure TControl.SetHeight(AHeight: word);
begin
Height := AHeight;
Draw;
end;
procedure TControl.Hide;
var
rect, empty: TRect;
begin
GetDrawRect(rect);
empty.Create;
HideEx(rect, empty);
end;
{ Hides only areas that are not intersected by AStart and AEnd. }
procedure TControl.HideEx(var AStart, AEnd: TRect);
var
partialRect, rect: TRect;
var sx, sy, ex, ey: integer;
var sw, sh, ew, eh: integer;
var sr, sb, er, eb: integer;
begin
if not IsVisible then
exit;
Visible := false;
if not Assigned(Parent) then
exit;
Desktop^.BeginDrawing;
VeridianApp^.CursorOff;
sx := AStart.X; sy := AStart.Y; ex := AEnd.X; ey := AEnd.Y;
sw := AStart.Width; sh := AStart.Height; ew := AEnd.Width; eh := AEnd.Height;
sr := AStart.Right; sb := AStart.Bottom; er := AEnd.Right; eb := AEnd.Bottom;
if not AStart.IntersectsRect(AEnd) then
Desktop^.PaintRegion(AStart, @self)
else begin
if (sw = ew) and (sh = eh) then begin
{ Moved }
if (ex >= sx) and (ey >= sy) then begin
{ Increased X and Y }
partialRect.CreateDims(sx, sy, sw, ey - sy);
Desktop^.PaintRegion(partialRect, @self);
partialRect.SetDims(sx, ey, ex - sx, sh);
Desktop^.PaintRegion(partialRect, @self);
end
else if (ex <= sx) and (ey <= sy) then begin
{ Decreased X and Y }
partialRect.CreateDims(er + 1, sy, sx - ex, sh);
Desktop^.PaintRegion(partialRect, @self);
partialRect.SetDims(sx, eb + 1, sw, sy - ey + 1);
Desktop^.PaintRegion(partialRect, @self);
end
else if (ex >= sx) and (ey <= sy) then begin
{ Increased X and Decreased Y }
partialRect.CreateDims(sx, eb + 1, sw, sy - ey);
Desktop^.PaintRegion(partialRect, @self);
partialRect.SetDims(sx, sy, ex - sx, sh - ey + sy);
Desktop^.PaintRegion(partialRect, @self);
end
else if (ex <= sx) and (ey >= sy) then begin
{ Decreased X and Increased Y }
partialRect.CreateDims(sx, sy, sw, ey - sy);
Desktop^.PaintRegion(partialRect, @self);
partialRect.SetDims(er + 1, sy, sx - ex, sh);
Desktop^.PaintRegion(partialRect, @self);
end;
end
else if (sx = ex) and (sy = ey) then begin
{ Resized Right, Bottom Right, or Bottom }
if (ew < sw) and (eh < sh) then begin
{ Decreased Width and Height }
partialRect.CreateDims(er + 1, sy, sr - er, sh);
Desktop^.PaintRegion(partialRect, @self);
partialRect.SetDims(sx, eb + 1, sw - (sw - ew), sh - eh);
Desktop^.PaintRegion(partialRect, @self);
end
else if (ew < sw) then begin
{ Decreased Width }
partialRect.CreateDims(er + 1, sy, sr - er, sh);
Desktop^.PaintRegion(partialRect, @self);
end
else if (eh < sh) then begin
{ Decreased Height }
partialRect.CreateDims(sx, eb + 1, sw, sb - eb);
Desktop^.PaintRegion(partialRect, @self);
end
end
else begin
{ Resized remaining cases }
if ex > sx then begin
{ Resized left, top left, or bottom left }
if (ey = sy) and (sh = eh) then begin
{ Resized Left }
partialRect.CreateDims(sx, sy, ex - sx, sh);
Desktop^.PaintRegion(partialRect, @self);
end
else if ey > sy then begin
{ Resized Top Left }
partialRect.CreateDims(sx, sy, sw, ey - sy);
Desktop^.PaintRegion(partialRect, @self);
partialRect.SetDims(sx, sy + (ey - sy), ex - sx, eh);
Desktop^.PaintRegion(partialRect, @self);
end
else if eb < sb then begin
{ Resized Bottom Left }
partialRect.CreateDims(sx, sy, ex - sx, sh);
Desktop^.PaintRegion(partialRect, @self);
partialRect.SetDims(ex, eb + 1, ew, sb - eb);
Desktop^.PaintRegion(partialRect, @self);
end
end
else if ex = sx then begin
if (ey > sy) and (er < sr) then begin
{ Resized Top Right }
partialRect.CreateDims(sx, sy, sw, ey - sy);
Desktop^.PaintRegion(partialRect, @self);
partialRect.SetDims(er + 1, ey, sr - er, sh - (ey - sy));
Desktop^.PaintRegion(partialRect, @self);
end
else begin