Repository navigation
Expand file tree
/
Copy pathJvInspector.pas
More file actions
3027 lines (2792 loc) · 101 KB
/
Copy pathJvInspector.pas
File metadata and controls
3027 lines (2792 loc) · 101 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
{ This is not the original file: it has been modified for Inno Setup. }
{-----------------------------------------------------------------------------
Project JEDI Visible Component Library (J-VCL)
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Initial Developer of the Original Code is Marcel Bestebroer
<jedi_mbe (at) users (dot) sf (dot) net>.
Portions created by Marcel Bestebroer are Copyright (C) 2000 - 2002 mbeSoft.
All Rights Reserved.
The in-place editor's autocomplete is derived from JvAutoComplete.pas.
The Initial Developer of that Original Code is Andreas Hausladen
[Andreas dott Hausdaden att gmx dott de].
Portions created by Andreas Hausladen are Copyright (C) 2004 Andreas Hausladen.
All Rights Reserved.
******************************************************************************
You may retrieve the latest version of this file at the Project JEDI home
page, located at http://www.delphi-jedi.org
-----------------------------------------------------------------------------}
unit JvInspector;
interface
uses
SysUtils, Classes, Generics.Collections,
Windows, Messages, Graphics, Controls, StdCtrls, ImgList;
type
// early declarations
TJvInspector = class;
TJvCustomInspectorItem = class;
TJvInspectorCustomCategoryItem = class;
TJvInspectorListBox = class;
TInspectorItemFlag = (iifReadonly, iifExpanded, iifValueList, iifEditButton,
iifNameDblClickEvent);
TInspectorItemFlags = set of TInspectorItemFlag;
TInspectorPaintRect = (iprItem, iprExpandButton, iprMarker, iprNameArea,
iprNameGlyph, iprNameText, iprValueArea, iprValueGlyph, iprValueText,
iprValueEdit, iprValueButton);
TInspectorGlyphKind = (igkNone, igkImage, igkColor);
{ A small square painted before a row's name or value text }
TInspectorGlyph = record
Kind: TInspectorGlyphKind;
ImageList: TCustomImageList; { igkImage }
ImageName: string; { igkImage }
Color: TColor; { igkColor }
end;
TInspectorItemEvent = procedure(Item: TJvCustomInspectorItem) of object;
TInspectorItemGetGlyphEvent = procedure(Item: TJvCustomInspectorItem; var Glyph: TInspectorGlyph) of object;
TInspectorItemGetValueListEvent = procedure(Item: TJvCustomInspectorItem; Values: TStrings) of object;
TInspectorItemEditButtonClickEvent = procedure(Item: TJvCustomInspectorItem; var Value: string) of object;
TJvInspAsOrdinal = procedure(Sender: TJvCustomInspectorItem; var Value: Int64) of object;
TJvInspAsString = procedure(Sender: TJvCustomInspectorItem; var Value: string) of object;
TInspectorBeforeEditEvent = procedure(Sender: TObject; Item: TJvCustomInspectorItem; Edit: TEdit) of object;
EJvInspectorData = class(Exception);
TOnJvInspectorCustomizeItemCanvas = procedure(Item: TJvCustomInspectorItem; Canvas: TCanvas) of object;
TJvInspector = class(TCustomControl)
private
FDivider: Integer;
FDraggingDivider: Boolean;
FLockCount: Integer;
FNeedRebuild: Boolean;
FCategoryColor: TColor;
FCategoryDividerColor: TColor;
FCategoryTextColor: TColor;
FDividerColor: TColor;
FHideSelectColor: TColor;
FHideSelectTextColor: TColor;
FNameColor: TColor;
FOnCustomizeItemCanvas: TOnJvInspectorCustomizeItemCanvas;
FMarkedItem: TJvCustomInspectorItem;
FPaintItem: TJvCustomInspectorItem;
FPaintItemIndex: Integer;
FPaintRect: TRect;
FTextHeight: Integer;
FSelectedColor: TColor;
FSelectedTextColor: TColor;
FValueColor: TColor;
FPaintGen: Integer;
FReadOnly: Boolean;
FRoot: TJvCustomInspectorItem;
FSelectedIndex: Integer;
FPressedItem: TJvCustomInspectorItem;
FTopIndex: Integer;
FLastClientWidth: Integer;
FVisibleList: TList<TJvCustomInspectorItem>;
FVisibleTags: TDictionary<NativeInt, Integer>; { Item.Tag -> FVisibleList index }
FOnEditorKeyDown: TKeyEvent;
FOnNameDblClick: TInspectorItemEvent;
FOnGetAsOrdinal: TJvInspAsOrdinal;
FOnGetAsString: TJvInspAsString;
FOnSetAsOrdinal: TJvInspAsOrdinal;
FOnSetAsString: TJvInspAsString;
FOnGetValueList: TInspectorItemGetValueListEvent;
FOnGetNameGlyph: TInspectorItemGetGlyphEvent;
FOnGetValueGlyph: TInspectorItemGetGlyphEvent;
FOnEditButtonClick: TInspectorItemEditButtonClickEvent;
// BeforeEdit NOTE: - WAP
//
// This event fired is when creating TEdit objects, and
// allows end users to customize the properties of the editor
// objects, or hook event handlers, which were
// otherwise invisible. This could be used to ill effect, so beware.
FBeforeEdit: TInspectorBeforeEditEvent;
FMouseWheelAccum: Integer;
FAccessibleName: string;
function ApplicationHook(var Msg: TMessage): Boolean;
procedure ApplyNameFont;
procedure ApplyValueFont(const ACanvas: TCanvas);
procedure ChangeSelectedIndex(const OldItem: TJvCustomInspectorItem;
const OldIndex, NewIndex: Integer; const CancelEdits: Boolean);
procedure DoPaintItem;
procedure InvalidateItem(const Item: TJvCustomInspectorItem);
procedure InvalidateRow(const Index: Integer);
procedure PaintItem(var ARect: TRect; const AItemIndex: Integer);
procedure PaintItems;
procedure SetMarkedItem(const Value: TJvCustomInspectorItem);
procedure SetupRects(const AItem: TJvCustomInspectorItem;
const APaintRect: TRect);
procedure UpdateTextHeight;
protected
FAccObject: IInterface;
function CalcItemIndex(const Y: Integer): Integer;
procedure ChangeScale(M, D: Integer; isDpiChange: Boolean); override;
procedure CMActivate(var Msg: TCMActivate); message CM_ACTIVATE;
procedure CMDeactivate(var Msg: TCMActivate); message CM_DEACTIVATE;
procedure CMHintShow(var Msg: TCMHintShow); message CM_HINTSHOW;
procedure CreateParams(var Params: TCreateParams); override;
function GetBackgroundColor: TColor;
function GetImageHeight: Integer;
function GetItemHeight: Integer;
function GetLastFullVisible: Integer;
function GetMaxTopIndex: Integer;
function GetSelected: TJvCustomInspectorItem;
function GetVisibleCount: Integer;
function GetVisibleItems(const I: Integer): TJvCustomInspectorItem;
function IdxToY(const Index: Integer): Integer;
function InheritedFocused: Boolean;
procedure InvalidateList;
procedure InvalidateUnlessLocked;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
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, Y: Integer); override;
procedure Paint; override;
procedure RebuildVisible;
procedure BoundsChanged;
procedure SetBackgroundColor(const Value: TColor);
procedure SetDivider(Value: Integer);
procedure SetSelected(const Value: TJvCustomInspectorItem);
procedure SetSelectedIndex(Value: Integer);
procedure SetTopIndex(Value: Integer);
procedure UpdateScrollBars;
procedure WMGetObject(var Msg: TMessage); message WM_GETOBJECT;
procedure WMVScroll(var Msg: TWMScroll); message WM_VSCROLL;
procedure WndProc(var Msg: TMessage); override;
function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override;
function YToIdx(const Y: Integer): Integer;
property DraggingDivider: Boolean read FDraggingDivider write FDraggingDivider;
property LockCount: Integer read FLockCount;
property NeedRebuild: Boolean read FNeedRebuild write FNeedRebuild;
property PaintGeneration: Integer read FPaintGen;
property SelectedIndex: Integer read FSelectedIndex write SetSelectedIndex;
property TopIndex: Integer read FTopIndex write SetTopIndex;
public
constructor Create(AOwner: TComponent); override;
procedure BeforeDestruction; override;
procedure BeginUpdate;
procedure EndUpdate;
function EditorActive: Boolean;
function EditorActiveWithNothingToUndo: Boolean;
function Focused: Boolean; override;
procedure InvalidateItemByTag(const ATag: NativeInt);
procedure ResyncEditor;
procedure Clear;
property AccessibleName: string read FAccessibleName write FAccessibleName;
property Divider: Integer read FDivider write SetDivider;
property MarkedItem: TJvCustomInspectorItem read FMarkedItem write SetMarkedItem;
property PopupMenu;
property ReadOnly: Boolean read FReadOnly write FReadOnly;
property Root: TJvCustomInspectorItem read FRoot;
property Selected: TJvCustomInspectorItem read GetSelected write SetSelected;
property BeforeEdit: TInspectorBeforeEditEvent read FBeforeEdit write FBeforeEdit; // Low level hook for customizing TEdit after objects are created, just before editing.
property OnKeyDown; // Standard control event
{ Standard TCustomControl event - this is really an event fired by
the TEdit control used when editing in a cell!}
property OnEditorKeyDown: TKeyEvent read FOnEditorKeyDown write FOnEditorKeyDown;
{ Fired when the name area of a row without children, or of a row with
iifNameDblClickEvent, is double-clicked. Such a row is then not expanded
or collapsed. }
property OnNameDblClick: TInspectorItemEvent read FOnNameDblClick write FOnNameDblClick;
property OnGetAsOrdinal: TJvInspAsOrdinal read FOnGetAsOrdinal write FOnGetAsOrdinal;
property OnGetAsString: TJvInspAsString read FOnGetAsString write FOnGetAsString;
property OnSetAsOrdinal: TJvInspAsOrdinal read FOnSetAsOrdinal write FOnSetAsOrdinal;
property OnSetAsString: TJvInspAsString read FOnSetAsString write FOnSetAsString;
property OnGetValueList: TInspectorItemGetValueListEvent read FOnGetValueList write FOnGetValueList;
property OnGetNameGlyph: TInspectorItemGetGlyphEvent read FOnGetNameGlyph write FOnGetNameGlyph;
property OnGetValueGlyph: TInspectorItemGetGlyphEvent read FOnGetValueGlyph write FOnGetValueGlyph;
property OnEditButtonClick: TInspectorItemEditButtonClickEvent read FOnEditButtonClick write FOnEditButtonClick;
property BackgroundColor: TColor read GetBackgroundColor write SetBackgroundColor;
property CategoryColor: TColor read FCategoryColor write FCategoryColor;
property CategoryDividerColor: TColor read FCategoryDividerColor write FCategoryDividerColor;
property CategoryTextColor: TColor read FCategoryTextColor write FCategoryTextColor;
property DividerColor: TColor read FDividerColor write FDividerColor;
property HideSelectColor: TColor read FHideSelectColor write FHideSelectColor;
property HideSelectTextColor: TColor read FHideSelectTextColor write FHideSelectTextColor;
property NameColor: TColor read FNameColor write FNameColor;
property SelectedColor: TColor read FSelectedColor write FSelectedColor;
property SelectedTextColor: TColor read FSelectedTextColor write FSelectedTextColor;
property ValueColor: TColor read FValueColor write FValueColor;
property OnCustomizeItemCanvas: TOnJvInspectorCustomizeItemCanvas read FOnCustomizeItemCanvas write FOnCustomizeItemCanvas;
end;
TJvCustomInspectorItem = class(TObject)
private
FDisplayName: string;
FDroppedDown: Boolean;
FEditCtrlDestroying: Boolean;
FEditCtrl: TEdit;
FEditWndPrc: TWndMethod;
FEditing: Boolean;
FFlags: TInspectorItemFlags;
FInspector: TJvInspector;
FItems: TObjectList<TJvCustomInspectorItem>;
FListBox: TJvInspectorListBox;
FListBoxFilled: Boolean;
FNameGlyph: TInspectorGlyph;
FOnGetValueList: TInspectorItemGetValueListEvent;
FParent: TJvCustomInspectorItem;
FLastPaintGen: Integer;
FPressed: Boolean;
FRects: array [TInspectorPaintRect] of TRect;
FTag: NativeInt;
FTracking: Boolean;
FUpdateEditCtrl: Integer; // Used to prevent EditCtrl destruction while in Apply().
FValueGlyph: TInspectorGlyph;
protected
procedure Apply;
procedure CancelPress; virtual;
function CanEdit: Boolean;
procedure CloseUp(Accept: Boolean);
procedure DrawGlyph(const ACanvas: TCanvas; const AGlyph: TInspectorGlyph;
const AGlyphRect, AClipRect: TRect);
procedure DoDropDownKeys(var Key: Word; Shift: TShiftState);
procedure DropDown;
procedure EditButtonClick;
procedure EditFocusLost(Sender: TObject);
procedure EditKeyPress(Sender: TObject; var Key: Char);
procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); dynamic;
procedure EditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); dynamic;
procedure EditMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Edit_WndProc(var Msg: TMessage);
procedure AutoComplete(var Key: Char);
function GetAsOrdinal: Int64;
function GetAsString: string;
function GetBaseCategory: TJvCustomInspectorItem;
function GetCount: NativeInt;
function GetDisplayValue: string; virtual;
function GetExpanded: Boolean;
function GetGlyph(const AEvent: TInspectorItemGetGlyphEvent): TInspectorGlyph;
function GetItems(const I: NativeInt): TJvCustomInspectorItem;
function GetLevel: Integer;
function GetReadOnly: Boolean;
function GetRects(const RectKind: TInspectorPaintRect): TRect;
function GetValueEditHitRect: TRect;
procedure GetValueList(const Strings: TStrings);
procedure InvalidateItem;
procedure SetAsOrdinal(Value: Int64);
procedure SetAsString(Value: string);
procedure InvalidateList;
function IsCategory: Boolean; virtual;
procedure ListValueSelect(Sender: TObject);
procedure ListDeactivate(Sender: TObject);
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); virtual;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); virtual;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;
procedure SelectValue(const Delta: Integer);
procedure SetDisplayValue(const Value: string); virtual;
procedure SetEditCtrl(const Value: TEdit);
procedure SetExpanded(Value: Boolean);
procedure SetFlags(const Value: TInspectorItemFlags); virtual;
procedure SetFocus;
procedure SetRects(const RectKind: TInspectorPaintRect; Value: TRect);
procedure StopTracking;
procedure TrackButton(X, Y: Integer);
procedure Undo;
property AsOrdinal: Int64 read GetAsOrdinal write SetAsOrdinal;
property AsString: string read GetAsString write SetAsString;
property DroppedDown: Boolean read FDroppedDown;
property EditCtrlDestroying: Boolean read FEditCtrlDestroying;
property EditCtrl: TEdit read FEditCtrl;
property EditWndPrc: TWndMethod read FEditWndPrc;
property LastPaintGeneration: Integer read FLastPaintGen;
property ListBox: TJvInspectorListBox read FListBox;
property NameGlyph: TInspectorGlyph read FNameGlyph;
property Pressed: Boolean read FPressed write FPressed;
property Tracking: Boolean read FTracking write FTracking;
property ValueGlyph: TInspectorGlyph read FValueGlyph;
public
constructor Create(const AParent: TJvCustomInspectorItem);
procedure BeforeDestruction; override;
procedure DrawValue(const ACanvas: TCanvas); virtual;
procedure InitEdit; dynamic;
procedure DoneEdit(const CancelEdits: Boolean = False); dynamic;
procedure ScrollInView(const ACenter: Boolean);
property Count: NativeInt read GetCount;
property DisplayName: string read FDisplayName write FDisplayName;
property DisplayValue: string read GetDisplayValue write SetDisplayValue;
property Editing: Boolean read FEditing;
property Expanded: Boolean read GetExpanded write SetExpanded;
property Flags: TInspectorItemFlags read FFlags write SetFlags;
property Inspector: TJvInspector read FInspector;
property Items[const I: NativeInt]: TJvCustomInspectorItem read GetItems; default;
property Level: Integer read GetLevel;
{ Per-item override of the inspector's OnGetValueList }
property OnGetValueList: TInspectorItemGetValueListEvent read FOnGetValueList write FOnGetValueList;
property Parent: TJvCustomInspectorItem read FParent;
property ReadOnly: Boolean read GetReadOnly;
property Rects[const RectKind: TInspectorPaintRect]: TRect read GetRects write SetRects;
property Tag: NativeInt read FTag write FTag;
end;
TJvInspectorCustomCategoryItem = class(TJvCustomInspectorItem)
protected
function IsCategory: Boolean; override;
procedure SetFlags(const Value: TInspectorItemFlags); override;
end;
TJvInspectorStringItem = class(TJvCustomInspectorItem)
protected
function GetDisplayValue: string; override;
procedure SetDisplayValue(const Value: string); override;
end;
TJvInspectorBooleanItem = class(TJvCustomInspectorItem)
public
const IndeterminateOrdinal = 2; { AsOrdinal value showing an indeterminate checkbox }
private
FClickRect: TRect;
FCheckPressed: Boolean;
FCheckTracking: Boolean;
FCheckKeyPressed: Boolean;
protected
procedure CancelPress; override;
procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); override;
procedure EditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 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 Toggle;
public
procedure DoneEdit(const CancelEdits: Boolean = False); override;
procedure DrawValue(const ACanvas: TCanvas); override;
procedure InitEdit; override;
end;
TJvInspectorListBox = class(TCustomListBox)
private
FOnValueSelect: TNotifyEvent;
FOnDeactivate: TNotifyEvent;
FNCClick: Boolean;
FClicking: Boolean;
FItem: TJvCustomInspectorItem;
FSearchText: string;
FSearchTickCount: UInt64;
FMouseWheelAccum: Integer;
procedure UpdateSelectedItem(const ClientPos: TPoint);
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure KeyPress(var Key: Char); 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 WMMouseWheel(var Msg: TWMMouseWheel); message WM_MOUSEWHEEL;
public
property OnValueSelect: TNotifyEvent read FOnValueSelect write FOnValueSelect;
property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate;
property Item: TJvCustomInspectorItem read FItem write FItem;
end;
implementation
uses
System.UITypes,
Character, Types, Forms, Themes,
PathFunc,
JvInspector.MSAA, OleAccFunc;
const
BackSpace = #8;
Esc = #27;
{ The checkbox size and the gap between it and its label, at 96 DPI. Both
glyph kinds use the gap and a color square uses the size; the value column
also reserves the size as its minimum glyph width, so a value row lines up
with a checkbox row. }
CheckBoxSize = 13;
CheckBoxLabelGap = 4;
resourcestring
RsJvInspItemValueException = 'Exception ';
RsEJvInspDataNoAccessAs = 'Data cannot be accessed as %s';
//============================================================================
function CanvasMaxTextHeight(Canvas: TCanvas): Integer;
var
tt: TTextMetric;
begin
GetTextMetrics(Canvas.Handle, tt);
Result := tt.tmHeight;
end;
{ With VCL Styles active, DrawElement changes the DC's selected objects
and colors, and does not restore them }
procedure DrawElementPreservingDCState(DC: HDC;
const Details: TThemedElementDetails; const R: TRect; DPI: Integer = 0);
var
SaveIndex: Integer;
begin
SaveIndex := SaveDC(DC);
try
StyleServices.DrawElement(DC, Details, R, nil, DPI);
finally
RestoreDC(DC, SaveIndex);
end;
end;
function DrawThemedFrameControl(DC: HDC; const Rect: TRect;
uType, uState: UINT; DPI: Integer = 0): BOOL;
const
Mask = $00FF;
var
Btn: TThemedButton;
ComboBox: TThemedComboBox;
R: TRect;
begin
Result := False;
if StyleServices.Enabled and (uType = DFC_SCROLL) and
((uState and Mask) = DFCS_SCROLLCOMBOBOX) then begin
R := Rect;
if uState and DFCS_PUSHED <> 0 then begin
{ Not all VCL Styles have an actual image for this, and will just show a
regular checkbox. This includes 'Windows11 Modern Dark'. In
TSeButtonObject.Draw variable FState is correctly set to ssPressed,
but FBitmapPressed.Assigned is False. }
ComboBox := tcDropDownButtonPressed
end else
ComboBox := tcDropDownButtonNormal;
DrawElementPreservingDCState(DC, StyleServices.GetElementDetails(ComboBox), R, DPI);
Result := True;
end else if StyleServices.Enabled and (uType = DFC_BUTTON) and
((uState and Mask) = DFCS_BUTTONCHECK) then begin
R := Rect;
if uState and DFCS_CHECKED <> 0 then
if uState and DFCS_PUSHED <> 0 then
Btn := tbCheckBoxCheckedPressed
else
Btn := tbCheckBoxCheckedNormal
else if uState and DFCS_PUSHED <> 0 then
Btn := tbCheckBoxUncheckedPressed { See above }
else
Btn := tbCheckBoxUncheckedNormal;
DrawElementPreservingDCState(DC, StyleServices.GetElementDetails(Btn), R, DPI);
Result := True;
end else if StyleServices.Enabled and (uType = DFC_BUTTON) and
((uState and Mask) = DFCS_BUTTON3STATE) then begin
R := Rect;
if uState and DFCS_CHECKED <> 0 then
if uState and DFCS_PUSHED <> 0 then
Btn := tbCheckBoxMixedPressed { See above }
else
Btn := tbCheckBoxMixedNormal
else if uState and DFCS_PUSHED <> 0 then
Btn := tbCheckBoxUncheckedPressed { See above }
else
Btn := tbCheckBoxUncheckedNormal;
DrawElementPreservingDCState(DC, StyleServices.GetElementDetails(Btn), R, DPI);
Result := True;
end else if StyleServices.Enabled and (uType = DFC_BUTTON) and
((uState and Mask) = DFCS_BUTTONPUSH) then begin
R := Rect;
if uState and DFCS_PUSHED <> 0 then
Btn := tbPushButtonPressed
else
Btn := tbPushButtonNormal;
DrawElementPreservingDCState(DC, StyleServices.GetElementDetails(Btn), R, DPI);
Result := True;
end;
if not Result then
Result := DrawFrameControl(DC, Rect, uType, uState);
end;
function WheelScrollTopIndex(var Accumulator: Integer; const WheelDelta,
CurrentTopIndex: Integer; PageScrollLines: Integer): Integer;
{ Returns the top index a wheel scroll should move to, keeping any leftover
delta in Accumulator as required by
https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mousewheel }
begin
{ Sanity check }
if PageScrollLines < 1 then
PageScrollLines := 1;
{ Mouse.WheelScrollLines stays 0 if no wheel was present at VCL startup, so
prefer SPI_GETWHEELSCROLLLINES }
var Lines: Integer; // 0 = don't scroll, -1 = WHEEL_PAGESCROLL
if not SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, Lines, 0) then
Lines := Mouse.WheelScrollLines;
{ Lines > PageScrollLines: see SPI_SETWHEELSCROLLLINES in
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfow }
if (Lines < 0) or (Lines > PageScrollLines) then
Lines := PageScrollLines;
Inc(Accumulator, WheelDelta * Lines);
const Count = Accumulator div WHEEL_DELTA;
Dec(Accumulator, Count * WHEEL_DELTA);
Result := CurrentTopIndex - Count;
if Result < 0 then
Result := 0;
end;
//=== { TJvInspector } =================================================
function TJvInspector.ApplicationHook(var Msg: TMessage): Boolean;
begin
Result := False;
// Forward the application's activate/deactivate to this inspector so the
// selected row repaints in its focused/unfocused style and an open dropdown
// closes
if (Msg.Msg = CM_ACTIVATE) or (Msg.Msg = CM_DEACTIVATE) then
if HandleAllocated then
PostMessage(Handle, Msg.Msg, 0, 0);
end;
constructor TJvInspector.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle + [csOpaque];
{$IFNDEF DEBUG}
DoubleBuffered := True;
{$ENDIF}
FVisibleList := TList<TJvCustomInspectorItem>.Create;
FVisibleTags := TDictionary<NativeInt, Integer>.Create;
FRoot := TJvCustomInspectorItem.Create(nil);
FRoot.FInspector := Self;
FSelectedIndex := -1;
TabStop := True;
Width := 300;
Height := 100;
Divider := 75;
BackgroundColor := clWindow;
FCategoryColor := clBtnFace;
FCategoryTextColor := clBtnText;
FCategoryDividerColor := clBtnShadow;
FDividerColor := clBtnFace;
FNameColor := clWindowText;
FValueColor := clWindowText;
FSelectedColor := clHighlight;
FSelectedTextColor := clHighlightText;
FHideSelectColor := clBtnFace;
FHideSelectTextColor := clBtnText;
Application.HookMainWindow(ApplicationHook);
end;
procedure TJvInspector.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or WS_CLIPCHILDREN;
end;
function TJvInspector.CalcItemIndex(const Y: Integer): Integer;
begin
if Y < 0 then
Result := -1
else begin
Result := TopIndex + Y div GetItemHeight;
if Result >= GetVisibleCount then
Result := -1;
end;
end;
procedure TJvInspector.ChangeScale(M, D: Integer; isDpiChange: Boolean);
begin
inherited;
if M <> D then
FDivider := MulDiv(FDivider, M, D);
end;
procedure TJvInspector.CMActivate(var Msg: TCMActivate);
begin
inherited;
InvalidateRow(SelectedIndex);
end;
procedure TJvInspector.CMDeactivate(var Msg: TCMActivate);
begin
inherited;
if Selected <> nil then
Selected.CancelPress;
InvalidateRow(SelectedIndex);
end;
procedure TJvInspector.CMHintShow(var Msg: TCMHintShow);
function TextIsClipped(const AItem: TJvCustomInspectorItem;
const AText: string; const AAvailableWidth: Integer): Boolean;
begin
Canvas.Font := Font;
if Assigned(FOnCustomizeItemCanvas) then
FOnCustomizeItemCanvas(AItem, Canvas);
Result := Canvas.TextWidth(AText) > AAvailableWidth;
end;
begin
inherited;
const HintInfo = Msg.HintInfo;
const X = HintInfo.CursorPos.X;
const Index = CalcItemIndex(HintInfo.CursorPos.Y);
const Item = GetVisibleItems(Index);
if Item <> nil then begin
const NameAreaLeft = Item.Rects[iprNameArea].Left;
const NameAreaRight = Item.Rects[iprNameArea].Right;
const ValueAreaLeft = Item.Rects[iprValueArea].Left;
const ValueAreaRight = Item.Rects[iprValueArea].Right;
var HintStr := '';
var HintAreaLeft := 0;
var HintAreaRight := 0;
if (X >= NameAreaLeft) and (X < NameAreaRight) then begin
if TextIsClipped(Item, Item.DisplayName, Item.Rects[iprNameText].Width) then
HintStr := Item.DisplayName;
HintAreaLeft := NameAreaLeft;
HintAreaRight := NameAreaRight;
end else if (X >= ValueAreaLeft) and (X < ValueAreaRight) and
not Item.Editing and not (Item is TJvInspectorBooleanItem) then begin
var Value: string;
try
Value := Item.DisplayValue;
except
Value := '';
end;
if TextIsClipped(Item, Value, Item.Rects[iprValueText].Width) then
HintStr := Value;
HintAreaLeft := ValueAreaLeft;
HintAreaRight := ValueAreaRight;
end;
if HintStr <> '' then begin
HintInfo.HintStr := HintStr;
const HintAreaTop = IdxToY(Index - TopIndex);
HintInfo.CursorRect := Rect(HintAreaLeft, HintAreaTop, HintAreaRight,
HintAreaTop + GetItemHeight);
HintInfo.HideTimeout := High(Integer); { infinite }
end;
end;
end;
function TJvInspector.GetImageHeight: Integer;
begin
Result := GetVisibleCount * GetItemHeight;
end;
function TJvInspector.GetItemHeight: Integer;
begin
Result := MulDiv(18, CurrentPPI, 96);
end;
function TJvInspector.GetLastFullVisible: Integer;
begin
Result := YToIdx(IdxToY(TopIndex) + Pred(ClientHeight));
if Result < 0 then
Result := Pred(GetVisibleCount)
else if Result > TopIndex + Pred(ClientHeight div GetItemHeight) then
Result := TopIndex + Pred(ClientHeight div GetItemHeight);
end;
function TJvInspector.GetMaxTopIndex: Integer;
begin
if GetImageHeight <= ClientHeight then
Result := 0 { Everything fits: no scrolling, so TopIndex must be 0 and not 1 }
else
Result := Succ(YToIdx(GetImageHeight - ClientHeight));
end;
function TJvInspector.GetSelected: TJvCustomInspectorItem;
begin
Result := GetVisibleItems(SelectedIndex);
end;
function TJvInspector.GetVisibleCount: Integer;
begin
Result := Integer(FVisibleList.Count);
end;
function TJvInspector.GetVisibleItems(const I: Integer): TJvCustomInspectorItem;
begin
if (I < 0) or (I >= FVisibleList.Count) then
Result := nil
else
Result := FVisibleList[I];
end;
function TJvInspector.IdxToY(const Index: Integer): Integer;
begin
Result := Index * GetItemHeight;
end;
procedure TJvInspector.InvalidateItem(const Item: TJvCustomInspectorItem);
begin
if (LockCount = 0) and HandleAllocated then
InvalidateRow(Integer(FVisibleList.IndexOf(Item)));
end;
procedure TJvInspector.InvalidateItemByTag(const ATag: NativeInt);
begin
var Index: Integer;
if (LockCount = 0) and HandleAllocated and
FVisibleTags.TryGetValue(ATag, Index) then
InvalidateRow(Index);
end;
procedure TJvInspector.InvalidateList;
begin
if not (csDestroying in ComponentState) and (LockCount = 0) then begin
if HandleAllocated then begin
RebuildVisible;
TopIndex := TopIndex; //the list may have shrunk
UpdateScrollBars;
Invalidate;
end else
NeedRebuild := True;
end else
NeedRebuild := True;
end;
procedure TJvInspector.InvalidateRow(const Index: Integer);
begin
if HandleAllocated then begin
const Y = IdxToY(Index - TopIndex);
if (Y >= 0) and (Y < ClientHeight) then begin
var R := Rect(0, Y, ClientWidth, Y + GetItemHeight);
Windows.InvalidateRect(Handle, @R, False);
end;
end;
end;
procedure TJvInspector.InvalidateUnlessLocked;
begin
if (LockCount = 0) and HandleAllocated then
Invalidate;
end;
procedure TJvInspector.KeyDown(var Key: Word; Shift: TShiftState);
var
Item: TJvCustomInspectorItem;
TmpIdx: Integer;
begin
Item := Selected;
if Shift = [] then begin
var IgnoreKey := True; // reset to False below for unhandled keys
case Key of
VK_UP:
if SelectedIndex > 0 then
SelectedIndex := SelectedIndex - 1;
VK_DOWN:
if SelectedIndex < Pred(GetVisibleCount) then
SelectedIndex := SelectedIndex + 1;
VK_PRIOR:
begin
if SelectedIndex > TopIndex then
SelectedIndex := TopIndex
else if SelectedIndex > 0 then begin
TmpIdx := YToIdx(IdxToY(SelectedIndex) + GetItemHeight - ClientHeight); { Also see WMVScroll }
if TmpIdx < 0 then
TmpIdx := 0;
SelectedIndex := TmpIdx;
end;
end;
VK_NEXT:
begin
TmpIdx := GetLastFullVisible;
if SelectedIndex < TmpIdx then
SelectedIndex := TmpIdx
else if SelectedIndex < Pred(GetVisibleCount) then
SelectedIndex := SelectedIndex + ClientHeight div GetItemHeight; { Also see WMVScroll }
end;
VK_RIGHT:
if (Item <> nil) and (Item.Count > 0) then begin
if not Item.Expanded then
Item.Expanded := True
else
SelectedIndex := SelectedIndex + 1;
end;
VK_LEFT:
if Item <> nil then begin
if Item.Expanded then
Item.Expanded := False
else begin
const ParentIndex = Integer(FVisibleList.IndexOf(Item.Parent));
if ParentIndex >= 0 then
SelectedIndex := ParentIndex;
end;
end;
VK_RETURN, VK_SPACE:
if (Item <> nil) and not Item.Editing then begin
if (Item.Count > 0) and not Item.Expanded then
Item.Expanded := True
else if Item.Expanded then
Item.Expanded := False;
end else
IgnoreKey := False;
else
IgnoreKey := False;
end;
if IgnoreKey then begin
Key := 0;
SendMessage(Handle, WM_CHANGEUISTATE, UIS_CLEAR or (UISF_HIDEFOCUS shl 16), 0);
end;
end;
if (Key <> 0) and ((Shift = []) or (Shift = [ssCtrl])) then begin
var IgnoreKey := True;
case Key of
VK_ADD:
if (Item <> nil) and (Item.Count > 0) and not Item.Expanded then
Item.Expanded := True;
VK_SUBTRACT:
if (Item <> nil) and Item.Expanded then
Item.Expanded := False;
else
IgnoreKey := False;
end;
if IgnoreKey then begin
Key := 0;
SendMessage(Handle, WM_CHANGEUISTATE, UIS_CLEAR or (UISF_HIDEFOCUS shl 16), 0);
end;
end;
inherited;
Item := Selected;
if (Item <> nil) and Item.Editing then begin
Item.ScrollInView(False);
Item.EditKeyDown(Self, Key, Shift);
end;
end;
procedure TJvInspector.KeyUp(var Key: Word; Shift: TShiftState);
begin
inherited;
const Item = Selected;
if (Item <> nil) and Item.Editing then
Item.EditKeyUp(Self, Key, Shift);
end;
procedure TJvInspector.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
ItemIndex: Integer;
Item: TJvCustomInspectorItem;
begin
inherited;
ItemIndex := CalcItemIndex(Y);
Item := GetVisibleItems(ItemIndex);
if not Focused and ((Item = nil) or (not Item.Editing)) then
SetFocus
else if (Item <> nil) and Item.Editing then
Item.SetFocus;
if (Button = mbRight) and (Item <> nil) and (ItemIndex <> SelectedIndex) then
SelectedIndex := ItemIndex;
if Button = mbLeft then begin
// Check divider dragging
if (X >= Pred(Divider)) and (X <= Succ(Divider)) then
DraggingDivider := True
// Check selecting
else if (Item <> nil) and (ItemIndex <> SelectedIndex) then
SelectedIndex := ItemIndex;
const Expandable = (Item <> nil) and
((Item.Count > 0) or (iifExpanded in Item.Flags));
const FireNameDblClick = (Item <> nil) and (ssDouble in Shift) and
not Item.IsCategory and (not Expandable or (iifNameDblClickEvent in Item.Flags)) and
Assigned(FOnNameDblClick) and
PtInRect(Item.Rects[iprNameArea], Point(X, Y));
if Expandable and not FireNameDblClick then begin
if PtInRect(Item.Rects[iprExpandButton], Point(X, Y)) or
((ssDouble in Shift) and (Item.IsCategory or (X < Pred(Divider)))) then
Item.Expanded := not Item.Expanded;
end;
if (Item <> nil) and (PtInRect(Item.Rects[iprNameArea], Point(X, Y)) or
PtInRect(Item.Rects[iprValueArea], Point(X, Y))) then begin
FPressedItem := Item;
Item.MouseDown(Button, Shift, X, Y);
end;
// A click on the value of an item that was not being edited yet lands on
// the inspector, not the freshly focused edit, so the edit can't start a
// click-drag selection. Forward the click to the edit so it places the
// caret and captures the mouse for dragging, like the Delphi object
// inspector (when the item was already being edited the click lands on the
// edit itself and never gets here). Hand the whole gesture to the edit:
// drop the inspector's own pressed-item, button-down and capture state,
// since it gets no matching MouseUp once the edit captures and would
// otherwise fire a stray click or keep following the mouse.
if not (ssDouble in Shift) and not DraggingDivider and
(Item <> nil) and Item.Editing and (Item.EditCtrl <> nil) and
Item.EditCtrl.HandleAllocated and Item.EditCtrl.CanFocus and
PtInRect(Item.GetValueEditHitRect, Point(X, Y)) then begin
FPressedItem := nil;
ControlState := ControlState - [csLButtonDown, csClicked];
MouseCapture := False;
const Keys = MK_LBUTTON or (Ord(ssShift in Shift) * MK_SHIFT) or
(Ord(ssCtrl in Shift) * MK_CONTROL);
Item.EditCtrl.Perform(WM_LBUTTONDOWN, WPARAM(Keys),
PointToLParam(Point(X - Item.EditCtrl.Left, Y - Item.EditCtrl.Top)));
end;
if FireNameDblClick then begin
FPressedItem := nil; // The handler may change focus or rebuild the items
FOnNameDblClick(Item);
end;
end;
end;
procedure TJvInspector.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited;
if DraggingDivider then
Divider := X
else if FPressedItem <> nil then begin
Cursor := crDefault;
FPressedItem.MouseMove(Shift, X, Y);
end
else if (X >= Pred(Divider)) and (X <= Succ(Divider)) then
Cursor := crHSplit
else begin
const Item = GetVisibleItems(CalcItemIndex(Y));
if (Item <> nil) and Item.CanEdit and not (Item is TJvInspectorBooleanItem) and
not Item.Editing and PtInRect(Item.GetValueEditHitRect, Point(X, Y)) then
Cursor := crIBeam
else
Cursor := crDefault;
end
end;
procedure TJvInspector.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;
if Button = mbLeft then begin
if DraggingDivider then
DraggingDivider := False;
if FPressedItem <> nil then begin
const Item = FPressedItem;
FPressedItem := nil;
Item.MouseUp(Button, Shift, X, Y);
end;
end;
end;
procedure TJvInspector.UpdateTextHeight;
begin
Canvas.Font := Font;
FTextHeight := CanvasMaxTextHeight(Canvas);
end;
procedure TJvInspector.Paint;
begin
if NeedRebuild then
InvalidateList;
Inc(FPaintGen);
UpdateTextHeight;
Canvas.Brush.Color := BackgroundColor;
PaintItems;
end;
procedure TJvInspector.RebuildVisible;
var