-
Notifications
You must be signed in to change notification settings - Fork 1
/
caControls.pas
1412 lines (1243 loc) · 37.5 KB
/
caControls.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
unit caControls;
{$INCLUDE ca.inc}
interface
uses
// Standard Delphi units
Windows,
Classes,
Messages,
Controls,
Sysutils,
Graphics,
Forms,
StdCtrls,
ExtCtrls,
Dialogs,
// ca units
caUtils,
caTypes,
caClasses,
caFrame;
type
TcaPaintEvent = procedure(Sender: TObject; ACanvas: TCanvas; ARect: TRect) of object;
TcaClickOutsideEvent = procedure(Sender: TObject; AClickedControl: TControl) of object;
//---------------------------------------------------------------------------
// IcaComponentFactory
//---------------------------------------------------------------------------
IcaComponentFactory = interface
['{3D7E850A-B6DD-4B60-9722-5456A12FF94D}']
function GetComponentClass: TComponentClass;
function GetComponentOwner: TComponent;
function GetNextComponentName: String;
function NewComponent: TComponent;
procedure SetComponentClass(const Value: TComponentClass);
procedure SetComponentOwner(const Value: TComponent);
property ComponentClass: TComponentClass read GetComponentClass write SetComponentClass;
property ComponentOwner: TComponent read GetComponentOwner write SetComponentOwner;
end;
//---------------------------------------------------------------------------
// TcaComponentFactory
//---------------------------------------------------------------------------
TcaComponentFactory = class(TInterfacedObject, IcaComponentFactory)
private
FComponentClass: TComponentClass;
FComponentOwner: TComponent;
function GetComponentClass: TComponentClass;
function GetComponentOwner: TComponent;
procedure SetComponentClass(const Value: TComponentClass);
procedure SetComponentOwner(const Value: TComponent);
public
constructor Create(AClass: TComponentClass; AOwner: TComponent); overload;
function GetNextComponentName: String;
property ComponentClass: TComponentClass read GetComponentClass write SetComponentClass;
function NewComponent: TComponent;
end;
//---------------------------------------------------------------------------
// IcaMargin
//---------------------------------------------------------------------------
IcaMargin = interface
['{2E99C170-05EE-40A0-A074-BA4F485551C8}']
// Property methods
function GetBottom: Integer;
function GetLeft: Integer;
function GetOnChanged: TNotifyEvent;
function GetRight: Integer;
function GetTop: Integer;
procedure SetBottom(const Value: Integer);
procedure SetLeft(const Value: Integer);
procedure SetOnChanged(const Value: TNotifyEvent);
procedure SetRight(const Value: Integer);
procedure SetTop(const Value: Integer);
// Properties
property Bottom: Integer read GetBottom write SetBottom;
property Left: Integer read GetLeft write SetLeft;
property OnChanged: TNotifyEvent read GetOnChanged write SetOnChanged;
property Right: Integer read GetRight write SetRight;
property Top: Integer read GetTop write SetTop;
end;
//---------------------------------------------------------------------------
// TcaMargin
//---------------------------------------------------------------------------
TcaMargin = class(TcaInterfacedPersistent, IcaMargin)
private
FBottom: Integer;
FLeft: Integer;
FOnChanged: TNotifyEvent;
FRight: Integer;
FTop: Integer;
FUpdateCount: Integer;
function GetBottom: Integer;
function GetLeft: Integer;
function GetOnChanged: TNotifyEvent;
function GetRight: Integer;
function GetTop: Integer;
procedure Changed;
procedure SetBottom(const Value: Integer);
procedure SetLeft(const Value: Integer);
procedure SetOnChanged(const Value: TNotifyEvent);
procedure SetRight(const Value: Integer);
procedure SetTop(const Value: Integer);
protected
procedure DoChanged; virtual;
public
procedure Assign(Source: TPersistent); override;
procedure BeginUpdate;
procedure EndUpdate;
published
property Bottom: Integer read GetBottom write SetBottom;
property Left: Integer read GetLeft write SetLeft;
property OnChanged: TNotifyEvent read GetOnChanged write SetOnChanged;
property Right: Integer read GetRight write SetRight;
property Top: Integer read GetTop write SetTop;
end;
//---------------------------------------------------------------------------
// IcaCustomPanel
//---------------------------------------------------------------------------
IcaCustomPanel = interface
['{EB2CD5CD-954A-46B3-A009-614FB67923E8}']
// Property methods
function GetTransparent: Boolean;
procedure SetTransparent(const Value: Boolean);
// Properties
property Transparent: Boolean read GetTransparent write SetTransparent;
end;
//---------------------------------------------------------------------------
// TcaCustomPanel
//---------------------------------------------------------------------------
TcaCustomPanel = class(TCustomPanel, IcaCustomPanel, IcaFrame)
private
// Private fields
FDefaultWindowProc: TWndMethod;
FFrame: TcaFrameProperties;
FFrameImpl: IcaFrame;
FOffScreenBitmap: TBitmap;
FOnClickOutside: TcaClickOutsideEvent;
FOnMouseEnter: TNotifyEvent;
FOnMouseLeave: TNotifyEvent;
FSubClassForm: Boolean;
FTransparent: Boolean;
// Property methods
function GetTransparent: Boolean;
procedure SetSubClassForm(const Value: Boolean);
procedure SetTransparent(const Value: Boolean);
// Private methods
procedure CreateFrameObjects;
procedure CreateOffScreenBitmap;
procedure FreeFrameObjects;
procedure FreeOffScreenBitmap;
procedure HookWindowProc(var Message: TMessage);
procedure ReplaceWindowProc;
procedure RestoreWindowProc;
// Component mesage handlers
procedure CMCancelMode(var Message: TCMCancelMode); message CM_CANCELMODE;
procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
procedure CMMouseenter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseleave(var Message: TMessage); message CM_MOUSELEAVE;
protected
// Protected methods
function GetOffScreenCanvas: TCanvas;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DoClickOutside(AClickedControl: TControl); virtual;
procedure DoHookWindowProc(var Message: TMessage); virtual;
procedure DoMouseEnter; virtual;
procedure DoMouseLeave; virtual;
procedure Paint; override;
procedure UpdateOffScreenBitmap;
procedure UpdateOnScreenBitmap;
// Protected properties
property Frame: TcaFrameProperties read FFrame write FFrame;
property FrameImpl: IcaFrame read FFrameImpl implements IcaFrame;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
property SubClassForm: Boolean read FSubClassForm write SetSubClassForm;
property Transparent: Boolean read GetTransparent write SetTransparent;
// Protected event properties
property OnClickOutside: TcaClickOutsideEvent read FOnClickOutside write FOnClickOutside;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
//---------------------------------------------------------------------------
// TcaPanel
//---------------------------------------------------------------------------
TcaPanel = class(TcaCustomPanel)
public
// TCustomPanel
property DockManager;
published
// TcaCustomPanel
property Frame;
property SubClassForm;
property Transparent;
// Event properties
property OnClickOutside;
// TCustomPanel
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BiDiMode;
property BorderWidth;
property BorderStyle;
property Caption;
property Color;
property Constraints;
property Ctl3D;
property UseDockManager default True;
property DockSite;
property DoubleBuffered;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Font;
property Locked;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
// Event properties
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDblClick;
property OnDockDrop;
property OnDockOver;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
end;
//---------------------------------------------------------------------------
// TcaFormPanel
//---------------------------------------------------------------------------
TcaFormCreateEvent = procedure(Sender: TObject; var AForm: TForm) of object;
TcaFormShowEvent = procedure(Sender: TObject; AForm: TForm) of object;
TcaCustomFormPanel = class(TcaPanel)
private
// Private fields
FForm: TForm;
// Event property fields
FOnBeforeShowForm: TcaFormShowEvent;
FOnCreateForm: TcaFormCreateEvent;
// Private methods
procedure UpdateChildForm;
protected
// Protected methods
procedure CreateWnd; override;
procedure DoCreateForm(var AForm: TForm); virtual;
procedure DoBeforeShowForm(AForm: TForm); virtual;
// Event properties
property OnCreateForm: TcaFormCreateEvent read FOnCreateForm write FOnCreateForm;
property OnBeforeShowForm: TcaFormShowEvent read FOnBeforeShowForm write FOnBeforeShowForm;
public
// Public methods
procedure CreateChildForm(AForm: TForm); overload;
procedure CreateChildForm(AFormClass: TFormClass); overload;
end;
//```````````````````````````````````````````````````````````````````````````
// TcaFormPanel
//```````````````````````````````````````````````````````````````````````````
TcaFormPanel = class(TcaCustomFormPanel)
published
// TcaCustomFormPanel event properties
property OnCreateForm;
// Promoted properties
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BiDiMode;
property BorderWidth;
property BorderStyle;
// property Caption;
property Color;
property Constraints;
property Ctl3D;
property UseDockManager default True;
property DockSite;
property DoubleBuffered;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Font;
property Locked;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
// Event properties
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDblClick;
property OnDockDrop;
property OnDockOver;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
end;
//---------------------------------------------------------------------------
// IcaGraphicControl
//---------------------------------------------------------------------------
IcaGraphicControl = interface
['{52F8AC8E-BCB3-4088-BF18-6EAC25F2B316}']
function GetCanvas: TCanvas;
function GetMouseIsDown: Boolean;
function GetMouseIsOver: Boolean;
function GetOnPaint: TcaPaintEvent;
procedure Paint;
procedure SetOnPaint(const Value: TcaPaintEvent);
property Canvas: TCanvas read GetCanvas;
property MouseIsDown: Boolean read GetMouseIsDown;
property MouseIsOver: Boolean read GetMouseIsOver;
property OnPaint: TcaPaintEvent read GetOnPaint write SetOnPaint;
end;
//---------------------------------------------------------------------------
// TcaGraphicControl
//---------------------------------------------------------------------------
TcaGraphicControl = class(TControl, IcaGraphicControl)
private
// Private fields
FAutoSizeMargin: Integer;
FCanvas: TCanvas;
FMouseIsDown: Boolean;
FMouseIsOver: Boolean;
FOffScreenBitmap: TBitmap;
FOnPaint: TcaPaintEvent;
FUpdateCount: Integer;
// Property methods
function GetCanvas: TCanvas;
function GetMouseIsDown: Boolean;
function GetMouseIsOver: Boolean;
function GetOnPaint: TcaPaintEvent;
procedure SetAutoSizeMargin(const Value: Integer);
procedure SetOnPaint(const Value: TcaPaintEvent);
// Component message handlers
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
// Windows message handlers
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
protected
// Protected methods
function GetAdjustSizeDelta: Integer; virtual;
function GetOffScreenCanvas: TCanvas;
procedure AdjustSize; override;
procedure BufferedPaint(C: TCanvas; R: TRect); virtual;
procedure DoMouseEnter; virtual;
procedure DoMouseLeave; virtual;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure Paint; virtual;
procedure RequestPaint; virtual;
procedure UpdateOnScreenBitmap;
// Protected properties
property AutoSizeMargin: Integer read FAutoSizeMargin write SetAutoSizeMargin;
property Canvas: TCanvas read GetCanvas;
property MouseIsDown: Boolean read GetMouseIsDown;
property MouseIsOver: Boolean read GetMouseIsOver;
property OffScreenCanvas: TCanvas read GetOffScreenCanvas;
property OnPaint: TcaPaintEvent read GetOnPaint write SetOnPaint;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
// Public methods
procedure BeginUpdate;
procedure EndUpdate;
end;
//---------------------------------------------------------------------------
// TcaXPGraphicControl
//---------------------------------------------------------------------------
TcaXPGraphicControl = class(TcaGraphicControl)
private
protected
public
end;
//---------------------------------------------------------------------------
// IcaSpacer
//---------------------------------------------------------------------------
IcaSpacer = interface
['{18414C8C-B37A-4111-8881-03B9F4C8088B}']
// Property methods
function GetGrooved: Boolean;
procedure SetGrooved(const Value: Boolean);
// Properties
property Grooved: Boolean read GetGrooved write SetGrooved;
end;
//---------------------------------------------------------------------------
// TcaSpacer
//---------------------------------------------------------------------------
TcaSpacer = class(TcaGraphicControl, IcaSpacer)
private
FGrooved: Boolean;
// Property methods
function GetGrooved: Boolean;
procedure SetGrooved(const Value: Boolean);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
published
// Properties
property Align;
property Grooved: Boolean read GetGrooved write SetGrooved;
property Width default 8;
property Height default 25;
end;
//---------------------------------------------------------------------------
// TcaSplitter
//---------------------------------------------------------------------------
TcaSplitter = class(TSplitter)
private
// Private fields
FPosition: Integer;
// Property methods
function GetPosition: Integer;
procedure SetPosition(const Value: Integer);
// Private methods
function FindControl: TControl;
procedure UpdateControlSize;
procedure UpdatePosition;
published
property Position: Integer read GetPosition write SetPosition;
end;
//---------------------------------------------------------------------------
// TcaMemo
//---------------------------------------------------------------------------
TcaMemo = class(TMemo)
published
property Action;
end;
//---------------------------------------------------------------------------
// IcaGraphicBox
//---------------------------------------------------------------------------
IcaGraphicBox = interface
['{E1D58E76-1FDA-41E5-906E-24060574BE6C}']
// Property methods
function GetColor: TColor;
function GetFrameColor: TColor;
function GetFrameWidth: Integer;
procedure SetColor(const Value: TColor);
procedure SetFrameColor(const Value: TColor);
procedure SetFrameWidth(const Value: Integer);
// Properties
property Color: TColor read GetColor write SetColor;
property FrameColor: TColor read GetFrameColor write SetFrameColor;
property FrameWidth: Integer read GetFrameWidth write SetFrameWidth;
end;
//---------------------------------------------------------------------------
// TcaGraphicBox
//---------------------------------------------------------------------------
TcaGraphicBox = class(TcaGraphicControl, IcaGraphicBox)
private
// Property fields
FColor: TColor;
FFrameColor: TColor;
FFrameWidth: Integer;
// Property methods
function GetColor: TColor;
function GetFrameColor: TColor;
function GetFrameWidth: Integer;
procedure SetColor(const Value: TColor);
procedure SetFrameColor(const Value: TColor);
procedure SetFrameWidth(const Value: Integer);
protected
// Protected methods
procedure BufferedPaint(C: TCanvas; R: TRect); override;
published
// Properties
property Align;
property Color: TColor read GetColor write SetColor;
property FrameColor: TColor read GetFrameColor write SetFrameColor;
property FrameWidth: Integer read GetFrameWidth write SetFrameWidth;
// Event properties
property OnPaint;
end;
implementation
//---------------------------------------------------------------------------
// TcaComponentFactory
//---------------------------------------------------------------------------
constructor TcaComponentFactory.Create(AClass: TComponentClass; AOwner: TComponent);
begin
inherited Create;
FComponentClass := AClass;
FComponentOwner := AOwner;
end;
function TcaComponentFactory.GetComponentClass: TComponentClass;
begin
Result := FComponentClass;
end;
function TcaComponentFactory.GetComponentOwner: TComponent;
begin
Result := FComponentOwner;
end;
function TcaComponentFactory.GetNextComponentName: String;
var
BaseName: String;
Index: Integer;
begin
BaseName := FComponentClass.ClassName;
System.Delete(BaseName, 1, 1);
Index := 1;
while FComponentOwner.FindComponent(BaseName + IntToStr(Index)) <> nil do
Inc(Index);
Result := BaseName + IntToStr(Index);
end;
function TcaComponentFactory.NewComponent: TComponent;
var
CompState: IcaComponentState;
begin
Result := TComponent(FComponentClass.Create(FComponentOwner));
if FComponentOwner <> nil then
begin
CompState := TcaComponentState.Create;
CompState.Component := FComponentOwner;
if CompState.IsDesigning then
if (FComponentOwner is TCustomForm) or (FComponentOwner is TDataModule) then
Result.Name := GetNextComponentName;
end;
end;
procedure TcaComponentFactory.SetComponentClass(const Value: TComponentClass);
begin
FComponentClass := Value;
end;
procedure TcaComponentFactory.SetComponentOwner(const Value: TComponent);
begin
FComponentOwner := Value;
end;
//---------------------------------------------------------------------------
// TcaMargin
//---------------------------------------------------------------------------
procedure TcaMargin.Assign(Source: TPersistent);
var
AMargin: TcaMargin;
begin
if Source is TcaMargin then
begin
AMargin := TcaMargin(Source);
Left := AMargin.Left;
Top := AMargin.Top;
Right := AMargin.Right;
Bottom := AMargin.Bottom;
end;
inherited;
end;
procedure TcaMargin.BeginUpdate;
begin
Inc(FUpdateCount);
end;
procedure TcaMargin.Changed;
begin
if FUpdateCount = 0 then DoChanged;
end;
procedure TcaMargin.DoChanged;
begin
if Assigned(FOnChanged) then FOnChanged(Self);
end;
procedure TcaMargin.EndUpdate;
begin
Dec(FUpdateCount);
Changed;
end;
function TcaMargin.GetBottom: Integer;
begin
Result := FBottom;
end;
function TcaMargin.GetLeft: Integer;
begin
Result := FLeft;
end;
function TcaMargin.GetOnChanged: TNotifyEvent;
begin
Result := FOnChanged;
end;
function TcaMargin.GetRight: Integer;
begin
Result := FRight;
end;
function TcaMargin.GetTop: Integer;
begin
Result := FTop;
end;
procedure TcaMargin.SetBottom(const Value: Integer);
begin
if Value <> FBottom then
begin
FBottom := Value;
Changed;
end;
end;
procedure TcaMargin.SetLeft(const Value: Integer);
begin
if Value <> FLeft then
begin
FLeft := Value;
Changed;
end;
end;
procedure TcaMargin.SetOnChanged(const Value: TNotifyEvent);
begin
FOnChanged := Value;
end;
procedure TcaMargin.SetRight(const Value: Integer);
begin
if Value <> FRight then
begin
FRight := Value;
Changed;
end;
end;
procedure TcaMargin.SetTop(const Value: Integer);
begin
if Value <> FTop then
begin
FTop := Value;
Changed;
end;
end;
//---------------------------------------------------------------------------
// TcaCustomPanel
//---------------------------------------------------------------------------
constructor TcaCustomPanel.Create(AOwner: TComponent);
begin
inherited;
CreateOffScreenBitmap;
CreateFrameObjects;
end;
destructor TcaCustomPanel.Destroy;
begin
FreeFrameObjects;
FreeOffScreenBitmap;
RestoreWindowProc;
inherited;
end;
// Protected methods
function TcaCustomPanel.GetOffScreenCanvas: TCanvas;
begin
Result := nil;
if FOffScreenBitmap <> nil then
begin
FOffScreenBitmap.Width := Width;
FOffScreenBitmap.Height := Height;
Result := FOffScreenBitmap.Canvas;
end;
end;
procedure TcaCustomPanel.CreateWnd;
begin
inherited;
end;
procedure TcaCustomPanel.DoClickOutside(AClickedControl: TControl);
begin
if Assigned(FOnClickOutside) then FOnClickOutside(Self, AClickedControl);
end;
procedure TcaCustomPanel.DoMouseEnter;
begin
if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;
procedure TcaCustomPanel.DoMouseLeave;
begin
if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;
procedure TcaCustomPanel.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
begin
if NewStyleControls then
begin
if FTransparent then ExStyle := ExStyle or WS_EX_TRANSPARENT;
end;
end;
end;
procedure TcaCustomPanel.Paint;
var
C: TCanvas;
begin
if not FTransparent then
begin
C := GetOffScreenCanvas;
C.Brush.Color := Color;
C.Brush.Style := bsSolid;
C.FillRect(Rect(0, 0, Width, Height));
FFrameImpl.Update;
UpdateOnScreenBitmap;
end
else
inherited;
end;
procedure TcaCustomPanel.UpdateOffScreenBitmap;
begin
BitBlt(FOffScreenBitmap.Canvas.Handle, 0, 0, Width, Height, Canvas.Handle, 0, 0, SRCCOPY);
end;
procedure TcaCustomPanel.UpdateOnScreenBitmap;
begin
BitBlt(Canvas.Handle, 0, 0, Width, Height, FOffScreenBitmap.Canvas.Handle, 0, 0, SRCCOPY);
end;
// Private methods
procedure TcaCustomPanel.CreateFrameObjects;
begin
FFrameImpl := TcaFrame.Create; // FFrameImpl: IcaFrame
FFrameImpl.Control := Self;
FFrameImpl.AdjustOffsets(0, 0, -2, -2);
FFrameImpl.Sides := [sdLeft, sdTop, sdRight, sdBottom];
FFrameImpl.Style := fsRaisedPanel;
FFrameImpl.LineColor := clBtnShadow;
FFrameImpl.FocusedSides := [sdLeft, sdTop, sdRight, sdBottom];
FFrameImpl.FocusedStyle := fsRaisedPanel;
FFrameImpl.FocusedLineColor := clBtnShadow;
FFrame := TcaFrameProperties.Create;
FFrame.Frame := FFrameImpl;
end;
procedure TcaCustomPanel.CreateOffScreenBitmap;
begin
FOffScreenBitmap := TBitmap.Create;
end;
procedure TcaCustomPanel.FreeFrameObjects;
begin
FFrame.Free;
end;
procedure TcaCustomPanel.FreeOffScreenBitmap;
begin
FOffScreenBitmap.Free;
end;
procedure TcaCustomPanel.HookWindowProc(var Message: TMessage);
begin
DoHookWindowProc(Message);
FDefaultWindowProc(Message);
end;
procedure TcaCustomPanel.ReplaceWindowProc;
begin
if Owner is TForm then
begin
FDefaultWindowProc := TControl(Owner).WindowProc;
TControl(Owner).WindowProc := HookWindowProc;
end;
end;
procedure TcaCustomPanel.RestoreWindowProc;
begin
if Owner is TForm then
if Assigned(FDefaultWindowProc) then
TControl(Owner).WindowProc := FDefaultWindowProc;
end;
// Component mesage handlers
procedure TcaCustomPanel.CMCancelMode(var Message: TCMCancelMode);
begin
inherited;
DoClickOutside(Message.Sender);
end;
procedure TcaCustomPanel.CMFocusChanged(var Message: TCMFocusChanged);
begin
inherited;
FFrameImpl.Focused := Focused;
end;
procedure TcaCustomPanel.DoHookWindowProc(var Message: TMessage);
begin
if Message.Msg = WM_LBUTTONDOWN then
Pass;
inherited;
end;
procedure TcaCustomPanel.CMMouseenter(var Message: TMessage);
begin
inherited;
DoMouseEnter;
end;
procedure TcaCustomPanel.CMMouseleave(var Message: TMessage);
begin
inherited;
DoMouseLeave;
end;
// Property methods
function TcaCustomPanel.GetTransparent: Boolean;
begin
Result := FTransparent;
end;
procedure TcaCustomPanel.SetSubClassForm(const Value: Boolean);
begin
if Value <> FSubClassForm then
begin
FSubClassForm := Value;
if FSubClassForm then
ReplaceWindowProc
else
RestoreWindowProc;
end;
end;
procedure TcaCustomPanel.SetTransparent(const Value: Boolean);
begin
if Value <> FTransparent then
begin
FTransparent := Value;
RecreateWnd;
end;
end;
//---------------------------------------------------------------------------
// TcaCustomFormPanel
//---------------------------------------------------------------------------
// Public methods
procedure TcaCustomFormPanel.CreateChildForm(AForm: TForm);
begin
FForm := AForm;
UpdateChildForm;
end;
procedure TcaCustomFormPanel.CreateChildForm(AFormClass: TFormClass);
begin
FForm := AFormClass.Create(Application);
UpdateChildForm;
end;
// Protected methods
procedure TcaCustomFormPanel.CreateWnd;
begin
inherited;
UpdateChildForm;
end;
procedure TcaCustomFormPanel.DoBeforeShowForm(AForm: TForm);
begin
if Assigned(FOnBeforeShowForm) then FOnBeforeShowForm(Self, FForm);
end;
procedure TcaCustomFormPanel.DoCreateForm(var AForm: TForm);
begin
if Assigned(FOnCreateForm) then FOnCreateForm(Self, FForm);
end;
// Private methods
procedure TcaCustomFormPanel.UpdateChildForm;
begin
if not Assigned(FForm) then
if Assigned(FOnCreateForm) then FOnCreateForm(Self, FForm);
if FForm <> nil then
begin
FForm.BorderStyle := bsNone;
FForm.BorderIcons := [];
FForm.Caption := '';
FForm.Align := alClient;
FForm.Parent := Self;
DoBeforeShowForm(FForm);
FForm.Show;
end;
end;
//---------------------------------------------------------------------------
// TcaGraphicControl
//---------------------------------------------------------------------------
constructor TcaGraphicControl.Create(AOwner: TComponent);
begin
inherited;
FOffScreenBitmap := TBitmap.Create;