-
Notifications
You must be signed in to change notification settings - Fork 321
/
JvDBGrid.pas
5488 lines (5069 loc) · 171 KB
/
JvDBGrid.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
{-----------------------------------------------------------------------------
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/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvDBGrid.PAS, released on 2002-07-04.
The Initial Developers of the Original Code are: Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 1997, 1998 Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 2001,2002 SGB Software
All Rights Reserved.
Contributor(s):
Polaris Software
Lionel Reynaud
Flemming Brandt Clausen
Frédéric Leneuf-Magaud
Andreas Hausladen
Ronald Hoek
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.delphi-jedi.org
-----------------------------------------------------------------------------
INFO: Draw events are triggered in this order:
- Title cells:
OnGetBtnParams
OnDrawColumnTitle
- Data cells:
OnGetCellParams
OnDrawColumnCell
OnGetCellProps and OnDrawDataCell are obsolete.
-----------------------------------------------------------------------------
KNOWN ISSUES:
- THE ColLines OPTION DOES NOT WORK WELL WITH HIDDEN COLUMNS - BUG SOURCE: DBGRID.PAS
If a column is followed by hidden columns and ColLines is set to False, the display size
of the column is smaller than its width. This is easy to notice when you give the focus
to the cell (the focus rect is truncated) or when you use the AutoSize feature (there's
a gap after the last column). This bug comes from DBGrid.pas.
-----------------------------------------------------------------------------
2004/07/08 - WPostma merged changes by Frédéric Leneuf-Magaud and ahuser.}
// $Id$
unit JvDBGrid;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Types,
Windows, Messages, Classes, Graphics, Controls, Grids, Menus, DBGrids, DB,
StdCtrls, Forms, Contnrs,
{$IFDEF HAS_UNIT_SYSTEM_UITYPES}
System.UITypes,
{$ENDIF HAS_UNIT_SYSTEM_UITYPES}
JvTypes, {JvTypes contains Exception base class}
JvAppStorage, JvFormPlacement, JvExDBGrids, JvDBUtils;
const
DefJvGridOptions = [dgEditing, dgTitles, dgIndicator, dgColumnResize,
dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit
{$IFDEF COMPILER14_UP}
, dgTitleClick, dgTitleHotTrack
{$ENDIF COMPILER14_UP}];
{$NODEFINE DefJvGridOptions}
JvDefaultAlternateRowColor = TColor($00CCCCCC); // Light gray
JvDefaultAlternateRowFontColor = TColor($00000000); // Black
// Consts for AutoSizeColumnIndex
JvGridResizeProportionally = -1;
JvGridResizeLastVisibleCol = -2;
type
TJvDBGrid = class;
// Mantis 3895: The only way to lift an ambiguity in an event handler is to
// redefine a type. A simple rename is not enough, hence the distinction
// between BCB and the others.
{$IFDEF BCB}
TJvDBGridBitmap = class(TBitmap)
end;
{$ELSE}
{$IFDEF DELPHI10_UP}
TJvDBGridBitmap = class(TBitmap)
end;
{$ELSE}
TJvDBGridBitmap = TBitmap;
{$ENDIF DELPHI10_UP}
{$ENDIF BCB}
TJvDBGridColumnResize = (gcrNone, gcrGrid, gcrDataSet);
TJvDBGridCellHintPosition = (gchpDefault, gchpMouse);
TSelectColumn = (scDataBase, scGrid);
TTitleClickEvent = procedure(Sender: TObject; ACol: Longint;
Field: TField) of object;
TCheckTitleBtnEvent = procedure(Sender: TObject; ACol: Longint;
Field: TField; var Enabled: Boolean) of object;
TGetCellParamsEvent = procedure(Sender: TObject; Field: TField;
AFont: TFont; var Background: TColor; Highlight: Boolean) of object;
TSortMarker = (smNone, smDown, smUp);
TGetBtnParamsEvent = procedure(Sender: TObject; Field: TField;
AFont: TFont; var Background: TColor; var ASortMarker: TSortMarker;
IsDown: Boolean) of object;
TGetCellPropsEvent = procedure(Sender: TObject; Field: TField;
AFont: TFont; var Background: TColor) of object; { obsolete }
TJvDBEditShowEvent = procedure(Sender: TObject; Field: TField;
var AllowEdit: Boolean) of object;
TDrawColumnTitleEvent = procedure(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; AColumn: TColumn; var ASortMarker: TJvDBGridBitmap; IsDown: Boolean;
var Offset: Integer; var DefaultDrawText,
DefaultDrawSortMarker: Boolean) of object;
TJvTitleHintEvent = procedure(Sender: TObject; Field: TField;
var AHint: string; var ATimeOut: Integer) of object;
TJvCellHintEvent = TJvTitleHintEvent;
TJvDBColumnResizeEvent = procedure(Grid: TJvDBGrid; ACol: Longint; NewWidth: Integer) of object;
TJvDBCheckIfBooleanFieldEvent = function(Grid: TJvDBGrid; Field: TField;
var StringForTrue: string; var StringForFalse: string): Boolean of object;
TJvDBCanEditCellEvent = procedure(Grid: TJvDBGrid; Field: TField; var AllowEdit: Boolean) of object;
TJvDBSelectColumnsEvent = procedure(Grid: TJvDBGrid; var DefaultDialog: Boolean) of object;
TJvDBGridColumnLookupInfo = record
IsLookup: Boolean;
KeyFields: string;
LookupDataSet: TDataSet;
LookupKeyFields: string;
LookupResultField: string;
end;
TJvDBGridGetColumnLookupInfo = procedure(Sender: TObject; Column: TColumn; var
LookupInfo: TJvDBGridColumnLookupInfo) of object;
TJvDBGridLayoutChangeKind = (lcLayoutChanged, lcSizeChanged, lcTopLeftChanged);
TJvDBGridLayoutChangeEvent = procedure(Grid: TJvDBGrid; Kind: TJvDBGridLayoutChangeKind) of object;
TJvDBGridLayoutChangeLink = class
private
FOnChange: TJvDBGridLayoutChangeEvent;
public
procedure DoChange(Grid: TJvDBGrid; Kind: TJvDBGridLayoutChangeKind);
property OnChange: TJvDBGridLayoutChangeEvent read FOnChange write FOnChange;
end;
EJVCLDbGridException = Class(EJVCLException);
TJvSelectDialogColumnStrings = class(TPersistent)
private
FCaption: string;
FRealNamesOption: string;
FOK: string;
FNoSelectionWarning: string;
public
constructor Create;
published
property Caption: string read FCaption write FCaption;
property RealNamesOption: string read FRealNamesOption write FRealNamesOption;
property OK: string read FOK write FOK;
property NoSelectionWarning: string read FNoSelectionWarning write FNoSelectionWarning;
end;
TJvDBGridControlSize = (
fcCellSize, // Fit the control into the cell
fcDesignSize, // Leave the control as it was at design time
fcBiggest // Take the biggest size between Cell size and Design time size
);
TJvDBGridControl = class(TCollectionItem)
private
FControlName: string;
FFieldName: string;
FFitCell: TJvDBGridControlSize;
FLeaveOnEnterKey: Boolean;
FLeaveOnUpDownKey: Boolean;
FDesignWidth: Integer; // value set when needed by PlaceControl
FDesignHeight: Integer; // value set when needed by PlaceControl
public
procedure Assign(Source: TPersistent); override;
published
property ControlName: string read FControlName write FControlName;
property FieldName: string read FFieldName write FFieldName;
property FitCell: TJvDBGridControlSize read FFitCell write FFitCell;
property LeaveOnEnterKey: Boolean read FLeaveOnEnterKey write FLeaveOnEnterKey default False;
property LeaveOnUpDownKey: Boolean read FLeaveOnUpDownKey write FLeaveOnUpDownKey default False;
end;
TJvDBGridControls = class(TCollection)
private
FParentDBGrid: TJvDBGrid;
function GetItem(Index: Integer): TJvDBGridControl;
procedure SetItem(Index: Integer; Value: TJvDBGridControl);
protected
function GetOwner: TPersistent; override;
public
constructor Create(ParentDBGrid: TJvDBGrid);
function Add: TJvDBGridControl;
function ControlByField(const FieldName: string): TJvDBGridControl;
function ControlByName(const CtrlName: string): TJvDBGridControl;
property Items[Index: Integer]: TJvDBGridControl read GetItem write SetItem; default;
end;
TJvGridPaintInfo = record
MouseInCol: Integer; // the column that the mouse is in
ColPressed: Boolean; // a column has been pressed
ColPressedIdx: Integer; // idx of the pressed column
ColSizing: Boolean; // currently sizing a column
ColMoving: Boolean; // currently moving a column
end;
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvDBGrid = class(TJvExDBGrid, IJvDataControl)
private
FAutoSort: Boolean;
FBeepOnError: Boolean;
FAutoAppend: Boolean;
FSizingIndex: Integer;
FSizingOfs: Integer;
FShowGlyphs: Boolean;
FDefaultDrawing: Boolean;
FReduceFlicker: Boolean;
FMultiSelect: Boolean;
FSelecting: Boolean;
FClearSelection: Boolean;
FTitleButtons: Boolean;
FPressedCol: TColumn;
FPressed: Boolean;
FTracking: Boolean;
FSwapButtons: Boolean;
FIniLink: TJvIniLink;
FDisableCount: Integer;
FFixedCols: Integer;
FOnCheckButton: TCheckTitleBtnEvent;
FOnGetCellProps: TGetCellPropsEvent;
FOnGetCellParams: TGetCellParamsEvent;
FOnGetBtnParams: TGetBtnParamsEvent;
FOnEditChange: TNotifyEvent;
FOnTitleBtnClick: TTitleClickEvent;
FOnTitleBtnDblClick: TTitleClickEvent;
FOnTopLeftChanged: TNotifyEvent;
FSelectionAnchor: {$IFDEF RTL200_UP}TBookmark{$ELSE}TBookmarkStr{$ENDIF RTL200_UP};
FOnDrawColumnTitle: TDrawColumnTitleEvent;
FWord: string;
FShowTitleHint: Boolean;
FSortedField: string;
FPostOnEnterKey: Boolean;
FSelectColumn: TSelectColumn;
FTitleArrow: Boolean;
FTitleArrowDown: Boolean;
FTitlePopup: TPopupMenu;
FOnShowTitleHint: TJvTitleHintEvent;
FOnTitleArrowMenuEvent: TNotifyEvent;
FAlternateRowColor: TColor;
FAlternateRowFontColor: TColor;
FAutoSizeColumns: Boolean;
FAutoSizeColumnIndex: Integer;
FMinColumnWidth: Integer;
FMaxColumnWidth: Integer;
FInAutoSize: Boolean;
FSelectColumnsDialogStrings: TJvSelectDialogColumnStrings;
FTitleColumn: TColumn;
FOnColumnResized: TJvDBColumnResizeEvent;
FSortMarker: TSortMarker;
FShowCellHint: Boolean;
FOnShowCellHint: TJvCellHintEvent;
{$IFDEF COMPILER9_UP}
FScrollBars: TScrollStyle;
{$ENDIF COMPILER9_UP}
FWordWrap: Boolean;
FWordWrapAllFields: Boolean;
FChangeLinks: TObjectList;
FShowMemos: Boolean;
FOnShowEditor: TJvDBEditShowEvent;
FAlwaysShowEditor: Boolean;
FOnGetColumnLookupInfo: TJvDBGridGetColumnLookupInfo;
FControls: TJvDBGridControls;
FCurrentControl: TWinControl;
FOldControlWndProc: TWndMethod;
FBooleanFieldToEdit: TField;
FBooleanEditor: Boolean;
FOnCheckIfBooleanField: TJvDBCheckIfBooleanFieldEvent;
FStringForTrue: string;
FStringForFalse: string;
FAutoSizeRows: Boolean;
FRowResize: Boolean;
FRowsHeight: Integer;
FTitleRowHeight: Integer;
FCellHintPosition: TJvDBGridCellHintPosition;
FCanDelete: Boolean;
{ Cancel edited record on mouse wheel or when resize column (double-click)}
FCancelOnMouse: Boolean;
{ Resize column using mouse double clicking }
FCanResizeColumn: Boolean;
FResizeColumnIndex: Longint;
FColumnResize: TJvDBGridColumnResize;
// XP Theming
{$IFNDEF COMPILER14_UP}
FUseXPThemes: Boolean;
{$ENDIF ~COMPILER14_UP}
FUseThemedHighlighting: Boolean;
FPaintInfo: TJvGridPaintInfo;
FCell: TGridCoord; // currently selected cell
FTitleButtonAllowMove: Boolean;
FReadOnlyCellColor: TColor;
FOnCanEditCell: TJvDBCanEditCellEvent;
FOnSelectColumns: TJvDBSelectColumnsEvent;
FOnBeforePaint: TNotifyEvent;
FOnAfterPaint: TNotifyEvent;
FOnBeforeMouseDown: TMouseEvent;
FOnAfterMouseDown: TMouseEvent;
FMouseDownEvent: TMouseEvent; // only valid while in MouseDown, contains the original OnMouseDown event
FDelphi2010OptionsMigrated: Boolean;
procedure ReadDelphi2010OptionsMigrated(Reader: TReader);
procedure WriteDelphi2010OptionsMigrated(Writer: TWriter);
{$IFDEF COMPILER10_UP}
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
{$ENDIF COMPILER10_UP}
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure SetAutoSizeRows(Value: Boolean);
procedure SetRowResize(Value: Boolean);
procedure SetRowsHeight(Value: Integer);
procedure SetTitleRowHeight(Value: Integer);
procedure WriteCellText(ARect: TRect; DX, DY: Integer; const Text: string;
Alignment: TAlignment; ARightToLeft: Boolean; FixCell: Boolean; Options: Integer = 0);
function GetImageIndex(Field: TField): Integer;
procedure SetShowGlyphs(Value: Boolean);
function GetStorage: TJvFormPlacement;
procedure SetStorage(Value: TJvFormPlacement);
procedure IniSave(Sender: TObject);
procedure IniLoad(Sender: TObject);
procedure SetMultiSelect(Value: Boolean);
procedure SetTitleButtons(Value: Boolean);
procedure StopTracking;
procedure TrackButton(X, Y: Integer);
function ActiveRowSelected: Boolean;
function GetSelCount: Longint;
function GetRow: Longint;
procedure SetRow(Value: Longint);
procedure SaveColumnsLayout(const AppStorage: TJvCustomAppStorage; const Section: string);
procedure RestoreColumnsLayout(const AppStorage: TJvCustomAppStorage; const Section: string);
function GetOptions: TDBGridOptions;
procedure SetOptions(Value: TDBGridOptions);
function GetMasterColumn(ACol, ARow: Longint): TColumn;
function GetTitleOffset: Integer;
procedure SetFixedCols(Value: Integer);
function GetFixedCols: Integer;
function CalcLeftColumn: Integer;
procedure WMChar(var Msg: TWMChar); message WM_CHAR;
procedure WMCancelMode(var Msg: TMessage); message WM_CANCELMODE;
procedure WMRButtonUp(var Msg: TWMMouse); message WM_RBUTTONUP;
procedure CMHintShow(var Msg: TCMHintShow); message CM_HINTSHOW;
procedure SetTitleArrow(const Value: Boolean);
procedure SetAlternateRowColor(const Value: TColor);
procedure ReadAlternateRowColor(Reader: TReader);
procedure SetAlternateRowFontColor(const Value: TColor);
procedure ReadAlternateRowFontColor(Reader: TReader);
procedure SetAutoSizeColumnIndex(const Value: Integer);
procedure SetAutoSizeColumns(const Value: Boolean);
procedure SetMaxColumnWidth(const Value: Integer);
procedure SetMinColumnWidth(const Value: Integer);
procedure SetSelectColumnsDialogStrings(const Value: TJvSelectDialogColumnStrings);
procedure SetSortedField(const Value: string);
procedure SetSortMarker(const Value: TSortMarker);
procedure WMVScroll(var Msg: TWMVScroll); message WM_VSCROLL;
procedure SetShowMemos(const Value: Boolean);
procedure SetBooleanEditor(const Value: Boolean);
{$IFDEF COMPILER9_UP}
procedure SetScrollBars(Value: TScrollStyle);
{$ENDIF COMPILER9_UP}
procedure ReadPostOnEnter(Reader: TReader);
procedure SetControls(Value: TJvDBGridControls);
procedure HideCurrentControl;
procedure ControlWndProc(var Message: TMessage);
procedure ChangeBoolean(const FieldValueChange: Shortint);
function EditWithBoolBox(Field: TField): Boolean; {$IFDEF DELPHI9} inline; {$ENDIF DELPHI9}
function DoKeyPress(var Msg: TWMChar): Boolean;
procedure SetWordWrap(Value: Boolean);
procedure SetWordWrapAllFields(Value: Boolean);
procedure NotifyLayoutChange(const Kind: TJvDBGridLayoutChangeKind);
// XP Theming
function GetUseXPThemes: Boolean;
procedure SetUseXPThemes(Value: Boolean);
{$IFNDEF COMPILER14_UP}
{$IFDEF JVCLThemesEnabled}
function ColumnOffset: Integer; // col offset used for calculations. Is 1 if indicator is being displayed
function ValidCell(ACell: TGridCoord): Boolean;
{$ENDIF JVCLThemesEnabled}
{$ENDIF ~COMPILER14_UP}
function GetMaxDisplayText: string;
function GetColumnMaxWidth: Integer;
protected
FCurrentDrawRow: Integer;
procedure MouseLeave(Control: TControl); override;
function AcquireFocus: Boolean;
function CanEditShow: Boolean; override;
function CanEditCell(AField: TField): Boolean; virtual;
function CreateEditor: TInplaceEdit; override;
procedure DblClick; override;
function DoTitleBtnDblClick: Boolean; dynamic;
procedure ShowSelectColumnClick; dynamic;
function IsInLookupCharList(Key: Char): Boolean; virtual;
// Custom lookup dataset
function GetColumnLookupInfo(Column: TColumn): TJvDBGridColumnLookupInfo;
virtual;
function CanEditModify: Boolean; override;
function GetEditStyle(ACol: Integer; ARow: Integer): TEditStyle; override;
procedure DoTitleClick(ACol: Longint; AField: TField); dynamic;
procedure CheckTitleButton(ACol, ARow: Longint; var Enabled: Boolean); dynamic;
function SortMarkerAssigned(const AFieldName: string): Boolean; dynamic;
function ChangeSortMarker(const Value: TSortMarker): Boolean;
procedure CallDrawCellEvent(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
procedure DrawTitleCaption(Canvas: TCanvas; const TextRect: TRect; DrawColumn: TColumn);
procedure DoDrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); virtual;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
procedure DrawDataCell(const Rect: TRect; Field: TField; State: TGridDrawState); override; { obsolete from Delphi 2.0 }
function DrawThemedHighlighting(ACanvas: TCanvas; R: TRect): Boolean; virtual;
function GetPaintInfo: TJvGridPaintInfo;
function BeginColumnDrag(var Origin: Integer; var Destination: Integer; const MousePt: TPoint): Boolean; override;
procedure ColumnMoved(FromIndex: Integer; ToIndex: Integer); override;
function AllowTitleClick: Boolean; virtual;
procedure EditChanged(Sender: TObject); dynamic;
procedure GetCellProps(Column: TColumn; AFont: TFont; var Background: TColor;
Highlight: Boolean); dynamic;
function HighlightCell(DataCol, DataRow: Integer; const Value: string;
AState: TGridDrawState): Boolean; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure SetColumnAttributes; override;
procedure DoBeforeMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;
procedure DoAfterMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;
procedure HandleMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;
procedure MouseDownEventHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
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;
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
procedure Scroll(Distance: Integer); override;
procedure LinkActive(Value: Boolean); override;
{$IFDEF COMPILER9_UP}
procedure UpdateScrollBar; override;
{$ENDIF COMPILER9_UP}
procedure LayoutChanged; override;
procedure TopLeftChanged; override;
procedure GridInvalidateRow(Row: Longint);
procedure DrawColumnCell(const Rect: TRect; DataCol: Integer;
Column: TColumn; State: TGridDrawState); override;
procedure ColWidthsChanged; override;
function DoEraseBackground(Canvas: TCanvas; Param: LPARAM): Boolean; override;
procedure Paint; override;
procedure CalcSizingState(X, Y: Integer; var State: TGridState;
var Index: Longint; var SizingPos, SizingOfs: Integer;
var FixedInfo: TGridDrawInfo); override;
procedure DoDrawColumnTitle(ACanvas: TCanvas; ARect: TRect; AColumn: TColumn;
var ASortMarker: TJvDBGridBitmap; IsDown: Boolean; var Offset: Integer;
var DefaultDrawText, DefaultDrawSortMarker: Boolean); virtual;
procedure ColEnter; override;
procedure ColExit; override;
function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override;
procedure EditButtonClick; override;
procedure CellClick(Column: TColumn); override;
procedure DefineProperties(Filer: TFiler); override;
procedure DoMinColWidth; virtual;
procedure DoMaxColWidth; virtual;
procedure DoAutoSizeColumns; virtual;
procedure Resize; override;
procedure Loaded; override;
function GetMinColWidth(Default: Integer): Integer;
function GetMaxColWidth(Default: Integer): Integer;
function LastVisibleColumn: Integer;
function FirstVisibleColumn: Integer;
procedure TitleClick(Column: TColumn); override;
procedure DoGetBtnParams(Field: TField; AFont: TFont; var Background: TColor;
var ASortMarker: TSortMarker; IsDown: Boolean); virtual;
procedure PlaceControl(Control: TWinControl; ACol, ARow: Integer); virtual;
procedure RowHeightsChanged; override;
function GetDataLink: TDataLink; virtual;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
public
{$IFDEF SUPPORTS_CLASS_CTORDTORS}
class destructor Destroy;
{$ENDIF SUPPORTS_CLASS_CTORDTORS}
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DefaultDrawColumnCell(const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); virtual;
procedure DefaultDataCellDraw(const Rect: TRect; Field: TField; State: TGridDrawState);
procedure DisableScroll;
procedure EnableScroll;
function ScrollDisabled: Boolean;
procedure MouseToCell(X, Y: Integer; var ACol, ARow: Longint);
procedure SelectAll;
procedure UnselectAll;
procedure ToggleRowSelection;
procedure GotoSelection(Index: Longint);
procedure LoadFromAppStore(const AppStorage: TJvCustomAppStorage; const Path: string);
procedure SaveToAppStore(const AppStorage: TJvCustomAppStorage; const Path: string);
procedure Load;
procedure Save;
procedure UpdateTabStops(ALimit: Integer = -1);
procedure ShowColumnsDialog;
procedure CloseControl; // Hide the current edit control and give the focus to the grid
procedure InitializeColumnsWidth(const MinWidth, MaxWidth: Integer;
const DisplayWholeTitle: Boolean; const FixedWidths: array of Integer);
procedure MouseWheelHandler(var Message: TMessage); override;
procedure RegisterLayoutChangeLink(Link: TJvDBGridLayoutChangeLink);
procedure UnregisterLayoutChangeLink(Link: TJvDBGridLayoutChangeLink);
procedure BeginUpdate;
procedure EndUpdate;
function CellRect(ACol, ARow: Longint): TRect;
property SelectedRows;
property SelCount: Longint read GetSelCount;
property Canvas;
property Col;
property InplaceEditor;
property LeftCol;
property Row: Longint read GetRow write SetRow;
property CurrentDrawRow: Integer read FCurrentDrawRow;
property VisibleRowCount;
property VisibleColCount;
property IndicatorOffset;
property TitleOffset: Integer read GetTitleOffset;
published
property AutoAppend: Boolean read FAutoAppend write FAutoAppend default True;
property SortMarker: TSortMarker read FSortMarker write SetSortMarker default smNone;
property AutoSort: Boolean read FAutoSort write FAutoSort default True;
property Options: TDBGridOptions read GetOptions write SetOptions default DefJvGridOptions;
property FixedCols: Integer read GetFixedCols write SetFixedCols default 0;
property ClearSelection: Boolean read FClearSelection write FClearSelection default True;
property DefaultDrawing: Boolean read FDefaultDrawing write FDefaultDrawing default True;
property IniStorage: TJvFormPlacement read GetStorage write SetStorage;
property MultiSelect: Boolean read FMultiSelect write SetMultiSelect default False;
property ShowGlyphs: Boolean read FShowGlyphs write SetShowGlyphs default True;
property TitleButtons: Boolean read FTitleButtons write SetTitleButtons default False;
property TitleButtonAllowMove: Boolean read FTitleButtonAllowMove write FTitleButtonAllowMove default False;
property OnCheckButton: TCheckTitleBtnEvent read FOnCheckButton write FOnCheckButton;
property OnGetCellProps: TGetCellPropsEvent read FOnGetCellProps write FOnGetCellProps; { obsolete }
property OnGetCellParams: TGetCellParamsEvent read FOnGetCellParams write FOnGetCellParams;
property OnGetBtnParams: TGetBtnParamsEvent read FOnGetBtnParams write FOnGetBtnParams;
property OnEditChange: TNotifyEvent read FOnEditChange write FOnEditChange;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
property OnShowEditor: TJvDBEditShowEvent read FOnShowEditor write FOnShowEditor;
property OnTitleBtnClick: TTitleClickEvent read FOnTitleBtnClick write FOnTitleBtnClick;
property OnTitleBtnDblClick: TTitleClickEvent read FOnTitleBtnDblClick write FOnTitleBtnDblClick;
property OnTopLeftChanged: TNotifyEvent read FOnTopLeftChanged write FOnTopLeftChanged;
property OnDrawColumnTitle: TDrawColumnTitleEvent read FOnDrawColumnTitle write FOnDrawColumnTitle;
property OnContextPopup;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnMouseWheelDown;
property OnMouseWheelUp;
property BeepOnError: Boolean read FBeepOnError write FBeepOnError default True;
property AlternateRowColor: TColor read FAlternateRowColor write SetAlternateRowColor default clNone;
property AlternateRowFontColor: TColor read FAlternateRowFontColor write SetAlternateRowFontColor default clNone;
property PostOnEnterKey: Boolean read FPostOnEnterKey write FPostOnEnterKey default False;
{$IFDEF COMPILER9_UP}
property ScrollBars: TScrollStyle read FScrollBars write SetScrollBars default ssBoth;
{$ENDIF COMPILER9_UP}
property SelectColumn: TSelectColumn read FSelectColumn write FSelectColumn default scDataBase;
property SortedField: string read FSortedField write SetSortedField;
property ShowTitleHint: Boolean read FShowTitleHint write FShowTitleHint default False;
property TitleArrow: Boolean read FTitleArrow write SetTitleArrow default False;
property TitlePopup: TPopupMenu read FTitlePopup write FTitlePopup;
property OnShowTitleHint: TJvTitleHintEvent read FOnShowTitleHint write FOnShowTitleHint;
property OnTitleArrowMenuEvent: TNotifyEvent read FOnTitleArrowMenuEvent write FOnTitleArrowMenuEvent;
property ShowCellHint: Boolean read FShowCellHint write FShowCellHint default False;
property OnShowCellHint: TJvCellHintEvent read FOnShowCellHint write FOnShowCellHint;
property MaxColumnWidth: Integer read FMaxColumnWidth write SetMaxColumnWidth default 0;
property MinColumnWidth: Integer read FMinColumnWidth write SetMinColumnWidth default 0;
property AutoSizeColumns: Boolean read FAutoSizeColumns write SetAutoSizeColumns default False;
property AutoSizeColumnIndex: Integer read FAutoSizeColumnIndex write SetAutoSizeColumnIndex
default JvGridResizeProportionally;
property SelectColumnsDialogStrings: TJvSelectDialogColumnStrings
read FSelectColumnsDialogStrings write SetSelectColumnsDialogStrings;
{ Determines how cell hint position is calculated, check TJvDBGrid.CMHintShow (Mantis #5759) }
property CellHintPosition: TJvDBGridCellHintPosition read FCellHintPosition write FCellHintPosition default gchpDefault;
{ Allows user to delete things using the "del" key }
property CanDelete: Boolean read FCanDelete write FCanDelete default True;
{ CancelOnMouse: cancel current record when using mouse wheel or on column resizing using double-click }
property CancelOnMouse: Boolean read FCancelOnMouse write FCancelOnMouse default False;
{ ColumnResize: columns can be resized on max Field.DisplayText using mouse double clicking }
property ColumnResize: TJvDBGridColumnResize read FColumnResize write FColumnResize default gcrGrid;
{ EditControls: list of controls used to edit data }
property EditControls: TJvDBGridControls read FControls write SetControls;
{ AutoSizeRows: are rows resized automatically ? }
property AutoSizeRows: Boolean read FAutoSizeRows write SetAutoSizeRows default True;
{ ReduceFlicker: improve (but slow) the display when painting/scrolling ? }
property ReduceFlicker: Boolean read FReduceFlicker write FReduceFlicker default True;
{ RowResize: can rows be resized with the mouse ? }
property RowResize: Boolean read FRowResize write SetRowResize default False;
{ RowsHeight: data rows height }
property RowsHeight: Integer read FRowsHeight write SetRowsHeight;
{ TitleRowHeight: title row height (cannot be resized with the mouse) }
property TitleRowHeight: Integer read FTitleRowHeight write SetTitleRowHeight;
{ WordWrap: if true, titles, memo and string fields are displayed on several lines }
property WordWrap: Boolean read FWordWrap write SetWordWrap default False;
{ WordWrapAllFields: if true and WordWrap is true, not only memo and string fields are displayed on several lines }
property WordWrapAllFields: Boolean read FWordWrapAllFields write SetWordWrapAllFields default False;
{ ShowMemos: if true, memo fields are shown as text }
property ShowMemos: Boolean read FShowMemos write SetShowMemos default True;
{ BooleanEditor: if true, a checkbox is used to edit boolean fields }
property BooleanEditor: Boolean read FBooleanEditor write SetBooleanEditor default True;
{ UseXPThemes: if true, the grid is painted in the active XP theme style }
property UseXPThemes: Boolean read GetUseXPThemes write SetUseXPThemes {$IFDEF COMPILER14_UP} stored False{$ENDIF} default True;
{ UseThemedHighlighting: if true, the grid's cell selection is painted with the styling color }
property UseThemedHighlighting: Boolean read FUseThemedHighlighting write FUseThemedHighlighting default True;
{ OnCheckIfBooleanField: event used to treat integer fields and string fields as boolean fields }
property OnCheckIfBooleanField: TJvDBCheckIfBooleanFieldEvent read FOnCheckIfBooleanField write FOnCheckIfBooleanField;
{ OnColumnResized: event triggered each time a column is resized with the mouse }
property OnColumnResized: TJvDBColumnResizeEvent read FOnColumnResized write FOnColumnResized;
{ ReadOnlyCellColor: The color of the cells that are read only => OnCanEditCell, not Field.CanModify }
property ReadOnlyCellColor: TColor read FReadOnlyCellColor write FReadOnlyCellColor default clDefault;
{ OnCanEditCell: event used to control the appearance of editor and cell background }
property OnCanEditCell: TJvDBCanEditCellEvent read FOnCanEditCell write FOnCanEditCell;
{ OnSelectColumns: event is triggered when the user clicks on the TitleArrow button. }
property OnSelectColumns: TJvDBSelectColumnsEvent read FOnSelectColumns write FOnSelectColumns;
{ OnBeforePaint: event triggered before the grid is painted. }
property OnBeforePaint: TNotifyEvent read FOnBeforePaint write FOnBeforePaint;
{ OnBeforePaint: event triggered after the grid was painted. }
property OnAfterPaint: TNotifyEvent read FOnAfterPaint write FOnAfterPaint;
{ OnBeforeMouseDown is called before handing MouseDown }
property OnBeforeMouseDown: TMouseEvent read FOnBeforeMouseDown write FOnBeforeMouseDown;
{ OnBeforeMouseDown is called after handing MouseDown }
property OnAfterMouseDown: TMouseEvent read FOnAfterMouseDown write FOnAfterMouseDown;
{ OnGetColumnLookupInfo is called whenever lookupinfo might be needed }
property OnGetColumnLookupInfo: TJvDBGridGetColumnLookupInfo read
FOnGetColumnLookupInfo write FOnGetColumnLookupInfo;
end;
var
// UseThemedHighlighting changes how grids look and if the application wants to be rendered with
// the classic highlighting, all grids can be reverted with JvDBGridDisableUseThemedHighlighting = True
JvDBGridDisableUseThemedHighlighting: Boolean = False;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$URL$';
Revision: '$Revision$';
Date: '$Date$';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
Variants, SysUtils, Math, TypInfo, Dialogs, DBConsts, StrUtils,
JvDBLookup,
JvConsts, JvResources, JvThemes, JvJCLUtils, JvJVCLUtils,
{$IFDEF COMPILER16_UP}
Themes,
{$ENDIF COMPILER16_UP}
{$IFDEF COMPILER7_UP}
// => TScrollDirection, DrawArray(must be after JvJVCLUtils)
{$ENDIF COMPILER7_UP}
{$IFDEF HAS_UNIT_CHARACTER}
Character,
{$ENDIF HAS_UNIT_CHARACTER}
JvDBGridSelectColumnForm, JclSysUtils;
{$R JvDBGrid.res}
type
TBookmarks = class(TBookmarkList);
TGridPicture = (gpBlob, gpMemo, gpPicture, gpOle, gpObject, gpData,
gpNotEmpty, gpMarkDown, gpMarkUp, gpChecked, gpUnChecked, gpPopup);
{$IFNDEF COMPILER7_UP}
TScrollDirection = (sdLeft, sdRight, sdUp, sdDown);
{$ENDIF ~COMPILER7_UP}
TCustomGridAccess = class(TCustomGrid);
const
GridBmpNames: array [TGridPicture] of PChar =
('JvDBGridBLOB', 'JvDBGridMEMO', 'JvDBGridPICT', 'JvDBGridOLE', 'JvDBGridOBJECT',
'JvDBGridDATA', 'JvDBGridNOTEMPTY', 'JvDBGridSMDOWN', 'JvDBGridSMUP',
'JvDBGridCHECKED', 'JvDBGridUNCHECKED', 'JvDBGridPOPUP');
bmMultiDot = 'JvDBGridMSDOT';
bmMultiArrow = 'JvDBGridMSARROW';
// Consts for ChangeBoolean
JvGridBool_INVERT = 9;
JvGridBool_CHECK = 0;
JvGridBool_UNCHECK = -1;
var
GridBitmaps: array [TGridPicture] of TJvDBGridBitmap =
(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil);
FirstGridBitmaps: Boolean = True;
MsIndicators: TImageList;
procedure FinalizeGridBitmaps;
var
I: TGridPicture;
begin
FreeAndNil(MsIndicators);
for I := Low(TGridPicture) to High(TGridPicture) do
FreeAndNil(GridBitmaps[I]);
end;
function GetGridBitmap(BmpType: TGridPicture): TJvDBGridBitmap;
begin
if GridBitmaps[BmpType] = nil then
begin
if FirstGridBitmaps then
FirstGridBitmaps := False;
GridBitmaps[BmpType] := TJvDBGridBitmap.Create;
GridBitmaps[BmpType].LoadFromResourceName(HInstance, GridBmpNames[BmpType]);
end;
Result := GridBitmaps[BmpType];
end;
function DrawBiDiText(DC: HDC; const Text: string; var R: TRect; Flags: UINT;
Alignment: TAlignment; RightToLeft: Boolean; CanvasOrientation: TCanvasOrientation): Integer;
const
AlignFlags: array [TAlignment] of UINT = (DT_LEFT, DT_RIGHT, DT_CENTER);
RTL: array [Boolean] of UINT = (0, DT_RTLREADING);
begin
if CanvasOrientation = coRightToLeft then
ChangeBiDiModeAlignment(Alignment);
Result := Windows.DrawText(DC, PChar(Text), Length(Text), R,
AlignFlags[Alignment] or RTL[RightToLeft] or Flags);
end;
function IsMemoField(AField: TField): Boolean; {$IFDEF SUPPORTS_INLINE} inline; {$ENDIF}
begin
Result := AField.DataType in [ftMemo {$IFDEF COMPILER10_UP}, ftWideMemo {$ENDIF}];
end;
function LookupInfoValid(const LookupInfo: TJvDBGridColumnLookupInfo): Boolean;
begin
Result :=
(LookupInfo.LookupDataSet <> nil) and (LookupInfo.LookupResultField <> '') and
(LookupInfo.LookupKeyFields <> '') and (LookupInfo.KeyFields <> '');
end;
//=== { TInternalInplaceEdit } ===============================================
type
TInternalInplaceEdit = class(TInplaceEditList)
private
FDataList: TJvDBLookupList; // TDBLookupListBox
FUseDataList: Boolean;
FLookupSource: TDataSource;
protected
procedure CloseUp(Accept: Boolean); override;
procedure DoEditButtonClick; override;
procedure DropDown; override;
procedure UpdateContents; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
MousePos: TPoint): Boolean; override;
public
constructor Create(Owner: TComponent); override;
property DataList: TJvDBLookupList read FDataList; // TDBLookupListBox
property OnChange;
end;
constructor TInternalInplaceEdit.Create(Owner: TComponent);
begin
inherited Create(Owner);
FLookupSource := TDataSource.Create(Self);
end;
procedure TInternalInplaceEdit.CloseUp(Accept: Boolean);
var
Column: TColumn;
MasterField: TField;
ListValue: Variant;
begin
if ListVisible then
begin
if GetCapture <> 0 then
SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
if ActiveList = DataList then
ListValue := DataList.KeyValue
else
if PickList.ItemIndex <> -1 then
ListValue := PickList.Items[PickList.ItemIndex]
else
ListValue := Null;
SetWindowPos(ActiveList.Handle, 0, 0, 0, 0, 0, SWP_NOZORDER or
SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
ListVisible := False;
if Assigned(FDataList) then
FDataList.LookupSource := nil; // ListSource
FLookupSource.DataSet := nil;
Invalidate;
if Accept then
if ActiveList = DataList then
begin
Column := TDBGrid(Grid).Columns[TCustomDBGrid(Grid).SelectedIndex];
MasterField := Column.Field.DataSet.FieldByName(TJvDBGrid(Grid).GetColumnLookupInfo(Column).KeyFields);
if MasterField.CanModify and (Grid as IJvDataControl).GetDataLink.Edit then
MasterField.Value := ListValue;
end
else
if (not VarIsNull(ListValue)) and EditCanModify then
TDBGrid(Grid).Columns[TCustomDBGrid(Grid).SelectedIndex].Field.Text := ListValue;
end;
end;
procedure TInternalInplaceEdit.DoEditButtonClick;
begin
TJvDBGrid(Grid).EditButtonClick; // TCustomDBGrid
end;
procedure TInternalInplaceEdit.DropDown;
var
Column: TColumn;
LookupInfo: TJvDBGridColumnLookupInfo;
begin
if not ListVisible then
begin
with TDBGrid(Grid) do
Column := Columns[SelectedIndex];
if ActiveList = FDataList then
begin
FDataList.Color := Color;
FDataList.Font := Font;
FDataList.RowCount := Column.DropDownRows;
LookupInfo := TJvDBGrid(Grid).GetColumnLookupInfo(Column);
FLookupSource.DataSet := LookupInfo.LookupDataSet;
FDataList.LookupField := LookupInfo.LookupKeyFields; // KeyField
FDataList.LookupDisplay := LookupInfo.LookupResultField; // ListField
FDataList.LookupSource := FLookupSource; // ListSource
FDataList.KeyValue := Column.Field.DataSet.FieldByName(LookupInfo.KeyFields).Value;
end
else
if ActiveList = PickList then
begin
PickList.Items.Assign(Column.PickList);
DropDownRows := Column.DropDownRows;
end;
end;
inherited DropDown;
end;
procedure TInternalInplaceEdit.UpdateContents;
var
Column: TColumn;
begin
inherited UpdateContents;
if FUseDataList then
begin
if FDataList = nil then
begin
FDataList := TJvPopupDataList.Create(Self);
FDataList.Visible := False;
FDataList.Parent := Self;
FDataList.OnMouseUp := ListMouseUp;
end;
ActiveList := FDataList;
end;
with TDBGrid(Grid) do
Column := Columns[SelectedIndex];
Self.ReadOnly := Column.ReadOnly;
Font.Assign(Column.Font);
ImeMode := Column.ImeMode;
ImeName := Column.ImeName;
end;
type
TSelection = record
StartPos: Integer;
EndPos: Integer;
end;
procedure TInternalInplaceEdit.KeyDown(var Key: Word; Shift: TShiftState);
procedure SendToParent;
begin
TJvDBGrid(Grid).KeyDown(Key, Shift);
Key := 0;
end;
procedure ParentEvent;
var
GridKeyDown: TKeyEvent;
begin
GridKeyDown := TJvDBGrid(Grid).OnKeyDown;
if Assigned(GridKeyDown) then
GridKeyDown(Grid, Key, Shift);
end;
function ForwardMovement: Boolean;
begin
Result := dgAlwaysShowEditor in TJvDBGrid(Grid).Options;
end;
function Ctrl: Boolean;
begin
Result := (Shift * KeyboardShiftStates = [ssCtrl]);
end;
function Selection: TSelection;
begin
SendMessage(Handle, EM_GETSEL, WPARAM(@Result.StartPos), LPARAM(@Result.EndPos));
end;
function CaretPos: Integer;
var
P: TPoint;
begin
Windows.GetCaretPos(P);
Result := SendMessage(Handle, EM_CHARFROMPOS, 0, MakeLong(P.X, P.Y));
end;
function RightSide: Boolean;
begin
with Selection do
Result := {(CaretPos = GetTextLen) and }
((StartPos = 0) or (EndPos = StartPos)) and (EndPos = GetTextLen);
end;
function LeftSide: Boolean;
begin
with Selection do
Result := (CaretPos = 0) and (StartPos = 0) and
((EndPos = 0) or (EndPos = GetTextLen));
end;
begin
case Key of
VK_LEFT:
if ForwardMovement and (Ctrl or LeftSide) then
SendToParent;
VK_RIGHT:
if ForwardMovement and (Ctrl or RightSide) then
SendToParent;
end;
inherited KeyDown(Key, Shift);
end;
function TInternalInplaceEdit.DoMouseWheel(Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint): Boolean;
var
DataLink: TDataLink;
begin
// Do not validate a record by error