-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathControls.pas
731 lines (647 loc) · 20.3 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
unit Controls;
{
LVCL - Very LIGHT VCL routines
------------------------------
Tiny replacement for the standard VCL Controls.pas
Just put the LVCL directory in your Project/Options/Path/SearchPath
and your .EXE will shrink from 300KB to 30KB
Notes:
- implements TControl+TCustomControl+TGraphicControl+TWinControl
- compatible with the standard .DFM files.
- only use existing properties in your DFM, otherwise you'll get error on startup
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
The Initial Developer of the Original Code is Arnaud Bouchez.
This work is Copyright (C) 2008 Arnaud Bouchez - http://bouchez.info
Emulates the original Delphi/Kylix Cross-Platform Runtime Library
(c)2000,2001 Borland Software Corporation
Portions created by Paul Toth are Copyright (C) 2001 Paul Toth. http://tothpaul.free.fr
All Rights Reserved.
Some modifications by Leonid Glazyrin, Feb 2012 <[email protected]>
* New TWinControl.Enabled property. Both Enabled and Visible loads from DFM
}
interface
uses
Windows, Messages, Classes, SysUtils, Graphics;
type
TShiftState = set of (ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble);
TMouseButton = (mbLeft, mbRight, mbMiddle);
TKeyPressEvent = procedure (Sender: TObject; var Key: Char) of object;
TKeyEvent = procedure (Sender: TObject; var Key: Word; Shift: TShiftState) of object;
TMouseEvent = procedure (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer) of object;
TControl = class(TComponent)
private
EOnClick: TNotifyEvent;
protected
procedure ReadProperty(const Name:string; Reader: TReader); override;
function FindMethod(Reader: TReader): TMethod;
public
Tag: integer;
property OnClick: TNotifyEvent read EOnClick write EOnClick;
end;
TWinControl = class;
TCustomControlClass = class of TCustomControl;
TCustomControl = class(TControl)
private
fParent: TWinControl;
fCanvas: TCanvas;
fFont: TFont;
fColor: integer;
fParentFont: boolean;
procedure SetVisible(const Value: boolean);
protected
EOnPaint: TNotifyEvent;
EOnShow: TNotifyEvent;
fCaption: string;
fLeft, fTop: integer;
fWidth, fHeight: integer;
fVisible,
fTransparent: boolean;
procedure ReadProperty(const Name: string; Reader: TReader); override;
function SubProperty(const Name: string): TPersistent; override;
function GetFont: TFont;
procedure SetFont(Value: TFont);
function GetCanvas: TCanvas;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; virtual;
procedure Invalidate;
function ClientRect: TRect; virtual;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: integer); virtual;
procedure Show; virtual;
procedure Hide; virtual;
property Font: TFont read GetFont write SetFont;
property Canvas: TCanvas read GetCanvas;
property Parent: TWinControl read fParent;
property Color: integer read fColor write fColor;
property Width: integer read fWidth;
property Height: integer read fHeight;
property Left: integer read fLeft;
property Top: integer read fTop;
property Transparent: boolean read fTransparent write fTransparent;
property Caption: string read fCaption;
property Visible: boolean read fVisible write SetVisible;
end;
TGraphicControl = class(TCustomControl)
protected
procedure SetParentComponent(Value: TComponent); override;
public
constructor Create(AOwner: TComponent); override;
end;
TControlStyle = set of (csAcceptsControl, csCaptureMouse, csClickEvents,
csFramed, csSetCaption, csOpaque, cdDoubleClicks);
TControlState = set of (csLButtonDown, csClicked, csPalette, csReadingState,
csAlignmentNeeded, csFocusing, csCreating, csPaintCopy, csCustomPaint,
csDestroyingHandle, csDocking);
TBorderStyle = (bsNone,bsSingle);
TWinControlClass = class of TWinControl;
TWinControl = class(TCustomControl)
private
fGraphics: TList;
fEnabled: Boolean;
procedure WMSize(var Msg: TWMSize); message wm_size;
procedure WMLButtonDown(var msg: TWMLButtonDown); message wm_lbuttondown;
procedure WMLButtonUp(var msg: TWMLButtonUp); message wm_lbuttonup;
procedure WMDblClick(var msg: TWMMouse); message WM_LBUTTONDBLCLK;
procedure WMRButtonDown(var msg: TWMMouse); message wm_rbuttondown;
procedure WMRButtonUp(var msg: TWMMouse); message wm_rbuttonup;
procedure WMEraseBkGnd(var msg: TWMEraseBkGnd); message wm_erasebkgnd;
procedure WMDestroy(var Msg: TWMDestroy); message wm_destroy;
procedure WMPaint(var Msg: TWMPaint); message wm_paint;
procedure WMChar(var Msg: TWMChar); message WM_CHAR;
procedure WMKeyDown(var Msg: TWMKey); message WM_KEYDOWN;
procedure WMKeyUp(var Msg: TWMKey); message WM_KEYUP;
procedure SetCaption(const Value: string);
function GetEnabled: boolean;
procedure SetEnabled(const Value: boolean);
public
procedure DefaultHandler(var Message); override;
protected
EOnKeyPress: TKeyPressEvent;
EOnKeyDown: TKeyEvent;
EOnKeyUp: TKeyEvent;
EOnMouseDown: TMouseEvent;
EOnMouseUp: TMouseEvent;
EOnDblClick: TNotifyEvent;
fHandle: THandle;
fOldProc: integer;
fTabOrder: integer;
fControlStyle: TControlStyle;
fControlState: TControlState;
fControls: TList;
procedure ReadProperty(const Name: string; Reader: TReader); override;
procedure SetParentComponent(Value: TComponent); override;
function GetParentComponent: TComponent; override;
procedure HandleNeeded;
procedure CreateHandle; virtual; abstract;
procedure SetHandle(Value: THandle);
procedure SetText(const Value: string); virtual;
procedure AddChild(AChild: TWinControl);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ClientRect: TRect; override;
procedure Paint; override;
procedure Show; override;
procedure Hide; override;
procedure SetFocus;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: integer); override;
property Handle: THandle read fHandle write SetHandle;
property Caption: string read fCaption write SetCaption;
property Enabled: boolean read GetEnabled write SetEnabled;
property Controls: TList read fControls;
property OnKeyPress: TKeyPressEvent read EOnKeyPress write EOnKeyPress;
property OnKeyDown: TKeyEvent read EOnKeyDown write EOnKeyDown;
property OnKeyUp: TKeyEvent read EOnKeyUp write EOnKeyUp;
property OnMouseDown: TMouseEvent read EOnMouseDown write EOnMouseDown;
property OnMouseUp: TMouseEvent read EOnMouseUp write EOnMouseUp;
property OnDblClick: TNotifyEvent read EOnDblClick write EOnDblClick;
end;
implementation
uses Forms;
function KeysToShiftState(Keys: Word): TShiftState;
begin
byte(Result) := 0;
if Keys and MK_SHIFT<>0 then Include(Result, ssShift);
if Keys and MK_CONTROL<>0 then Include(Result, ssCtrl);
if Keys and MK_LBUTTON<>0 then Include(Result, ssLeft);
if Keys and MK_RBUTTON<>0 then Include(Result, ssRight);
if Keys and MK_MBUTTON<>0 then Include(Result, ssMiddle);
if GetKeyState(VK_MENU) < 0 then Include(Result, ssAlt);
end;
function KeyDataToShiftState(KeyData: Longint): TShiftState;
const
AltMask = $20000000;
begin
byte(Result) := 0;
if GetKeyState(VK_SHIFT)<0 then Include(Result, ssShift);
if GetKeyState(VK_CONTROL)<0 then Include(Result, ssCtrl);
if KeyData and AltMask<>0 then Include(Result, ssAlt);
end;
function GetParentForm(Control: TCustomControl): TCustomForm;
begin
while Control.FParent<>nil do
Control := Control.Parent;
if Control.InheritsFrom(TCustomForm) then
Result := TCustomForm(Control) else
Result := nil;
end;
function WndProc(Hwnd,Msg,wParam,lParam: integer): integer; stdcall;
var obj: TObject;
dsp: TMessage;
begin
obj := TObject(GetWindowLong(HWnd,GWL_USERDATA)); // faster than GetProp()
if not Assigned(obj) then
result := DefWindowProc(HWnd,Msg,wParam,lParam) else begin
dsp.msg := msg;
dsp.wParam := WParam;
dsp.lParam := lParam;
dsp.result := 0;
obj.Dispatch(dsp);
result := dsp.result;
end;
end;
procedure TControl.ReadProperty(const Name: string; Reader:TReader);
const
TControlProperties:array[0..1] of PChar=(
'OnClick','Tag'
);
begin
case StringIndex(Name,TControlProperties) of
0 : TMethod(EOnClick) := FindMethod(Reader);
1 : Tag := Reader.IntegerProperty;
else inherited;
end;
end;
function TControl.FindMethod(Reader: TReader): TMethod;
var AComponent: TComponent;
Name: shortstring;
begin
if Reader.ReadValueType in [vaString,vaIdent] then begin
Name := Reader.ReadShortString;
AComponent := self;
while AComponent<>nil do begin
result.Data := AComponent;
result.Code := AComponent.MethodAddress(Name);
if result.Code<>nil then
exit;
AComponent := AComponent.Owner;
end;
end;
raise EClassesError.Create('method?');
end;
constructor TCustomControl.Create(AOwner: TComponent);
begin
inherited;
fParentFont := true; // default value
fVisible := true;
end;
destructor TCustomControl.Destroy;
begin
fFont.Free;
fCanvas.Free;
inherited;
end;
function TCustomControl.GetCanvas: TCanvas;
begin
if fCanvas=nil then
fCanvas := TCanvas.Create;
result := fCanvas;
end;
procedure TCustomControl.ReadProperty(const Name: string; Reader: TReader);
const
TWinControlProperties: array[0..10] of PChar=(
'Left','Top',
'Width','Height',
'Color',
'Transparent',
'Caption',
'OnPaint',
'ParentFont',
'OnShow',
'Visible'
);
begin
case StringIndex(Name,TWinControlProperties) of
0 : fLeft := Reader.IntegerProperty;
1 : fTop := Reader.IntegerProperty;
2 : fWidth := Reader.IntegerProperty;
3 : fHeight := Reader.IntegerProperty;
4 : fColor := Reader.ColorProperty;
5 : fTransparent := Reader.BooleanProperty;
6 : fCaption := Reader.StringProperty;
7 : TMethod(EOnPaint) := FindMethod(Reader);
8 : fParentFont := Reader.BooleanProperty;
9 : TMethod(EOnShow) := FindMethod(Reader);
10: fVisible := Reader.BooleanProperty;
else inherited;
end;
end;
function TCustomControl.SubProperty(const Name:string): TPersistent;
const
TControlSubProperties:array[0..0] of PChar=(
'Font'
);
begin
case StringIndex(Name,TControlSubProperties) of
0 : begin
if fFont=nil then
fFont := TFont.Create;
result := fFont;
end;
else result := nil;
end;
end;
function TCustomControl.GetFont: TFont;
begin
if fFont=nil then begin
if fParentFont and (Parent<>nil) then begin
result := Parent.Font;
exit;
end;
fFont := TFont.Create;
end;
result := fFont;
end;
procedure TCustomControl.SetFont(Value: TFont);
begin
fParentFont := false; // to create a custom font
Font.Assign(Value);
end;
procedure TCustomControl.Paint;
begin
if not fTransparent then
with Canvas do
if Assigned(EOnPaint) then EOnPaint(Self);
end;
function TCustomControl.ClientRect: TRect;
begin
result.Left := fLeft;
result.Right := result.Left+fWidth;
result.Top := fTop;
result.Bottom := result.Top+fHeight;
end;
procedure TCustomControl.SetBounds(ALeft, ATop, AWidth, AHeight: integer);
begin
fLeft := aLeft;
fTop := aTop;
fWidth := aWidth;
fHeight := aHeight;
end;
procedure TCustomControl.Invalidate;
var R: TRect;
begin
if Parent=nil then
exit;
R := ClientRect;
InvalidateRect(Parent.Handle,@R,false);
end;
constructor TGraphicControl.Create(AOwner: TComponent);
begin
inherited;
fVisible := true; // default value (TWinControl.Show expects fVisible=false)
end;
procedure TGraphicControl.SetParentComponent(Value: TComponent);
begin
while (Value<>nil) and not Value.InheritsFrom(TWinControl) do
Value := Value.ParentComponent;
if Value<>nil then begin
fParent := TWinControl(Value);
Font.Assign(fParent.Font);
fParent.fGraphics.Add(Self);
end;
end;
constructor TWinControl.Create(AOwner: TComponent);
begin
inherited;
fControls := TList.Create;
fGraphics := TList.Create;
fEnabled:= True;
end;
destructor TWinControl.Destroy;
begin
if fColor<>0 then
DeleteObject(fColor);
Handle := 0;
fControls.Free;
fGraphics.Free;
inherited;
end;
procedure TWinControl.ReadProperty(const Name:string; Reader:TReader);
const
TWinControlProperties:array[0..8] of PChar=(
'Text',
'TabOrder',
'OnKeyPress', 'OnKeyDown', 'OnKeyUp',
'OnMouseDown', 'OnMouseUp', 'OnDblClick',
'Enabled'
);
begin
case StringIndex(Name,TWinControlProperties) of
0 : SetText(Reader.StringProperty);
1 : fTabOrder := Reader.IntegerProperty;
2 : TMethod(EOnKeyPress) := FindMethod(Reader);
3 : TMethod(EOnKeyDown) := FindMethod(Reader);
4 : TMethod(EOnKeyUp) := FindMethod(Reader);
5 : TMethod(EOnMouseDown) := FindMethod(Reader);
6 : TMethod(EOnMouseUp) := FindMethod(Reader);
7 : TMethod(EOnDblClick) := FindMethod(Reader);
8 : Enabled := Reader.BooleanProperty;
else inherited;
end;
end;
procedure TWinControl.SetParentComponent(Value:TComponent);
begin
while (Value<>nil) and not(Value.InheritsFrom(TWinControl)) do
Value := Value.ParentComponent;
if Value<>nil then begin
fParent := TWinControl(Value);
Canvas.Font.Assign(fParent.Font);
fParent.AddChild(Self);
end;
end;
function TWinControl.GetParentComponent:TComponent;
begin
result := fParent;
end;
procedure TWinControl.HandleNeeded;
begin
if self=nil then exit;
if fParent<>nil then
fParent.HandleNeeded;
if fHandle=0 then
CreateHandle;
end;
procedure TWinControl.SetHandle(Value: THandle);
begin
if fHandle<>0 then begin
SetWindowLong(fHandle,GWL_WNDPROC,fOldProc);
DestroyWindow(fHandle);
end;
fHandle := Value;
if fHandle<>0 then begin
fOldProc := GetWindowLong(fHandle,GWL_WNDPROC);
SetWindowLong(fHandle,GWL_USERDATA,integer(self)); // faster than SetProp()
SetWindowLong(fHandle,GWL_WNDPROC,integer(@WndProc));
SendMessage(fHandle,WM_SETFONT,integer(Font.Handle),0);
SetEnabled(FEnabled);
end;
end;
procedure TWinControl.SetText(const Value:string);
begin
fCaption := Value;
end;
procedure TWinControl.AddChild(AChild:TWinControl);
begin
fControls.Add(AChild);
end;
procedure TWinControl.WMSize(var Msg: TWMSize);
begin
inherited;
fWidth := msg.Width;
fHeight := msg.Height;
end;
procedure TWinControl.WMLButtonDown(var msg: TWMLButtonDown);
begin
inherited;
Include(fControlState,csClicked);
if Assigned(EOnMouseDown) then
EOnMouseDown(Self, mbLeft, KeysToShiftState(msg.Keys), msg.XPos, msg.YPos);
end;
procedure TWinControl.WMLButtonUp(var msg: TWMLButtonUp);
begin
inherited;
if Assigned(EOnMouseUp) then
EOnMouseUp(Self, mbLeft, KeysToShiftState(msg.Keys), msg.XPos, msg.YPos);
//if csClicked in fControlState then begin
if Assigned(EOnClick) then
if (cardinal(msg.XPos)<=cardinal(fWidth)) and
(cardinal(msg.YPos)<=cardinal(fHeight)) then
EOnClick(Self);
Exclude(fControlState,csClicked);
//end;
end;
procedure TWinControl.WMDblClick(var msg: TWMMouse);
begin
inherited;
if Assigned(EOnDblClick) then
EOnDblClick(Self);
end;
procedure TWinControl.WMRButtonDown(var msg: TWMRButtonDown);
begin
inherited;
if Assigned(EOnMouseDown) then
EOnMouseDown(Self, mbRight, KeysToShiftState(msg.Keys), msg.XPos, msg.YPos);
end;
procedure TWinControl.WMRButtonUp(var msg: TWMRButtonUp);
begin
inherited;
if Assigned(EOnMouseUp) then
EOnMouseUp(Self, mbRight, KeysToShiftState(msg.Keys), msg.XPos, msg.YPos);
end;
procedure TWinControl.WMChar(var Msg: TWMChar);
var Key: Char; Form: TCustomForm;
begin
inherited;
Key := chr(Msg.CharCode);
Form := GetParentForm(Self);
if (Form<>nil) and (Form<>Self) and Form.KeyPreview and Assigned(Form.EOnKeyPress) then
begin
Form.EOnKeyPress(Self, Key);
if Key = #0 then Exit;
end;
if Assigned(EOnKeyPress) then
EOnKeyPress(Self, Key);
end;
procedure TWinControl.WMKeyDown(var Msg: TWMKey);
var Key: word; Shift: TShiftState; Form: TCustomForm;
begin
inherited;
Key := Msg.CharCode;
Shift := KeyDataToShiftState(Msg.KeyData);
Form := GetParentForm(Self);
if (Form<>nil) and (Form<>Self) and Form.KeyPreview and Assigned(Form.EOnKeyDown) then
begin
Form.EOnKeyDown(Self, Key, Shift);
if Key = 0 then Exit;
end;
if Assigned(EOnKeyDown) then
EOnKeyDown(Self, Key, Shift);
end;
procedure TWinControl.WMKeyUp(var Msg: TWMKey);
var Key: word; Shift: TShiftState; Form: TCustomForm;
begin
inherited;
Key := Msg.CharCode;
Shift := KeyDataToShiftState(Msg.KeyData);
Form := GetParentForm(Self);
if (Form<>nil) and (Form<>Self) and Form.KeyPreview and Assigned(Form.EOnKeyUp) then
begin
Form.EOnKeyUp(Self, Key, Shift);
if key = 0 then Exit;
end;
if Assigned(EOnKeyUp) then
EOnKeyUp(Self, Key, Shift);
end;
procedure TWinControl.WMEraseBkGnd(var msg: TWMEraseBkGnd);
begin
msg.result := 1;
if not fTransparent then
with Canvas do begin
Handle := Msg.DC;
Brush.Color := Self.Color;
FillRect(Rect(0,0,fWidth,fHeight));
end;
end;
procedure TWinControl.WMPaint(var Msg: TWMPaint);
begin
with Canvas do begin
Handle := Msg.DC;
if Handle=0 then
Handle := GetDC(self.fHandle);
Paint;
if Msg.DC=0 then
ReleaseDC(self.fHandle,Handle);
end;
inherited;
end;
procedure TWinControl.WMDestroy(var Msg: TWMDestroy);
begin
inherited;
PostQuitMessage(0);
end;
procedure TWinControl.DefaultHandler(var Message);
begin
with TMessage(Message) do
result := CallWindowProc(pointer(fOldProc),fHandle,Msg,wParam,lParam)
end;
procedure TWinControl.Paint;
var H, i: integer;
begin
inherited;
if fGraphics.Count=0 then exit;
H := Self.Canvas.Handle;
for i := 0 to fGraphics.Count-1 do
with TGraphicControl(fGraphics.List[i]) do begin
Canvas.Handle := H;
Paint;
end;
end;
procedure TWinControl.SetFocus;
begin
Windows.SetFocus(fHandle);
end;
procedure TWinControl.SetCaption(const Value: string);
begin
fCaption := Value;
if fHandle<>0 then
SendMessage(fHandle,WM_SETTEXT,0,integer(Value));
end;
procedure TWinControl.Hide;
begin
HandleNeeded;
fVisible := false;
ShowWindow(fHandle,SW_HIDE);
end;
procedure TWinControl.Show;
var i: integer;
begin
HandleNeeded;
for i := 0 to fControls.Count-1 do
with TWinControl(fControls.List[i]) do
if Visible then
Show;
ShowWindow(fHandle,SW_SHOW);
if Assigned(EOnShow) then
EOnShow(Self);
end;
function TWinControl.ClientRect: TRect;
begin
GetClientRect(Handle,result);
end;
procedure TWinControl.SetBounds(ALeft, ATop, AWidth, AHeight: integer);
begin
inherited;
MoveWindow(Handle,ALeft,Atop,AWidth,AHeight,false);
end;
function TWinControl.GetEnabled: boolean;
begin
if fHandle<>0 then // enabled by default
fEnabled := IsWindowEnabled(fHandle);
result := fEnabled;
end;
procedure TWinControl.SetEnabled(const Value: boolean);
begin
if GetEnabled = Value then Exit;
FEnabled := Value;
if fHandle<>0 then
begin
EnableWindow(fHandle, Value);
Invalidate; // necessary for Graphic controls
end;
end;
procedure TCustomControl.Hide;
begin
fVisible := false;
end;
procedure TCustomControl.Show;
begin
fVisible := true;
end;
procedure TCustomControl.SetVisible(const Value: boolean);
begin
if Value=fVisible then
exit;
fVisible := Value;
if Value then
Show else
Hide;
end;
end.