-
Notifications
You must be signed in to change notification settings - Fork 2
/
Inspector.pas
2004 lines (1756 loc) · 56.7 KB
/
Inspector.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
{*******************************************************}
{ }
{ TInspector }
{ Author: Ernst Reidinga }
{ }
{ Inspector like component with categories, }
{ inline editor and button. VCL Styles }
{ are supported. }
{ }
{ Version: 1.0 }
{ Date : 22/08/2023 }
{ }
{ Version History: }
{ - 1.0.0.0 }
{ }
{*******************************************************}
unit Inspector;
interface
uses
WinApi.Windows, WinApi.Messages, System.SysUtils, System.Classes, Vcl.Controls,
Vcl.Themes, Vcl.Graphics, System.Types, Vcl.StdCtrls;
const
MinimalHeight = 16;
MinimalWidth = 16;
const
CategoryHeight = 22;
CategoryColor = clBtnFace;
const
PropertyHeight = 20;
const
GutterWidth = 18;
GutterColor = clBtnFace;
const
SplitterColor = clBtnFace;
SplitterCursor = crSizeWE;
SplitterLeft = 130;
const
TextOffset = 2;
ButtonWidth = 20;
type
TInspectorProperty = class;
TInspectorCategory = class;
TInspectorPropertyEvent = procedure(const &Property: TInspectorProperty) of object;
TInspectorCategoryEvent = procedure(const Category: TInspectorCategory) of object;
TInspectorPropertyEdit = class(TCustomEdit)
private
FInspectorProperty: TInspectorProperty;
public
constructor Create(AOwner: TComponent); override;
property InspectorProperty: TInspectorProperty read FInspectorProperty write FInspectorProperty;
public
procedure UpdateEditHeight;
procedure UpdateEditorPosition(const Rect: TRect);
procedure SetEditorActive(const Rect: TRect; const Value: string);
procedure SetEditorInActive;
end;
TInspectorPropertyEditButton = class(TButton)
public
procedure UpdateEditorPosition(const Rect: TRect);
procedure SetEditorActive(const Rect: TRect);
procedure SetEditorInActive;
end;
TInspectorProperty = class(TCollectionItem)
private
FName: string;
FValue: Variant;
FEditButton: Boolean;
FTag: Integer;
FRect: TRect;
FSelectRect: TRect;
FEditorRect: TRect;
procedure SetName(const Name: string);
procedure SetValue(const Value: Variant);
procedure SetEditButton(const Button: Boolean);
protected
function GetDisplayName: string; override;
public
constructor Create(Collection: TCollection); override;
procedure Assign(Source: TPersistent); override;
property Rect: TRect read FRect write FRect;
property SelectRect: TRect read FSelectRect write FSelectRect;
property EditorRect: TRect read FEditorRect write FEditorRect;
published
property Name: string read FName write SetName;
property Value: Variant read FValue write SetValue;
property EditButton: Boolean read FEditButton write SetEditButton default False;
property Tag: Integer read FTag write FTag;
end;
TInspectorPropertyCollection = class(TOwnedCollection)
private
FOnChange: TNotifyEvent;
function GetItem(Index: Integer): TInspectorProperty;
procedure SetItem(Index: Integer; Value: TInspectorProperty);
protected
procedure Update(Item: TCollectionItem); override;
public
function Add: TInspectorProperty;
procedure Assign(Source: TPersistent); override;
property Items[Index: Integer]: TInspectorProperty read GetItem write SetItem; default;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
TInspectorCategory = class(TCollectionItem)
private
FCaption: TCaption;
FCollapsed: Boolean;
FProperties: TInspectorPropertyCollection;
FRect: TRect;
FCollapseRect: TRect;
procedure SetCaption(const Caption: TCaption);
procedure SetCollapsed(Collapsed: Boolean);
protected
procedure PropertiesChanged(Sender: TObject);
function GetDisplayName: string; override;
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
property Rect: TRect read FRect write FRect;
property CollapseRect: TRect read FCollapseRect write FCollapseRect;
published
property Caption: TCaption read FCaption write SetCaption;
property Collapsed: Boolean read FCollapsed write SetCollapsed default False;
property Properties: TInspectorPropertyCollection read FProperties write FProperties;
end;
TInspectorCategoryCollection = class(TOwnedCollection)
private
FOnChange: TNotifyEvent;
function GetItem(Index: Integer): TInspectorCategory;
procedure SetItem(Index: Integer; Value: TInspectorCategory);
protected
procedure Update(Item: TCollectionItem); override;
public
function Add: TInspectorCategory;
procedure Assign(Source: TPersistent); override;
property Items[Index: Integer]: TInspectorCategory read GetItem write SetItem; default;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
TInspectorCategoryOptions = class(TPersistent)
private
FOnChange: TNotifyEvent;
FHeight: Integer;
FColor: TColor;
FShowFocusRect: Boolean;
FFont: TFont;
procedure SetHeight(Height: Integer);
procedure SetColor(Color: TColor);
procedure SetShowFocusRect(Show: Boolean);
protected
procedure FontChanged(Sender: TObject);
public
constructor Create; virtual;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property Height: Integer read FHeight write SetHeight default CategoryHeight;
property Color: TColor read FColor write SetColor default CategoryColor;
property ShowFocusRect: Boolean read FShowFocusRect write SetShowFocusRect default True;
property Font: TFont read FFont write FFont;
end;
TInspectorPropertyOptions = class(TPersistent)
private
FOnChange: TNotifyEvent;
FHeight: Integer;
FFont: TFont;
procedure SetHeight(Height: Integer);
protected
procedure FontChanged(Sender: TObject);
public
constructor Create; virtual;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property Height: Integer read FHeight write SetHeight default PropertyHeight;
property Font: TFont read FFont write FFont;
end;
TInspectorGutterOptions = class(TPersistent)
private
FOnChange: TNotifyEvent;
FWidth: Integer;
FColor: TColor;
procedure SetWidth(Width: Integer);
procedure SetColor(Color: TColor);
public
constructor Create; virtual;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property Width: Integer read FWidth write SetWidth default GutterWidth;
property Color: TColor read FColor write SetColor default GutterColor;
end;
TInspectorSplitter = class(TPersistent)
private
FOnChange: TNotifyEvent;
FColor: TColor;
FCursor: TCursor;
FLeft: Integer;
FRect: TRect;
procedure SetColor(Color: TColor);
procedure SetCursor(Cursor: TCursor);
procedure SetLeft(Left: Integer);
public
public
constructor Create; virtual;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
property Rect: TRect read FRect write FRect;
published
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property Color: TColor read FColor write SetColor default SplitterColor;
property Cursor: TCursor read FCursor write SetCursor default SplitterCursor;
property Left: Integer read FLeft write SetLeft default SplitterLeft;
end;
TInspector = class(TCustomControl)
private
class constructor Create;
class destructor Destroy;
private
FOnPropertySelect : TInspectorPropertyEvent;
FOnPropertyChange : TInspectorPropertyEvent;
FOnPropertyChanged : TInspectorPropertyEvent;
FOnPropertyButtonClick : TInspectorPropertyEvent;
FOnCategorySelect : TInspectorCategoryEvent;
FOnCategoryCollapse : TInspectorCategoryEvent;
FOnCategoryExpand : TInspectorCategoryEvent;
FBuffer : TBitmap;
FItemBuffer : TBitmap;
FUpdateRect : TRect;
FOldScrollPos : Integer;
FScrollPos : Integer;
FUpdateCount : Integer;
FOldHeight : Integer;
FSplitterMouseDown: Boolean;
FSelectedMouseDown: Boolean;
FSelected: TCollectionItem;
FCategories: TInspectorCategoryCollection;
FCategoryOptions: TInspectorCategoryOptions;
FPropertyOptions: TInspectorPropertyOptions;
FGutterOptions: TInspectorGutterOptions;
FSplitter: TInspectorSplitter;
FInspectorEditActive: Boolean;
FInspectorEditButtonActive: Boolean;
FInspectorEdit: TInspectorPropertyEdit;
FInspectorEditButton: TInspectorPropertyEditButton;
procedure SetSelected(const Item: TCollectionItem);
procedure OnPropertyEditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure OnPropertyEditorExit(Sender: TObject);
procedure OnPropertyEditorChange(Sender: TObject);
procedure OnPropertyEditorButtonClick(Sender: TObject);
procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd); message WM_ERASEBKGND;
procedure WMPaletteChanged(var Message: TMessage); message WM_PALETTECHANGED;
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMGetDLGCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
protected
procedure CategoriesChanged(Sender: TObject);
procedure OptionsChanged(Sender: TObject);
procedure UpdateRects;
procedure UpdateBuffer;
procedure UpdateStyleElements; override;
procedure WndProc(var Message: TMessage); override;
procedure ScrollPosUpdated;
function ScrollOffsetRect(const Rect: TRect): TRect;
procedure Paint; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure SelectPrevious;
procedure SelectNext;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X: Integer; Y: Integer); override;
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
procedure DblClick; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure Repaint; override;
procedure BeginUpdate; virtual;
procedure EndUpdate; virtual;
procedure Clear; virtual;
property Selected: TCollectionItem read FSelected write SetSelected;
published
property OnPropertySelect: TInspectorPropertyEvent read FOnPropertySelect write FOnPropertySelect;
property OnPropertyChange: TInspectorPropertyEvent read FOnPropertyChange write FOnPropertyChange;
property OnPropertyChanged: TInspectorPropertyEvent read FOnPropertyChanged write FOnPropertyChanged;
property OnPropertyButtonClick: TInspectorPropertyEvent read FOnPropertyButtonClick write FOnPropertyButtonClick;
property OnCategorySelect: TInspectorCategoryEvent read FOnCategorySelect write FOnCategorySelect;
property OnCategoryCollapse: TInspectorCategoryEvent read FOnCategoryCollapse write FOnCategoryCollapse;
property OnCategoryExpand: TInspectorCategoryEvent read FOnCategoryExpand write FOnCategoryExpand;
property Categories: TInspectorCategoryCollection read FCategories write FCategories;
property CategoryOptions: TInspectorCategoryOptions read FCategoryOptions write FCategoryOptions;
property PropertyOptions: TInspectorPropertyOptions read FPropertyOptions write FPropertyOptions;
property GutterOptions: TInspectorGutterOptions read FGutterOptions write FGutterOptions;
property Splitter: TInspectorSplitter read FSplitter write FSplitter;
property Align;
property Anchors;
property Enabled;
property TabStop default True;
end;
procedure Register;
implementation
uses Vcl.Forms, System.Math;
procedure Register;
begin
RegisterComponents('ERDesigns', [TInspector]);
end;
constructor TInspectorPropertyEdit.Create(AOwner: TComponent);
begin
inherited Create(Aowner);
BorderStyle := bsNone;
UpdateEditHeight;
end;
procedure TInspectorPropertyEdit.UpdateEditHeight;
var
DC: HDC;
SaveFont: HFont;
Metrics: TTextMetric;
begin
DC := GetDC(0);
try
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
finally
ReleaseDC(0, DC);
end;
Height := Metrics.tmHeight;
end;
procedure TInspectorPropertyEdit.UpdateEditorPosition(const Rect: TRect);
begin
var RectCenter := Rect.Top + (Rect.Height div 2);
var EditCenter := Height div 2;
var NewTop := RectCenter - EditCenter;
if (Top <> NewTop) then Top := NewTop;
if (Rect.Left <> Left) then Left := Rect.Left;
if (Rect.Width <> Width) then Width := Rect.Right - Rect.Left;
end;
procedure TInspectorPropertyEdit.SetEditorActive(const Rect: TRect; const Value: string);
begin
if Assigned(OnExit) then OnExit(Self);
Text := Value;
SelectAll;
UpdateEditorPosition(Rect);
Visible := True;
SetFocus;
end;
procedure TInspectorPropertyEdit.SetEditorInActive;
begin
Visible := False;
end;
procedure TInspectorPropertyEditButton.UpdateEditorPosition(const Rect: TRect);
begin
var RectCenter := Rect.Top + (Rect.Height div 2);
var ButtonCenter := Height div 2;
var NewLeft := Rect.Right - Width + TextOffset;
var NewTop := RectCenter - ButtonCenter + 1;
if (Left <> NewLeft) then Left := NewLeft;
if (Top <> NewTop) then Top := NewTop;
end;
procedure TInspectorPropertyEditButton.SetEditorActive(const Rect: TRect);
begin
UpdateEditorPosition(Rect);
Visible := True;
end;
procedure TInspectorPropertyEditButton.SetEditorInActive;
begin
Visible := False;
end;
constructor TInspectorProperty.Create(Collection: TCollection);
begin
inherited Create(Collection);
FName := '';
FValue := '';
end;
procedure TInspectorProperty.Assign(Source: TPersistent);
begin
if (Source <> nil) and (Source is TInspectorProperty) then
begin
FName := (Source as TInspectorProperty).Name;
FValue := (Source as TInspectorProperty).Value;
FEditButton := (Source as TInspectorProperty).EditButton;
FTag := (Source as TInspectorProperty).Tag;
end;
end;
procedure TInspectorProperty.SetName(const Name: string);
begin
FName := Name;
Changed(False);
end;
procedure TInspectorProperty.SetValue(const Value: Variant);
begin
FValue := Value;
Changed(False);
end;
procedure TInspectorProperty.SetEditButton(const Button: Boolean);
begin
FEditButton := Button;
Changed(False);
end;
function TInspectorProperty.GetDisplayName: string;
begin
if (FName <> '') then
Result := FName
else
Result := inherited;
end;
function TInspectorPropertyCollection.GetItem(Index: Integer): TInspectorProperty;
begin
Result := inherited GetItem(Index) as TInspectorProperty;
end;
procedure TInspectorPropertyCollection.SetItem(Index: Integer; Value: TInspectorProperty);
begin
inherited SetItem(Index, Value);
end;
function TInspectorPropertyCollection.Add: TInspectorProperty;
begin
Result := TInspectorProperty(inherited Add);
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TInspectorPropertyCollection.Update(Item: TCollectionItem);
begin
inherited Update(Item);
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TInspectorPropertyCollection.Assign(Source: TPersistent);
var
LI : TInspectorPropertyCollection;
Loop : Integer;
begin
if (Source is TInspectorPropertyCollection) then
begin
LI := TInspectorPropertyCollection(Source);
Clear;
for Loop := 0 to LI.Count - 1 do Add.Assign(LI.Items[Loop]);
end else
inherited;
if Assigned(FOnChange) then FOnChange(Self);
end;
constructor TInspectorCategory.Create(Collection: TCollection);
begin
inherited Create(Collection);
FCaption := Format('Category %d', [Index]);
FCollapsed := False;
FProperties := TInspectorPropertyCollection.Create(Self, TInspectorProperty);
FProperties.OnChange := PropertiesChanged;
end;
destructor TInspectorCategory.Destroy;
begin
FProperties.Free;
inherited Destroy;
end;
procedure TInspectorCategory.Assign(Source: TPersistent);
begin
if (Source <> nil) and (Source is TInspectorCategory) then
begin
FCaption := (Source as TInspectorCategory).Caption;
FCollapsed := (Source as TInspectorCategory).Collapsed;
FProperties.Assign((Source as TInspectorCategory).Properties);
end;
end;
procedure TInspectorCategory.SetCaption(const Caption: TCaption);
begin
if (FCaption <> Caption) then
begin
FCaption := Caption;
Changed(False);
end;
end;
procedure TInspectorCategory.SetCollapsed(Collapsed: Boolean);
begin
if (FCollapsed <> Collapsed) then
begin
FCollapsed := Collapsed;
Changed(False);
end;
end;
procedure TInspectorCategory.PropertiesChanged(Sender: TObject);
begin
Changed(False);
end;
function TInspectorCategory.GetDisplayName: string;
begin
if (FCaption <> '') then
Result := FCaption
else
Result := inherited;
end;
function TInspectorCategoryCollection.GetItem(Index: Integer): TInspectorCategory;
begin
Result := inherited GetItem(Index) as TInspectorCategory;
end;
procedure TInspectorCategoryCollection.SetItem(Index: Integer; Value: TInspectorCategory);
begin
inherited SetItem(Index, Value);
end;
function TInspectorCategoryCollection.Add: TInspectorCategory;
begin
Result := TInspectorCategory(inherited Add);
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TInspectorCategoryCollection.Update(Item: TCollectionItem);
begin
inherited Update(Item);
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TInspectorCategoryCollection.Assign(Source: TPersistent);
var
LI : TInspectorCategoryCollection;
Loop : Integer;
begin
if (Source is TInspectorCategoryCollection) then
begin
LI := TInspectorCategoryCollection(Source);
Clear;
for Loop := 0 to LI.Count - 1 do Add.Assign(LI.Items[Loop]);
end else
inherited;
if Assigned(FOnChange) then FOnChange(Self);
end;
constructor TInspectorCategoryOptions.Create;
begin
inherited Create;
FHeight := CategoryHeight;
FColor := CategoryColor;
FShowFocusRect := True;
FFont := TFont.Create;
FFont.OnChange := FontChanged;
end;
destructor TInspectorCategoryOptions.Destroy;
begin
FFont.Free;
inherited Destroy;
end;
procedure TInspectorCategoryOptions.Assign(Source: TPersistent);
begin
inherited;
if (Source is TInspectorCategoryOptions) then
begin
FHeight := (Source as TInspectorCategoryOptions).Height;
FColor := (Source as TInspectorCategoryOptions).Color;
FShowFocusRect := (Source as TInspectorCategoryOptions).ShowFocusRect;
FFont.Assign((Source as TInspectorCategoryOptions).Font);
end;
end;
procedure TInspectorCategoryOptions.FontChanged(Sender: TObject);
begin
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TInspectorCategoryOptions.SetHeight(Height: Integer);
begin
if (FHeight <> Height) and (Height >= MinimalHeight) then
begin
FHeight := Height;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
procedure TInspectorCategoryOptions.SetColor(Color: TColor);
begin
if (FColor <> Color) then
begin
FColor := Color;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
procedure TInspectorCategoryOptions.SetShowFocusRect(Show: Boolean);
begin
if (FShowFocusRect <> Show) then
begin
FShowFocusRect := Show;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
constructor TInspectorPropertyOptions.Create;
begin
inherited Create;
FHeight := PropertyHeight;
FFont := TFont.Create;
FFont.OnChange := FontChanged;
end;
destructor TInspectorPropertyOptions.Destroy;
begin
FFont.Free;
inherited Destroy;
end;
procedure TInspectorPropertyOptions.Assign(Source: TPersistent);
begin
inherited;
if (Source is TInspectorPropertyOptions) then
begin
FHeight := (Source as TInspectorPropertyOptions).Height;
FFont.Assign((Source as TInspectorPropertyOptions).Font);
end;
end;
procedure TInspectorPropertyOptions.FontChanged(Sender: TObject);
begin
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TInspectorPropertyOptions.SetHeight(Height: Integer);
begin
if (FHeight <> Height) and (Height >= MinimalHeight) then
begin
FHeight := Height;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
constructor TInspectorGutterOptions.Create;
begin
inherited Create;
FWidth := GutterWidth;
FColor := GutterColor;
end;
destructor TInspectorGutterOptions.Destroy;
begin
inherited Destroy;
end;
procedure TInspectorGutterOptions.Assign(Source: TPersistent);
begin
inherited;
if (Source is TInspectorGutterOptions) then
begin
FWidth := (Source as TInspectorGutterOptions).Width;
FColor := (Source as TInspectorGutterOptions).Color;
end;
end;
procedure TInspectorGutterOptions.SetWidth(Width: Integer);
begin
if (FWidth <> Width) and (Width >= MinimalWidth) then
begin
FWidth := Width;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
procedure TInspectorGutterOptions.SetColor(Color: TColor);
begin
if (FColor <> Color) then
begin
FColor := Color;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
constructor TInspectorSplitter.Create;
begin
inherited Create;
FColor := SplitterColor;
FCursor := SplitterCursor;
FLeft := SplitterLeft;
end;
destructor TInspectorSplitter.Destroy;
begin
inherited Destroy;
end;
procedure TInspectorSplitter.Assign(Source: TPersistent);
begin
inherited;
if (Source is TInspectorSplitter) then
begin
FColor := (Source as TInspectorSplitter).Color;
FCursor := (Source as TInspectorSplitter).Cursor;
FLeft := (Source as TInspectorSplitter).Left;
end;
end;
procedure TInspectorSplitter.SetColor(Color: TColor);
begin
if (FColor <> Color) then
begin
FColor := Color;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
procedure TInspectorSplitter.SetCursor(Cursor: TCursor);
begin
if (FCursor <> Cursor) then
begin
FCursor := Cursor;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
procedure TInspectorSplitter.SetLeft(Left: Integer);
begin
if (FLeft <> Left) and (Left >= 0) then
begin
FLeft := Left;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
class constructor TInspector.Create;
begin
TCustomStyleEngine.RegisterStyleHook(TInspector, TScrollingStyleHook);
end;
class destructor TInspector.Destroy;
begin
TCustomStyleEngine.UnRegisterStyleHook(TInspector, TScrollingStyleHook);
end;
constructor TInspector.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csOpaque, csCaptureMouse, csClickEvents, csDoubleClicks, csReplicatable];
Color := clWindow;
TabStop := True;
FBuffer := TBitmap.Create;
FBuffer.PixelFormat := pf32bit;
FItemBuffer := TBitmap.Create;
FItemBuffer.PixelFormat := pf32Bit;
FUpdateCount := -1;
FScrollPos := 0;
FCategories := TInspectorCategoryCollection.Create(Self, TInspectorCategory);
Fcategories.OnChange := CategoriesChanged;
FCategoryOptions := TInspectorCategoryOptions.Create;
FCategoryOptions.OnChange := OptionsChanged;
FPropertyOptions := TInspectorPropertyOptions.Create;
FPropertyOptions.OnChange := OptionsChanged;
FGutterOptions := TInspectorGutterOptions.Create;
FGutterOptions.OnChange := OptionsChanged;
FSplitter := TInspectorSplitter.Create;
FSplitter.OnChange := OptionsChanged;
FInspectorEdit := TInspectorPropertyEdit.Create(Self);
FInspectorEdit.Font.Assign(PropertyOptions.Font);
FInspectorEdit.Top := -100;
FInspectorEdit.Parent := Self;
FInspectorEdit.Visible := False;
FInspectorEdit.OnKeyDown := OnPropertyEditorKeyDown;
FInspectorEdit.OnExit := OnPropertyEditorExit;
FInspectorEdit.OnChange := OnPropertyEditorChange;
FInspectorEditButton := TInspectorPropertyEditButton.Create(Self);
FInspectorEditButton.Font.Assign(PropertyOptions.Font);
FInspectorEditButton.Top := -100;
FInspectorEditButton.Width := ButtonWidth;
FInspectorEditButton.Height := PropertyOptions.Height - 2;
FInspectorEditButton.Caption := '…';
FInspectorEditButton.Parent := Self;
FInspectorEditButton.Visible := False;
FInspectorEditButton.OnClick := OnPropertyEditorButtonClick;
end;
destructor TInspector.Destroy;
begin
FBuffer.Free;
FItemBuffer.Free;
FCategories.Free;
FCategoryOptions.Free;
FPropertyOptions.Free;
FGutterOptions.Free;
FSplitter.Free;
FInspectorEdit.Free;
FInspectorEditButton.Free;
inherited Destroy;
end;
procedure TInspector.Assign(Source: TPersistent);
begin
inherited;
if (Source is TInspector) then
begin
FCategories.Assign((Source as TInspector).Categories);
FCategoryOptions.Assign((Source as TInspector).CategoryOptions);
FPropertyOptions.Assign((Source as TInspector).PropertyOptions);
FGutterOptions.Assign((Source as TInspector).GutterOptions);
FSplitter.Assign((Source as TInspector).Splitter);
end;
end;
procedure TInspector.Repaint;
begin
UpdateRects;
UpdateBuffer;
Invalidate;
end;
procedure TInspector.BeginUpdate;
begin
Inc(FUpdateCount);
end;
procedure TInspector.EndUpdate;
begin
Dec(FUpdateCount);
if (FUpdateCount <= -1) then
begin
UpdateRects;
UpdateBuffer;
Invalidate;
end;
end;
procedure TInspector.Clear;
begin
FCategories.Clear;
FScrollPos := 0;
ScrollPosUpdated;
end;
procedure TInspector.CategoriesChanged(Sender: TObject);
begin
if (FItemBuffer.Height < ClientHeight) and (FScrollPos > 0) then
begin
FScrollPos := 0;
ScrollPosUpdated;
Exit;
end;
UpdateRects;
UpdateBuffer;
Invalidate;
end;
procedure TInspector.OptionsChanged(Sender: TObject);
begin
FInspectorEdit.Font.Assign(PropertyOptions.Font);
FInspectorEditButton.Font.Assign(PropertyOptions.Font);
FInspectorEditButton.Height := PropertyOptions.Height - 2;
UpdateRects;
UpdateBuffer;
Invalidate;
end;
procedure TInspector.UpdateRects;
function CategoryTextRectOffset(const Rect: TRect): TRect;
begin
Result := TRect.Create(Rect);
Result.Left := Result.Left + TextOffset;
end;
function PropertyTextRectOffset(const Rect: TRect): TRect;
begin
Result := TRect.Create(Rect);
Result.Left := Result.Left + TextOffset;
Result.Right := Splitter.Left;
end;
function PropertyValueRectOffset(const Rect: TRect): TRect;
begin
Result := TRect.Create(Rect);
Result.Left := Result.Left + TextOffset;
end;
procedure FillItemBufferBackground;
var
S : TCustomStyleServices;
D : TThemedElementDetails;
C : TColor;
begin
S := StyleServices(Self);
if (Enabled and Focused) then
D := S.GetElementDetails(tcTransparentBackgroundFocused)
else
if (Enabled and not Focused) then
D := S.GetElementDetails(tcTransparentBackgroundNormal)
else
if not Enabled then
D := S.GetElementDetails(tcTransparentBackgroundDisabled);
if not S.GetElementColor(D, ecFillColor, C) then C := S.GetSystemColor(clWindow);
with FItemBuffer.Canvas do
begin
Brush.Color := C;
Brush.Style := bsSolid;
FillRect(TRect.Create(0, 0, FItemBuffer.Width, FItemBuffer.Height));
end;
end;
procedure DrawCategory(const Category: TInspectorCategory);
var
S : TCustomStyleServices;