-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
bcbasectrls.pas
1837 lines (1582 loc) · 49.5 KB
/
bcbasectrls.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
// SPDX-License-Identifier: LGPL-3.0-linking-exception
{ Base framework classes
originally written in 2012 by Krzysztof Dibowski dibowski at interia.pl
}
{******************************* CONTRIBUTOR(S) ******************************
- Edivando S. Santos Brasil | [email protected]
(Compatibility with delphi VCL 11/2018)
***************************** END CONTRIBUTOR(S) *****************************}
unit BCBaseCtrls;
{$I bgracontrols.inc}
interface
uses
Classes, SysUtils, Controls, ExtCtrls, Graphics,
{$IFNDEF FPC}Windows, Messages, BGRAGraphics, GraphType, FPImage, {$ELSE} LCLType,{$ENDIF}
BGRABitmap, BGRABitmapTypes;
type
{$IFNDEF FPC}
TSpacingSize = Integer;
TControlCellAlign = (
ccaFill,
ccaLeftTop,
ccaRightBottom,
ccaCenter
);
TControlCellAligns = set of TControlCellAlign;
TControlBorderSpacingDefault = record
Left: TSpacingSize;
Top: TSpacingSize;
Right: TSpacingSize;
Bottom: TSpacingSize;
Around: TSpacingSize;
end;
PControlBorderSpacingDefault = ^TControlBorderSpacingDefault;
TBGRAGraphicCtrl = class;
TBGRACustomCtrl = class;
TControlBorderSpacing = class;
ILCLControl = interface
['{97A3D274-C4BD-4095-9B23-8E50D6E0EA24}']
procedure DoOnResize;
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;{%H-}WithThemeSpace: boolean);
procedure MouseEnter;
procedure MouseLeave;
procedure TextChanged;
procedure FontChanged(Sender: TObject);
procedure RealSetText(const Value: TCaption);
procedure Resize;
procedure SetColor(Value: TColor);
function GetColor : TColor;
function ColorIsStored: boolean;
function RealGetText: TCaption;
function CreateControlBorderSpacing: TControlBorderSpacing;
procedure SetBorderSpacing(const AValue: TControlBorderSpacing);
procedure SetInitialBounds(aLeft, aTop, aWidth, aHeight: integer);
procedure InvalidatePreferredSize;
procedure EnableAutoSizing;
procedure DoBorderSpacingChange(Sender: TObject; InnerSpaceChanged: Boolean);
function GetInstance : TObject;
function IsInnerBorderStored: boolean;
end;
TControlBorderSpacing = class(TPersistent)
private
FAround: TSpacingSize;
FBottom: TSpacingSize;
FCellAlignHorizontal: TControlCellAlign;
FCellAlignVertical: TControlCellAlign;
FControl: ILCLControl;
FInnerBorder: Integer;
FLeft: TSpacingSize;
FOnChange: TNotifyEvent;
FRight: TSpacingSize;
FTop: TSpacingSize;
FDefault: PControlBorderSpacingDefault;
function GetAroundBottom: Integer;
function GetAroundLeft: Integer;
function GetAroundRight: Integer;
function GetAroundTop: Integer;
function GetControlBottom: Integer;
function GetControlHeight: Integer;
function GetControlLeft: Integer;
function GetControlRight: Integer;
function GetControlTop: Integer;
function GetControlWidth: Integer;
function IsAroundStored: boolean;
function IsBottomStored: boolean;
function IsInnerBorderStored: boolean;
function IsLeftStored: boolean;
function IsRightStored: boolean;
function IsTopStored: boolean;
procedure SetAround(const AValue: TSpacingSize);
procedure SetBottom(const AValue: TSpacingSize);
procedure SetCellAlignHorizontal(const AValue: TControlCellAlign);
procedure SetCellAlignVertical(const AValue: TControlCellAlign);
procedure SetInnerBorder(const AValue: Integer);
procedure SetLeft(const AValue: TSpacingSize);
procedure SetRight(const AValue: TSpacingSize);
procedure SetSpace(Kind: TAnchorKind; const AValue: integer);
procedure SetTop(const AValue: TSpacingSize);
protected
procedure Change(InnerSpaceChanged: Boolean); virtual;
public
constructor Create(OwnerControl: ILCLControl; ADefault: PControlBorderSpacingDefault = nil);
procedure Assign(Source: TPersistent); override;
procedure AssignTo(Dest: TPersistent); override;
function IsEqual(Spacing: TControlBorderSpacing): boolean;
procedure GetSpaceAround(var SpaceAround: TRect); virtual;
function GetSideSpace(Kind: TAnchorKind): Integer; // Around+GetSpace
function GetSpace(Kind: TAnchorKind): Integer; virtual;
procedure AutoAdjustLayout(const AXProportion, AYProportion: Double);
public
property Control: ILCLControl read FControl;
property Space[Kind: TAnchorKind]: integer read GetSpace write SetSpace;
property AroundLeft: Integer read GetAroundLeft;
property AroundTop: Integer read GetAroundTop;
property AroundRight: Integer read GetAroundRight;
property AroundBottom: Integer read GetAroundBottom;
property ControlLeft: Integer read GetControlLeft;
property ControlTop: Integer read GetControlTop;
property ControlWidth: Integer read GetControlWidth;
property ControlHeight: Integer read GetControlHeight;
property ControlRight: Integer read GetControlRight;
property ControlBottom: Integer read GetControlBottom;
published
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property Left: TSpacingSize read FLeft write SetLeft stored IsLeftStored;
property Top: TSpacingSize read FTop write SetTop stored IsTopStored;
property Right: TSpacingSize read FRight write SetRight stored IsRightStored;
property Bottom: TSpacingSize read FBottom write SetBottom stored IsBottomStored;
property Around: TSpacingSize read FAround write SetAround stored IsAroundStored;
property InnerBorder: Integer read FInnerBorder write SetInnerBorder stored IsInnerBorderStored default 0;
property CellAlignHorizontal: TControlCellAlign read FCellAlignHorizontal write SetCellAlignHorizontal default ccaFill;
property CellAlignVertical: TControlCellAlign read FCellAlignVertical write SetCellAlignVertical default ccaFill;
end;
TChildControlResizeStyle = (
crsAnchorAligning, // (like Delphi)
crsScaleChilds, // scale children equally, keep space between children fixed
crsHomogenousChildResize, // enlarge children equally (i.e. by the same amount of pixel)
crsHomogenousSpaceResize // enlarge space between children equally
{$IFDEF EnablecrsSameSize}
,crsSameSize // each child gets the same size (maybe one pixel difference)
{$ENDIF}
);
TControlChildrenLayout = (
cclNone,
cclLeftToRightThenTopToBottom, // if BiDiMode <> bdLeftToRight then it becomes RightToLeft
cclTopToBottomThenLeftToRight
);
TControlChildSizing = class(TPersistent)
private
FControl: ILCLControl;
FControlsPerLine: integer;
FEnlargeHorizontal: TChildControlResizeStyle;
FEnlargeVertical: TChildControlResizeStyle;
FHorizontalSpacing: integer;
FLayout: TControlChildrenLayout;
FLeftRightSpacing: integer;
FOnChange: TNotifyEvent;
FShrinkHorizontal: TChildControlResizeStyle;
FShrinkVertical: TChildControlResizeStyle;
FTopBottomSpacing: integer;
FVerticalSpacing: integer;
procedure SetControlsPerLine(const AValue: integer);
procedure SetEnlargeHorizontal(const AValue: TChildControlResizeStyle);
procedure SetEnlargeVertical(const AValue: TChildControlResizeStyle);
procedure SetHorizontalSpacing(const AValue: integer);
procedure SetLayout(const AValue: TControlChildrenLayout);
procedure SetLeftRightSpacing(const AValue: integer);
procedure SetShrinkHorizontal(const AValue: TChildControlResizeStyle);
procedure SetShrinkVertical(const AValue: TChildControlResizeStyle);
procedure SetTopBottomSpacing(const AValue: integer);
procedure SetVerticalSpacing(const AValue: integer);
protected
procedure Change; virtual;
public
constructor Create(OwnerControl: ILCLControl);
procedure Assign(Source: TPersistent); override;
procedure AssignTo(Dest: TPersistent); override;
function IsEqual(Sizing: TControlChildSizing): boolean;
procedure SetGridSpacing(Spacing: integer);
public
property Control: ILCLControl read FControl;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
published
property LeftRightSpacing: integer read FLeftRightSpacing write SetLeftRightSpacing default 0;
property TopBottomSpacing: integer read FTopBottomSpacing write SetTopBottomSpacing default 0;
property HorizontalSpacing: integer read FHorizontalSpacing write SetHorizontalSpacing default 0;
property VerticalSpacing: integer read FVerticalSpacing write SetVerticalSpacing default 0;
property EnlargeHorizontal: TChildControlResizeStyle read FEnlargeHorizontal
write SetEnlargeHorizontal default crsAnchorAligning;
property EnlargeVertical: TChildControlResizeStyle read FEnlargeVertical
write SetEnlargeVertical default crsAnchorAligning;
property ShrinkHorizontal: TChildControlResizeStyle read FShrinkHorizontal
write SetShrinkHorizontal default crsAnchorAligning;
property ShrinkVertical: TChildControlResizeStyle read FShrinkVertical
write SetShrinkVertical default crsAnchorAligning;
property Layout: TControlChildrenLayout read FLayout write SetLayout default cclNone;
property ControlsPerLine: integer read FControlsPerLine write SetControlsPerLine default 0;
end;
{$ENDIF}
{$IFDEF FPC}
TBGRAGraphicCtrl = class(TGraphicControl)
{$ELSE}
TBGRAGraphicCtrl = class(TGraphicControl, ILCLControl)
protected
FBorderSpacing: TControlBorderSpacing;
FOnChange: TNotifyEvent;
FMouseInClient: boolean;
procedure DoOnResize; virtual;
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;{%H-}WithThemeSpace: boolean); virtual;
procedure MouseEnter; virtual;
procedure MouseLeave; virtual;
procedure TextChanged; virtual;
procedure FontChanged(Sender: TObject); virtual;
procedure RealSetText(const Value: TCaption); virtual;
procedure Resize; override;
class function GetControlClassDefaultSize: TSize; virtual;
procedure SetColor(Value: TColor); virtual;
function GetColor : TColor;
procedure CMMouseEnter(var Message :TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message :TMessage); message CM_MOUSELEAVE;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
function ColorIsStored: boolean; virtual;
function RealGetText: TCaption; virtual;
function CreateControlBorderSpacing: TControlBorderSpacing; virtual;
procedure SetBorderSpacing(const AValue: TControlBorderSpacing);
procedure DoBorderSpacingChange(Sender: TObject; InnerSpaceChanged: Boolean); virtual;
function GetInstance : TObject;
function IsInnerBorderStored: boolean;
public
constructor Create(TheOwner: TComponent);override;
destructor Destroy;override;
procedure SetInitialBounds(aLeft, aTop, aWidth, aHeight: integer); virtual;
procedure InvalidatePreferredSize; virtual;
procedure EnableAutoSizing;
property Color: TColor read GetColor write SetColor stored ColorIsStored default clWindow;
property BorderSpacing: TControlBorderSpacing read FBorderSpacing write SetBorderSpacing;
property Caption;
property Canvas;
{$ENDIF}
end;
{$IFDEF FPC}
TBGRACustomCtrl = class(TCustomControl)
{$ELSE}
TBGRACustomCtrl = class(TCustomControl, ILCLControl)
protected
FBorderSpacing: TControlBorderSpacing;
FChildSizing: TControlChildSizing;
FOnChange: TNotifyEvent;
FMouseInClient: boolean;
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;{%H-}WithThemeSpace: boolean); {$IFDEF FPC}override;{$ELSE}virtual;{$ENDIF}
procedure DoOnResize; virtual;
procedure MouseEnter; virtual;
procedure MouseLeave; virtual;
procedure TextChanged; virtual;
procedure FontChanged(Sender: TObject); virtual;
function GetDefaultDockCaption: String; virtual;
procedure RealSetText(const Value: TCaption); virtual;
procedure EnabledChanged; virtual;
procedure Resize; override;
class function GetControlClassDefaultSize: TSize; virtual;
procedure SetColor(Value: TColor); virtual;
function GetColor : TColor;
procedure UTF8KeyPress(var UTF8Key: {$IFDEF FPC}TUTF8Char{$ELSE}String{$ENDIF}); virtual;
procedure CMMouseEnter(var Message :TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message :TMessage); message CM_MOUSELEAVE;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
function ColorIsStored: boolean; virtual;
function RealGetText: TCaption; virtual;
function CreateControlBorderSpacing: TControlBorderSpacing; virtual;
procedure SetBorderSpacing(const AValue: TControlBorderSpacing);
procedure DoBorderSpacingChange(Sender: TObject; InnerSpaceChanged: Boolean); virtual;
function GetInstance : TObject;
function IsInnerBorderStored: boolean;
procedure SetChildSizing(const AValue: TControlChildSizing);
procedure DoChildSizingChange(Sender: TObject); virtual;
public
constructor Create(TheOwner: TComponent);override;
destructor Destroy;override;
procedure SetInitialBounds(aLeft, aTop, aWidth, aHeight: integer); virtual;
procedure InvalidatePreferredSize; virtual;
procedure EnableAutoSizing;
property Color: TColor read GetColor write SetColor stored ColorIsStored default clWindow;
property BorderSpacing: TControlBorderSpacing read FBorderSpacing write SetBorderSpacing;
property ChildSizing: TControlChildSizing read FChildSizing write SetChildSizing;
property Caption;
property Canvas;
{$ENDIF}
end;
{$IFDEF FPC}
TBGRACustomPanel = class(TCustomPanel)
{$ELSE}
TBGRACustomPanel = class(TCustomPanel, ILCLControl)
protected
FBorderSpacing: TControlBorderSpacing;
FChildSizing: TControlChildSizing;
FOnChange: TNotifyEvent;
FMouseInClient: boolean;
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;{%H-}WithThemeSpace: boolean); {$IFDEF FPC}override;{$ELSE}virtual;{$ENDIF}
procedure DoOnResize; virtual;
procedure MouseEnter; virtual;
procedure MouseLeave; virtual;
procedure TextChanged; virtual;
procedure FontChanged(Sender: TObject); virtual;
function GetDefaultDockCaption: String; virtual;
procedure RealSetText(const Value: TCaption); virtual;
procedure EnabledChanged; virtual;
procedure Resize; override;
class function GetControlClassDefaultSize: TSize; virtual;
procedure SetColor(Value: TColor); virtual;
function GetColor : TColor;
procedure UTF8KeyPress(var UTF8Key: {$IFDEF FPC}TUTF8Char{$ELSE}String{$ENDIF}); virtual;
procedure CMMouseEnter(var Message :TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message :TMessage); message CM_MOUSELEAVE;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
function ColorIsStored: boolean; virtual;
function RealGetText: TCaption; virtual;
function CreateControlBorderSpacing: TControlBorderSpacing; virtual;
procedure SetBorderSpacing(const AValue: TControlBorderSpacing);
procedure DoBorderSpacingChange(Sender: TObject; InnerSpaceChanged: Boolean); virtual;
function GetInstance : TObject;
function IsInnerBorderStored: boolean;
procedure SetChildSizing(const AValue: TControlChildSizing);
procedure DoChildSizingChange(Sender: TObject); virtual;
public
constructor Create(TheOwner: TComponent);override;
destructor Destroy;override;
procedure SetInitialBounds(aLeft, aTop, aWidth, aHeight: integer); virtual;
procedure InvalidatePreferredSize; virtual;
procedure EnableAutoSizing;
property Color: TColor read GetColor write SetColor stored ColorIsStored default clWindow;
property BorderSpacing: TControlBorderSpacing read FBorderSpacing write SetBorderSpacing;
property ChildSizing: TControlChildSizing read FChildSizing write SetChildSizing;
property Canvas;
{$ENDIF}
end;
TOnBCPropertyChange = procedure(ASender: TObject; AData: PtrInt) of object;
{ TBCProperty
Base BC Property with OnChange event support
}
TBCProperty = class(TPersistent)
private
FOnChange: TOnBCPropertyChange;
protected
FControl: TControl;
procedure Change(AData: PtrInt = 0); virtual;
public
constructor Create(AControl: TControl); virtual;
public
property Control: TControl read FControl;
property OnChange: TOnBCPropertyChange read FOnChange write FOnChange;
end;
{ TBGRABitmapEx
Some BGRABitmap descendant which can store custom data and has NeedRender flag
}
TBGRABitmapEx = class(TBGRABitmap)
private
FCustomData: PtrInt;
FNeedRender: Boolean;
protected
procedure Init; override;
public
property NeedRender: Boolean read FNeedRender write FNeedRender;
property CustomData: PtrInt read FCustomData write FCustomData;
procedure Discard;
end;
{ TBCGraphicControl
BC graphic control with some basic functionality like begin/end update and
debug functions
}
TBCGraphicControl = class(TBGRAGraphicCtrl)
private
{$IFDEF INDEBUG}
FPaintCount: Integer;
{$ENDIF}
FUpdateCount: Integer;
protected
procedure DoOnResize; override;
protected
{$IFDEF INDEBUG}
function GetDebugText: String; virtual;
{$ENDIF}
procedure Paint; override; // do not override in descendants!
// All descendants should use DrawControl method instead of Paint.
// DrawControl is not called between BeginUpdate and EndUpdate
procedure DrawControl; virtual;
// This method is called when control should be rendered (when some
// general action occur which change "body" e.g. resize)
procedure RenderControl; virtual;
public
{$IFDEF FPC}
{ Save all published settings to file }
procedure SaveToFile(AFileName: string); virtual; abstract;
{ Load and assign all published settings from file }
procedure LoadFromFile(AFileName: string); virtual; abstract;
{ Assign the properties from AFileName to this instance }
procedure AssignFromFile(AFileName: string); virtual; abstract;
{ Used by SaveToFile/LoadFromFile }
{$ENDIF}
constructor Create(AOwner: TComponent); override;
// This disable DrawControl method
procedure BeginUpdate; virtual;
// This enable DrawControl method
procedure EndUpdate; virtual;
// Called on EndUpdate if FUpdateCount is 0
procedure UpdateControl; virtual;
// Check if BeginUpdate was called
function IsUpdating: Boolean;
end;
{ TBCStyleDummyProperty
This is only dummy property type for access to style editor from
object inspector
}
TBCStyleDummyProperty = class(TBCProperty)
end;
{ TBCStyleGraphicControl
All descendants of this class have support for saving and loading styles and
access to style editor from object inspector or component context menu
}
TBCStyleGraphicControl = class(TBCGraphicControl)
private
FAssignStyle: TBCStyleDummyProperty;
protected
function GetStyleExtension: String; virtual; abstract;
// Dummy property for access to style editor dialog
property AssignStyle: TBCStyleDummyProperty read FAssignStyle;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property StyleExtension: String read GetStyleExtension;
end;
{ TBCCustomControl
BC custom control with some basic functionality like begin/end update and
debug functions
}
TBCCustomControl = class(TBGRACustomCtrl)
private
{$IFDEF INDEBUG}
FPaintCount: Integer;
{$ENDIF}
FUpdateCount: Integer;
protected
procedure DoOnResize; override;
protected
{$IFDEF INDEBUG}
function GetDebugText: String; virtual;
{$ENDIF}
procedure Paint; override; // do not override in descendants!
// All descendants should use DrawControl method instead of Paint.
// DrawControl is not called between BeginUpdate and EndUpdate
procedure DrawControl; virtual;
// This method is called when control should be rendered (when some
// general action occur which change "body" e.g. resize)
procedure RenderControl; virtual;
public
constructor Create(AOwner: TComponent); override;
// This disable DrawControl method
procedure BeginUpdate; virtual;
// This enable DrawControl method
procedure EndUpdate; virtual;
// Called on EndUpdate if FUpdateCount is 0
procedure UpdateControl; virtual;
// Check if BeginUpdate was called
function IsUpdating: Boolean;
end;
{ TBCStyleCustomControl
All descendants of this class have support for saving and loading styles and
access to style editor from object inspector or component context menu
}
TBCStyleCustomControl = class(TBCCustomControl)
private
FAssignStyle: TBCStyleDummyProperty;
protected
function GetStyleExtension: String; virtual; abstract;
// Dummy property for access to style editor dialog
property AssignStyle: TBCStyleDummyProperty read FAssignStyle;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property StyleExtension: String read GetStyleExtension;
end;
{$IFDEF FPC}procedure Register;{$ENDIF}
implementation
//{$IFDEF INDEBUG} uses Graphics; {$ENDIF}
{$IFDEF FPC}
procedure Register;
begin
RegisterNoIcon([TBCCustomControl]);
end;
{$ENDIF}
{ TBCStyleCustomControl }
constructor TBCStyleCustomControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAssignStyle := TBCStyleDummyProperty.Create(Self);
end;
destructor TBCStyleCustomControl.Destroy;
begin
FAssignStyle.Free;
inherited Destroy;
end;
{ TBCStyleGraphicControl }
constructor TBCStyleGraphicControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAssignStyle := TBCStyleDummyProperty.Create(Self);
end;
destructor TBCStyleGraphicControl.Destroy;
begin
FAssignStyle.Free;
inherited Destroy;
end;
{ TBCCustomControl }
procedure TBCCustomControl.DoOnResize;
begin
inherited DoOnResize;
RenderControl;
end;
{$IFDEF INDEBUG}
function TBCCustomControl.GetDebugText: String;
begin
Result := EmptyStr;
end;
{$ENDIF}
procedure TBCCustomControl.Paint;
begin
if (csCreating in ControlState) or IsUpdating then
Exit;
DrawControl;
{$IFDEF INDEBUG}
FPaintCount := FPaintCount +1;
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := clBlack;
Canvas.Font.Color := clWhite;
Canvas.TextOut(1,1,'P: '+IntToStr(FPaintCount)+' '+GetDebugText);
{$ENDIF}
inherited Paint;
end;
procedure TBCCustomControl.DrawControl;
begin
end;
procedure TBCCustomControl.RenderControl;
begin
end;
constructor TBCCustomControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF INDEBUG}
FPaintCount := 0;
{$ENDIF}
end;
procedure TBCCustomControl.BeginUpdate;
begin
FUpdateCount := FUpdateCount +1;
end;
procedure TBCCustomControl.EndUpdate;
begin
if FUpdateCount > 0 then
begin
FUpdateCount := FUpdateCount -1;
if FUpdateCount=0 then
UpdateControl;
end;
end;
procedure TBCCustomControl.UpdateControl;
begin
Self.Invalidate;
end;
function TBCCustomControl.IsUpdating: Boolean;
begin
Result := FUpdateCount>0;
end;
{ TBCProperty }
procedure TBCProperty.Change(AData: PtrInt);
begin
if Assigned(FOnChange) then
FOnChange(Self,AData);
end;
constructor TBCProperty.Create(AControl: TControl);
begin
FControl := AControl;
inherited Create;
end;
{ TBCGraphicControl }
procedure TBCGraphicControl.DoOnResize;
begin
inherited DoOnResize;
RenderControl;
end;
{$IFDEF INDEBUG}
function TBCGraphicControl.GetDebugText: String;
begin
Result := EmptyStr;
end;
{$ENDIF}
procedure TBCGraphicControl.Paint;
begin
//inherited Paint;
if (csCreating in ControlState) or IsUpdating then
Exit;
DrawControl;
{$IFDEF INDEBUG}
FPaintCount := FPaintCount +1;
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := clBlack;
Canvas.Font.Color := clWhite;
Canvas.TextOut(1,1,'P: '+IntToStr(FPaintCount)+' '+GetDebugText);
{$ENDIF}
end;
procedure TBCGraphicControl.DrawControl;
begin
end;
procedure TBCGraphicControl.RenderControl;
begin
end;
constructor TBCGraphicControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF INDEBUG}
FPaintCount := 0;
{$ENDIF}
end;
procedure TBCGraphicControl.BeginUpdate;
begin
FUpdateCount := FUpdateCount +1;
end;
procedure TBCGraphicControl.EndUpdate;
begin
if FUpdateCount > 0 then
begin
FUpdateCount := FUpdateCount -1;
if FUpdateCount=0 then
UpdateControl;
end;
end;
procedure TBCGraphicControl.UpdateControl;
begin
Invalidate;
end;
function TBCGraphicControl.IsUpdating: Boolean;
begin
Result := FUpdateCount>0;
end;
{ TBGRABitmapEx }
procedure TBGRABitmapEx.Init;
begin
inherited Init;
FNeedRender := True;
FCustomData := 0;
end;
procedure TBGRABitmapEx.Discard;
begin
FNeedRender := true;
SetSize(0,0);
end;
{$IFNDEF FPC}
constructor TBGRAGraphicCtrl.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FBorderSpacing := CreateControlBorderSpacing;
FOnChange := Font.OnChange;
Font.OnChange := FontChanged;
end;
function TBGRAGraphicCtrl.CreateControlBorderSpacing: TControlBorderSpacing;
begin
Result := TControlBorderSpacing.Create(Self);
end;
destructor TBGRAGraphicCtrl.Destroy;
begin
FreeAndNil(FBorderSpacing);
inherited;
end;
procedure TBGRAGraphicCtrl.DoBorderSpacingChange(Sender: TObject; InnerSpaceChanged: Boolean);
var
IParent : ILCLControl;
begin
if Parent <> nil then
if Supports(Parent, ILCLControl, IParent) then
IParent.InvalidatePreferredSize;
AdjustSize;
end;
procedure TBGRAGraphicCtrl.DoOnResize;
begin
if Assigned(OnResize) then
OnResize(Self);
end;
procedure TBGRAGraphicCtrl.SetBorderSpacing(const AValue: TControlBorderSpacing);
begin
if FBorderSpacing=AValue then exit;
FBorderSpacing.Assign(AValue);
end;
procedure TBGRAGraphicCtrl.SetColor(Value: TColor);
begin
if inherited Color <> Value then
begin
inherited Color := Value;
ParentColor := False;
Perform(CM_COLORCHANGED, 0, 0);
Invalidate;
end;
end;
function TBGRAGraphicCtrl.GetColor: TColor;
begin
Result := inherited Color;
end;
procedure TBGRAGraphicCtrl.EnableAutoSizing;
begin
end;
class function TBGRAGraphicCtrl.GetControlClassDefaultSize: TSize;
begin
Result.CX := 75;
Result.CY := 50;
end;
function TBGRAGraphicCtrl.GetInstance: TObject;
begin
result := Self;
end;
procedure TBGRAGraphicCtrl.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;{%H-}WithThemeSpace: boolean);
begin
PreferredWidth:=0;
PreferredHeight:=0;
end;
procedure TBGRAGraphicCtrl.MouseEnter;
begin
if Assigned(OnMouseEnter) then
OnMouseEnter(Self);
end;
procedure TBGRAGraphicCtrl.MouseLeave;
begin
if Assigned(OnMouseLeave) then
OnMouseLeave(Self);
end;
procedure TBGRAGraphicCtrl.TextChanged;
begin
// overrided;
end;
procedure TBGRAGraphicCtrl.FontChanged(Sender: TObject);
begin
ParentFont := False;
DesktopFont := False;
Invalidate;
Perform(CM_FONTCHANGED, 0, 0);
if AutoSize then
begin
InvalidatePreferredSize;
AdjustSize;
end;
if Assigned(FOnChange) then
FOnChange(Self);
end;
function TBGRAGraphicCtrl.RealGetText: TCaption;
begin
Result := Caption;
end;
procedure TBGRAGraphicCtrl.RealSetText(const Value: TCaption);
begin
if RealGetText = Value then Exit;
Caption := Value;
Perform(CM_TEXTCHANGED, 0, 0);
end;
procedure TBGRAGraphicCtrl.InvalidatePreferredSize;
begin
// Invalidate;
end;
function TBGRAGraphicCtrl.IsInnerBorderStored: boolean;
begin
Result:=BorderSpacing.InnerBorder<>0;
end;
procedure TBGRAGraphicCtrl.Resize;
begin
inherited;
Invalidate;
DoOnResize;
end;
function TBGRAGraphicCtrl.ColorIsStored: boolean;
begin
Result := not ParentColor;
end;
procedure TBGRAGraphicCtrl.SetInitialBounds(aLeft, aTop, aWidth, aHeight: integer);
begin
{if (csLoading in ComponentState)
or ((Owner<>nil) and (csLoading in Owner.ComponentState)) then
exit;}
SetBounds(aLeft,aTop,aWidth,aHeight);
// DoOnResize;
end;
procedure TBGRAGraphicCtrl.CMTextChanged(var Message: TMessage);
begin
inherited;
TextChanged;
end;
procedure TBGRAGraphicCtrl.CMMouseEnter(var Message: TMessage);
begin
if FMouseInClient then
Exit;
FMouseInClient := True;
// broadcast to parents first
if Assigned(Parent) then
Parent.Perform(CM_MOUSEENTER, 0, LParam(Self));
// if it is not a child message then perform an event
if (Message.LParam = 0) then
MouseEnter;
end;
procedure TBGRAGraphicCtrl.CMMouseLeave(var Message: TMessage);
begin
if not FMouseInClient then
Exit;
FMouseInClient := False;
// broadcast to parents first
if Assigned(Parent) then
Parent.Perform(CM_MOUSELEAVE, 0, LParam(Self));
// if it is not a child message then perform an event
if (Message.LParam = 0) then
MouseLeave;
end;
{TBGRACustomCtrl}
constructor TBGRACustomCtrl.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FBorderSpacing := CreateControlBorderSpacing;
FChildSizing:=TControlChildSizing.Create(Self);
FChildSizing.OnChange := DoChildSizingChange;
FOnChange := Font.OnChange;
Font.OnChange := FontChanged;
end;
function TBGRACustomCtrl.CreateControlBorderSpacing: TControlBorderSpacing;
begin
Result := TControlBorderSpacing.Create(Self);
end;
destructor TBGRACustomCtrl.Destroy;
begin
FreeAndNil(FBorderSpacing);
FreeAndNil(FChildSizing);
inherited;
end;
procedure TBGRACustomCtrl.DoBorderSpacingChange(Sender: TObject; InnerSpaceChanged: Boolean);
var
IParent : ILCLControl;
begin
if Parent <> nil then
if Supports(Parent, ILCLControl, IParent) then
IParent.InvalidatePreferredSize;
AdjustSize;
end;
procedure TBGRACustomCtrl.DoChildSizingChange(Sender: TObject);
begin
//debugln('TWinControl.DoChildSizingChange ',DbgSName(Self));
if ControlCount=0 then exit;
InvalidatePreferredSize;
ReAlign;
end;
procedure TBGRACustomCtrl.DoOnResize;
begin
if Assigned(OnResize) then
OnResize(Self);
end;
procedure TBGRACustomCtrl.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;{%H-}WithThemeSpace: boolean);
begin
PreferredWidth:=0;
PreferredHeight:=0;
end;
procedure TBGRACustomCtrl.MouseEnter;
begin
if Assigned(OnMouseEnter) then
OnMouseEnter(Self);
end;
procedure TBGRACustomCtrl.MouseLeave;
begin
if Assigned(OnMouseLeave) then
OnMouseLeave(Self);
end;
procedure TBGRACustomCtrl.TextChanged;
begin
// overrided;
end;
procedure TBGRACustomCtrl.FontChanged(Sender: TObject);