Repository navigation
Expand file tree
/
Copy pathSCStaticEdit.pas
More file actions
2069 lines (1734 loc) · 49.1 KB
/
Copy pathSCStaticEdit.pas
File metadata and controls
2069 lines (1734 loc) · 49.1 KB
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
{*******************************************************}
{ }
{ CA SweetControls Component Library }
{ }
{ Copyright (c) 1996,2004 CodeAccelerate Corporation }
{ }
{*******************************************************}
unit SCStaticEdit;
{$I SweetControls.inc}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ImgList, StdActns, ActnList, Menus, SCCommon, SCConsts, SCControl;
type
TSCCharChangeEvent = procedure(Sender: TObject; const Index: Integer) of object;
TSCGetCharEvent = procedure(Sender: TObject; var C: Char;
const Index: Integer; var Allowed: Boolean) of object;
TSCCharColorEvent = procedure(Sender: TObject; const Index: Integer;
var C: TColor) of object;
TSCCustomStaticEdit = class;
TSCStaticEditBorderProps = class(TSCControlBorderProps)
public
constructor Create(AOwner: TSCCustomControl); override;
published
property Border default sccb3DLowered;
property Color default clWindow;
property ExDraw;
property FlatColor;
property FlatInnerColor;
property InnerBorder;
property Width;
end;
TSCStaticEditPictureProps = class(TSCPictureProps);
TSCStaticEditColors = class(TPersistent)
private
FOwner: TSCCustomStaticEdit;
FDisabledColor: TColor;
FDisabledTextColor: TColor;
FHideSelectionColor: TColor;
FHideSelectionTextColor: TColor;
FHighlightColor: TColor;
FHighlightTextColor: TColor;
FGroupSelectionColor: TColor;
FGroupSelectionTextColor: TColor;
procedure SetDisabledColor(Value: TColor);
procedure SetDisabledTextColor(Value: TColor);
procedure SetHideSelectionColor(Value: TColor);
procedure SetHideSelectionTextColor(Value: TColor);
procedure SetHighlightColor(Value: TColor);
procedure SetHighlightTextColor(Value: TColor);
procedure SetGroupSelectionColor(Value: TColor);
procedure SetGroupSelectionTextColor(Value: TColor);
protected
procedure Changed;
function GetOwner: TPersistent; override;
property Owner: TSCCustomStaticEdit read FOwner;
public
constructor Create(AOwner: TSCCustomStaticEdit); virtual;
procedure Assign(Source: TPersistent); override;
published
property DisabledColor: TColor read FDisabledColor write SetDisabledColor default clBtnFace;
property DisabledTextColor: TColor read FDisabledTextColor write SetDisabledTextColor default clGrayText;
property GroupSelectionColor: TColor read FGroupSelectionColor write SetGroupSelectionColor default clHighlight;
property GroupSelectionTextColor: TColor read FGroupSelectionTextColor write SetGroupSelectionTextColor default clHighlightText;
property HideSelectionColor: TColor read FHideSelectionColor write SetHideSelectionColor default clBtnShadow;
property HideSelectionTextColor: TColor read FHideSelectionTextColor write SetHideSelectionTextColor default clBtnHighlight;
property HighlightColor: TColor read FHighlightColor write SetHighlightColor default clHighlight;
property HighlightTextColor: TColor read FHighlightTextColor write SetHighlightTextColor default clHighlightText;
end;
TSCStaticEditColorsClass = class of TSCStaticEditColors;
TSCStaticEditItem = class(TCollectionItem)
private
FCharData: Char;
FColor: TColor;
FEditable: Boolean;
FGroupIndex: Integer;
FTag: Integer;
procedure SetCharData(const Value: Char);
procedure SetColor(Value: TColor);
procedure SetEditable(Value: Boolean);
procedure SetGroupIndex(Value: Integer);
procedure SetTag(Value: Integer);
protected
function GetRangedValue(C: Char; var Allowed: Boolean): Char;
function GetDisplayName: string; override;
function GetStaticEdit: TSCCustomStaticEdit;
public
constructor Create(Collection: TCollection); override;
procedure Assign(Source: TPersistent); override;
property StaticEdit: TSCCustomStaticEdit read GetStaticEdit;
published
property CharData: Char read FCharData write SetCharData default '0';
property Color: TColor read FColor write SetColor default clNone;
property Editable: Boolean read FEditable write SetEditable default True;
property GroupIndex: Integer read FGroupIndex write SetGroupIndex default 0;
property Tag: Integer read FTag write SetTag default 0;
end;
TSCStaticEditItems = class(TCollection)
private
FOwner: TSCCustomStaticEdit;
function GetItem(Index: Integer): TSCStaticEditItem;
procedure SetItem(Index: Integer; Value: TSCStaticEditItem);
protected
function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override;
public
constructor Create(AOwner: TSCCustomStaticEdit); virtual;
procedure Assign(Source: TPersistent); override;
function Add: TSCStaticEditItem;
{$IFDEF SC_DELPHI5_AND_EARLY}
property Owner: TSCCustomStaticEdit read FOwner;
{$ENDIF}
property Items[Index: Integer]: TSCStaticEditItem read GetItem write SetItem; default;
end;
TSCCustomStaticEdit = class(TSCCustomControl)
private
FAlignment: TLeftRight;
FColors: TSCStaticEditColors;
FReadonly: Boolean;
FCreating: Boolean;
FItemIndex: Integer;
FIsMouseDown: Boolean;
FHideSelection: Boolean;
FUpdateCount: Integer;
FEditCount: Integer;
FCharList: TList;
FIndentLeft: Integer;
FIndentRight: Integer;
FItems: TSCStaticEditItems;
FOnGetChar: TSCGetCharEvent;
FOnCharChange: TSCCharChangeEvent;
FOnEditValue: TNotifyEvent;
FOnGetBackColor: TSCCharColorEvent;
FOnGetForeColor: TSCCharColorEvent;
procedure SetAlignment(Value: TLeftRight);
procedure SetColors(Value: TSCStaticEditColors);
procedure SetReadonly(Value: Boolean);
procedure SetHideSelection(Value: Boolean);
function GetCaption: TCaption;
function GetEditingText: Boolean;
procedure SetItems(Value: TSCStaticEditItems);
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CNChar(var Message: TWMChar); message CN_CHAR;
procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
protected
procedure CreateWnd; override;
procedure Paint; override;
procedure Loaded; override;
procedure UpdateView;
procedure EditValueChanged;
procedure DoEditValueChanged; virtual;
function GetColorsClass: TSCStaticEditColorsClass; dynamic;
procedure ItemValueChanged(Index: Integer);
procedure DoItemValueChanged(Index: Integer); virtual;
procedure GetChar(var C: Char; Index: Integer; var Allowed: Boolean);
procedure DoGetChar(var C: Char; const Index: Integer;
var Allowed: Boolean); virtual;
procedure SetItemIndex(Value: Integer);
function GetRealIndex(const Value: Integer): Integer;
function GetDefaultBackColor: TColor; override;
function GetDefaultForeColor: TColor; override;
function GetBackColor(const Index: Integer): TColor;
function GetForeColor(const Index: Integer): TColor;
procedure DoGetBackColor(const Index: Integer; var C: TColor); virtual;
procedure DoGetForeColor(const Index: Integer; var C: TColor); virtual;
procedure PaintText(C: TCanvas); virtual;
procedure DoDrawBack(C: TCanvas); virtual;
procedure DoDrawText(C: TCanvas); virtual;
procedure ConstrainedResize(var MinWidth, MinHeight, MaxWidth, MaxHeight: Integer); override;
function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
procedure DoPictureListChanged; override;
function GetBorderPropsClass: TSCControlBorderPropsClass; override;
function GetPicturePropsClass: TSCCustomPicturePropsClass; override;
procedure DoColorsChanged; dynamic;
function GetCharList: TList;
procedure RemoveCharList;
procedure InitiateCharList;
function GetCharSize(C: Char): TPoint;
function GetCharWidth(C: Char): Integer;
function GetCharHeight(C: Char): Integer;
function GetTextWidth(S: String): Integer;
function GetLineWidth(L: Integer): Integer;
function GetLineHeight: Integer; virtual;
function GetEditRect: TRect; virtual;
procedure AdjustBounds; override;
function GetAutoHeight: Integer; dynamic;
function GetExtraBorderSize: Integer; virtual;
function CanGetFocus: Boolean; override;
procedure StopTracking; override;
procedure EnabledChanged; override;
procedure BorderChanged; override;
function GetBlendValue: Word; override;
procedure ItemChanged(Item: TSCStaticEditItem);
function CanBeepForKey(Key: Word; Shift: TShiftState): Boolean; virtual;
function IsValidKey(Key: Char): Boolean; virtual;
function UpdateKey(Key: Char): Char; virtual;
procedure DoMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure ProcessKeyDown(var Key: Word); virtual;
procedure ProcessKeyPress(var Key: Char); virtual;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure Clear; virtual;
property Alignment: TLeftRight read FAlignment write SetAlignment default taLeftJustify;
property Creating: Boolean read FCreating;
property AutoSize default True;
property BorderProps;
property Color default clWindow;
property ClickFocus default True;
property ItemIndex: Integer read FItemIndex write SetItemIndex default -1;
property Colors: TSCStaticEditColors read FColors write SetColors;
property HideSelection: Boolean read FHideSelection write SetHideSelection default True;
property ReadOnly: Boolean read FReadOnly write SetReadOnly default False;
property TabStop default True;
property Items: TSCStaticEditItems read FItems write SetItems;
property IsMouseDown: Boolean read FIsMouseDown;
property Text: TCaption read GetCaption;
property OnGetChar: TSCGetCharEvent read FOnGetChar write FOnGetChar;
property OnEditValue: TNotifyEvent read FOnEditValue write FOnEditValue;
property OnCharChange: TSCCharChangeEvent read FOnCharChange write FOnCharChange;
property OnGetBackColor: TSCCharColorEvent read FOnGetBackColor write FOnGetBackColor;
property OnGetForeColor: TSCCharColorEvent read FOnGetForeColor write FOnGetForeColor;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure BeginUpdate;
procedure EndUpdate;
procedure BeginEdit;
procedure EndEdit;
function SetChar(C: Char): Boolean;
function GetFirstJump: Integer;
function GetLastJump: Integer;
function GetPrevJump(const Value: Integer): Integer;
function GetNextJump(const Value: Integer): Integer;
function GetPrevGroup(const Value: Integer): Integer;
function GetNextGroup(const Value: Integer): Integer;
function ItemAtPos(P: TPoint): Integer;
function ItemFocused(Index: Integer): Boolean;
function ItemSelected(Index: Integer): Boolean;
property UpdateCount: Integer read FUpdateCount;
property EditCount: Integer read FEditCount;
property EditingText: Boolean read GetEditingText;
end;
TSCStaticEdit = class(TSCCustomStaticEdit)
public
property ItemIndex;
property Text;
published
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BorderProps;
property Color;
property Colors;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property Items;
property ParentColor;
property ParentFont;
property ParentShowHint;
property Picture;
property PictureProps;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Transparent;
property Visible;
property OnCanResize;
property OnChange;
property OnCharChange;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEditValue;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetChar;
property OnGetBackColor;
property OnGetForeColor;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
end;
implementation
{ TSCStaticEditBorderProps }
constructor TSCStaticEditBorderProps.Create(AOwner: TSCCustomControl);
begin
inherited Create(AOwner);
Border := sccb3DLowered;
Color := clWindow;
end;
{ TSCStaticEditColors }
procedure TSCStaticEditColors.Assign(Source: TPersistent);
begin
if Source is TSCStaticEditColors then
begin
if FOwner <> nil then FOwner.BeginUpdate;
try
with TSCStaticEditColors(Source) do
begin
Self.DisabledColor := DisabledColor;
Self.DisabledTextColor := DisabledTextColor;
Self.HideSelectionColor := HideSelectionColor;
Self.HideSelectionTextColor := HideSelectionTextColor;
Self.HighlightColor := HighlightColor;
Self.HighlightTextColor := HighlightTextColor;
Self.GroupSelectionColor := GroupSelectionColor;
Self.GroupSelectionTextColor := GroupSelectionTextColor;
end;
finally
if FOwner <> nil then
FOwner.EndUpdate;
end;
end else
inherited Assign(Source);
end;
procedure TSCStaticEditColors.Changed;
begin
if FOwner <> nil then FOwner.DoColorsChanged;
end;
constructor TSCStaticEditColors.Create(AOwner: TSCCustomStaticEdit);
begin
inherited Create;
FOwner := AOwner;
FDisabledColor := clBtnFace;
FDisabledTextColor := clGrayText;
FHideSelectionColor := clBtnShadow;
FHideSelectionTextColor := clBtnHighlight;
FHighlightColor := clHighlight;
FHighlightTextColor := clHighlightText;
FGroupSelectionColor := clHighlight;
FGroupSelectionTextColor := clHighlightText;
end;
function TSCStaticEditColors.GetOwner: TPersistent;
begin
Result := FOwner;
end;
procedure TSCStaticEditColors.SetDisabledColor(Value: TColor);
begin
if FDisabledColor <> Value then
begin
FDisabledColor := Value;
Changed;
end;
end;
procedure TSCStaticEditColors.SetDisabledTextColor(Value: TColor);
begin
if FDisabledTextColor <> Value then
begin
FDisabledTextColor := Value;
Changed;
end;
end;
procedure TSCStaticEditColors.SetHideSelectionColor(Value: TColor);
begin
if FHideSelectionColor <> Value then
begin
FHideSelectionColor := Value;
Changed;
end;
end;
procedure TSCStaticEditColors.SetHideSelectionTextColor(Value: TColor);
begin
if FHideSelectionTextColor <> Value then
begin
FHideSelectionTextColor := Value;
Changed;
end;
end;
procedure TSCStaticEditColors.SetHighlightColor(Value: TColor);
begin
if FHighlightColor <> Value then
begin
FHighlightColor := Value;
Changed;
end;
end;
procedure TSCStaticEditColors.SetHighlightTextColor(Value: TColor);
begin
if FHighlightTextColor <> Value then
begin
FHighlightTextColor := Value;
Changed;
end;
end;
procedure TSCStaticEditColors.SetGroupSelectionColor(Value: TColor);
begin
if FGroupSelectionColor <> Value then
begin
FGroupSelectionColor := Value;
Changed;
end;
end;
procedure TSCStaticEditColors.SetGroupSelectionTextColor(Value: TColor);
begin
if FGroupSelectionTextColor <> Value then
begin
FGroupSelectionTextColor := Value;
Changed;
end;
end;
{ TSCCustomStaticEdit }
procedure TSCCustomStaticEdit.AdjustBounds;
begin
AdjustSize;
end;
procedure TSCCustomStaticEdit.Assign(Source: TPersistent);
begin
inherited Assign(Source);
if Source is TSCCustomStaticEdit then
begin
with TSCCustomStaticEdit(Source) do
begin
Self.AutoSize := AutoSize;
Self.Colors := Colors;
Self.HideSelection := HideSelection;
Self.Picture := Picture;
Self.PictureProps := PictureProps;
Self.ReadOnly := ReadOnly;
end;
end;
end;
procedure TSCCustomStaticEdit.BeginUpdate;
begin
Inc(FUpdateCount);
end;
procedure TSCCustomStaticEdit.BorderChanged;
begin
inherited BorderChanged;
AdjustSize;
end;
function TSCCustomStaticEdit.CanAutoSize(var NewWidth,
NewHeight: Integer): Boolean;
begin
Result := True;
if HandleAllocated then NewHeight := GetAutoHeight;
end;
function TSCCustomStaticEdit.CanBeepForKey(Key: Word;
Shift: TShiftState): Boolean;
begin
Result := not IsValidKey(Char(Key));
end;
function TSCCustomStaticEdit.CanGetFocus: Boolean;
begin
Result := False;
end;
procedure TSCCustomStaticEdit.Clear;
begin
end;
procedure TSCCustomStaticEdit.CMFontChanged(var Message: TMessage);
begin
inherited;
InitiateCharList;
AdjustSize;
Invalidate;
end;
procedure TSCCustomStaticEdit.CNChar(var Message: TWMChar);
var
Key: Char;
ShiftState: TShiftState;
KeyState: TKeyboardState;
begin
Inc(FEditCount);
try
inherited;
if not (IsDesigning or FIsMouseDown or MouseIsDown) and not ReadOnly then
begin
Key := Char(Message.CharCode);
if (Key <> ^H) and not IsValidKey(Key) then
begin
GetKeyboardState(KeyState);
ShiftState := KeyboardStateToShiftState(KeyState);
if CanBeepForKey(Ord(Key), ShiftState) then
Beep;
end;
end;
finally
Dec(FEditCount);
end;
end;
procedure TSCCustomStaticEdit.ConstrainedResize(var MinWidth, MinHeight,
MaxWidth, MaxHeight: Integer);
begin
inherited ConstrainedResize(MinWidth, MinHeight, MaxWidth, MaxHeight);
if AutoSize then
begin
MinHeight := GetAutoHeight;
MaxHeight := MinHeight;
end;
end;
constructor TSCCustomStaticEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csSetCaption];
SetBounds(Left, Top, 120, 21);
Border := sccb3DLowered;
BorderColor := clWindow;
ParentColor := False;
Color := clWindow;
TabStop := True;
AutoSize := True;
DoubleBuffered := True;
ClickFocus := True;
FHideSelection := True;
FItemIndex := -1;
FIndentLeft := 0;
FIndentRight := 0;
FColors := GetColorsClass.Create(Self);
FItems := TSCStaticEditItems.Create(Self);
end;
procedure TSCCustomStaticEdit.CreateWnd;
begin
FCreating := True;
try
inherited CreateWnd;
finally
FCreating := False;
end;
end;
destructor TSCCustomStaticEdit.Destroy;
begin
RemoveCharList;
FreeAndNil(FColors);
FreeAndNil(FItems);
inherited Destroy;
end;
procedure TSCCustomStaticEdit.DoColorsChanged;
begin
UpdateView;
end;
procedure TSCCustomStaticEdit.DoDrawBack(C: TCanvas);
var
CR: TRect;
begin
if C <> nil then
begin
CR := GetClientRect;
if not IsRectEmpty(CR) then
with C do
begin
Brush.Style := bsSolid;
Brush.Color := GetBackColor(-1);
FillRect(CR);
end;
if Transparent then
PaintParentOn(C);
end;
end;
procedure TSCCustomStaticEdit.DoDrawText(C: TCanvas);
var
CR, R: TRect;
SR: Integer;
begin
if C <> nil then
begin
CR := GetClientRect;
if not IsRectEmpty(CR) then
begin
R := GetEditRect;
IntersectRect(R, R, CR);
if not IsRectEmpty(R) then
begin
SR := IntersectClipRect(C.Handle, R.Left, R.Top, R.Right, R.Bottom);
try
if SR <> NULLREGION then
PaintText(C);
finally
SelectClipRgn(C.Handle, 0);
end;
end;
end;
end;
end;
procedure TSCCustomStaticEdit.DoMouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
R: TRect;
begin
FIsMouseDown := Button = mbLeft;
if FIsMouseDown then
begin
R := GetEditRect;
if (Border <> sccbNone) or (BorderInner <> sccbNone) then
InflateRect(R, 1, 1);
if IsRectEmpty(R) or not PtInRect(R, Point(X, Y)) then
FIsMouseDown := False;
end;
inherited DoMouseDown(Button, Shift, X, Y);
end;
procedure TSCCustomStaticEdit.DoPictureListChanged;
begin
if ShowPicture then
UpdateView;
end;
procedure TSCCustomStaticEdit.EnabledChanged;
begin
FIsMouseDown := False;
Invalidate;
end;
procedure TSCCustomStaticEdit.EndUpdate;
begin
if FUpdateCount > 0 then
begin
Dec(FUpdateCount);
UpdateView;
end;
end;
function TSCCustomStaticEdit.GetAutoHeight: Integer;
var
Eh: Integer;
begin
Result := Height;
if HandleAllocated then
begin
Result := GetLineHeight + 3;
Eh := GetExtraBorderSize;
Inc(Result, 2*(GetBorderSize + BorderWidth + GetInnerBorderSize + Eh));
end;
end;
function TSCCustomStaticEdit.GetBackColor(const Index: Integer): TColor;
var
IsSelected, IsFocused: Boolean;
begin
Result := clNone;
if not Enabled then
begin
if FColors <> nil then
Result := FColors.DisabledColor;
if Result = clNone then
Result := GetDefaultBackColor;
end else
begin
if Index < 0 then
Result := GetDefaultBackColor;
if not IsDesigning then
begin
IsFocused := ItemFocused(Index);
IsSelected := ItemSelected(Index);
if IsFocused or IsSelected then
begin
Result := clNone;
if (FColors <> nil) then
begin
if HasFocus then
begin
Result := FColors.GroupSelectionColor;
if IsFocused then
Result := FColors.HighlightColor;
end else
if not Self.HideSelection then
Result := FColors.HideSelectionColor;
end;
end;
end;
end;
DoGetBackColor(Index, Result);
if Assigned(FOnGetBackColor) then
FOnGetBackColor(Self, Index, Result);
end;
function TSCCustomStaticEdit.GetBlendValue: Word;
begin
Result := 0;
end;
function TSCCustomStaticEdit.GetBorderPropsClass: TSCControlBorderPropsClass;
begin
Result := TSCStaticEditBorderProps;
end;
function TSCCustomStaticEdit.GetCaption: TCaption;
var
C: Char;
I: Integer;
begin
Result := '';
if (FItems <> nil) and (FItems.Count > 0) then
for I := 0 to FItems.Count-1 do
begin
C := FItems[I].CharData;
if Ord(C) < 32 then C := ' ';
Result := Result + C;
end;
end;
function TSCCustomStaticEdit.GetCharHeight(C: Char): Integer;
var
I: Integer;
P: PPoint;
L: TList;
begin
Result := 0;
L := GetCharList;
I := Ord(C);
if (L <> nil) and (I > 0) and (I < L.Count) then
begin
P := L.Items[I];
Result := P^.y;
end;
end;
function TSCCustomStaticEdit.GetCharList: TList;
begin
if FCharList = nil then
InitiateCharList;
Result := FCharList;
end;
function TSCCustomStaticEdit.GetCharSize(C: Char): TPoint;
var
I: Integer;
P: PPoint;
L: TList;
begin
Result := Point(0, 0);
L := GetCharList;
I := Ord(C);
if (L <> nil) and (I > 0) and (I < L.Count) then
begin
P := L.Items[I];
Result.x := P^.x;
Result.y := P^.y;
end;
end;
function TSCCustomStaticEdit.GetCharWidth(C: Char): Integer;
var
I: Integer;
P: PPoint;
L: TList;
begin
Result := 0;
L := GetCharList;
I := Ord(C);
if (L <> nil) and (I > 0) and (I < L.Count) then
begin
P := L.Items[I];
Result := P^.x;
end;
end;
function TSCCustomStaticEdit.GetEditingText: Boolean;
begin
Result := FEditCount > 0;
end;
function TSCCustomStaticEdit.GetExtraBorderSize: Integer;
begin
Result := 0;
end;
function TSCCustomStaticEdit.GetForeColor(const Index: Integer): TColor;
var
IsSelected, IsFocused: Boolean;
begin
Result := clNone;
if not Enabled then
begin
if FColors <> nil then
Result := FColors.DisabledTextColor;
if Result = clNone then
Result := GetDefaultForeColor;
end else
begin
if Index < 0 then
Result := GetDefaultForeColor;
if (FItems <> nil) and (Index > -1) and (Index < FItems.Count) then
begin
Result := FItems[Index].Color;
if not IsDesigning then
begin
IsFocused := ItemFocused(Index);
IsSelected := ItemSelected(Index);
if (IsFocused or IsSelected) then
begin
Result := clNone;
if (FColors <> nil) then
begin
if HasFocus then
begin
Result := FColors.GroupSelectionTextColor;
if IsFocused then
Result := FColors.HighlightTextColor;
end else
if not Self.HideSelection then
Result := FColors.HideSelectionTextColor;
end;
end;
end;
end;
end;
DoGetForeColor(Index, Result);
if Assigned(FOnGetForeColor) then
FOnGetForeColor(Self, Index, Result);
end;
function TSCCustomStaticEdit.GetLineHeight: Integer;
begin
Result := 0;
if HandleAllocated then
Result := ((GetCharHeight('R') + GetCharHeight('q')) div 2) + 1;
end;
function TSCCustomStaticEdit.GetLineWidth(L: Integer): Integer;
var
S: String;
Ln, I: Integer;
begin
Result := 0;
S := GetCaption;
Ln := Length(S);
for I := 1 to Ln do
Inc(Result, GetCharWidth(S[I]));
end;
function TSCCustomStaticEdit.GetPicturePropsClass: TSCCustomPicturePropsClass;
begin
Result := TSCStaticEditPictureProps;
end;
function TSCCustomStaticEdit.GetTextWidth(S: String): Integer;
var
I: Integer;
begin
Result := 0;
for I := 1 to Length(S) do
Inc(Result, GetCharWidth(S[I]));
end;
type
TCharCanvas = class(TCanvas);
procedure TSCCustomStaticEdit.InitiateCharList;
var
S: TSize;
P: PPoint;
I: Integer;
begin
RemoveCharList;
if not HandleAllocated then
Exit;