forked from sirodcar/commonx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBetterListView.pas
More file actions
98 lines (80 loc) · 2.81 KB
/
BetterListView.pas
File metadata and controls
98 lines (80 loc) · 2.81 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
unit BetterListView;
interface
uses
Windows
, Classes
, Controls
, Messages
, ComCtrls
, CommCtrl
;
type
TColumnEvent = procedure (ASender: TObject; const AColIndex: Integer) of object;
TColumnSizeEvent = procedure (ASender: TObject; const AColIndex, AColWidth: Integer) of object;
TBetterListView=class(TListView)
private
FOnColumnBeginResize: TColumnEvent;
FOnColumnResizing: TColumnSizeEvent;
FOnColumnResized: TColumnEvent;
procedure HandleWMNotify(var AMsg: TWMNotify); message WM_NOTIFY;
protected
procedure DoColumnResized(const AColIndex: Integer);
procedure DoColumnBeginResize(const AColIndex: Integer);
procedure DoColumnResizing(const AColIndex, AWidth: Integer);
published
// event that will be raised when a column starts resizing. The column's index
// will be indicated in AColIndex parameter
property OnColumnBeginResize: TColumnEvent read FOnColumnBeginResize write FOnColumnBeginResize;
// event that will be raised when a column is resizing. The column's index
// will be indicated in AColIndex parameter, and the current width indicated
// in AColWidth parameter
property OnColumnResizing : TColumnSizeEvent read FOnColumnResizing write FOnColumnResizing;
// event that will be raised when a column just finished resizing. The
// column's index will be indicated in AColIndex parameter
property OnColumnResized : TColumnEvent read FOnColumnResized write FOnColumnResized;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('CodeCall', [TBetterListView]);
end;
{ TBetterListView }
procedure TBetterListView.DoColumnBeginResize(const AColIndex: Integer);
begin
if Assigned(FOnColumnBeginResize) then
FOnColumnBeginResize(Self, AColIndex);
end;
procedure TBetterListView.DoColumnResized(const AColIndex: Integer);
begin
if Assigned(FOnColumnResized) then
FOnColumnResized(Self, AColIndex);
end;
procedure TBetterListView.DoColumnResizing(const AColIndex, AWidth: Integer);
begin
Columns[AcolIndex].Width := awidth;
if Assigned(FOnColumnResizing) then
FOnColumnResizing(Self, AColIndex, AWidth);
end;
procedure TBetterListView.HandleWMNotify(var AMsg: TWMNotify);
var
vColWidth: Integer;
begin
inherited;
case PHDNotify(AMsg.NMHdr)^.Hdr.Code of
HDN_ENDTRACKA, HDN_ENDTRACKW:
DoColumnResized(PHDNotify(AMsg.NMHdr)^.Item);
HDN_BEGINTRACKA, HDN_BEGINTRACKW:
DoColumnBeginResize(PHDNotify(AMsg.NMHdr)^.Item);
HDN_TRACKA, HDN_TRACKW, -320:
begin
vColWidth := -1;
if (PHDNotify(AMsg.NMHdr)^.PItem<>nil)
and (PHDNotify(AMsg.NMHdr)^.PItem^.Mask and HDI_WIDTH <> 0)
then
vColWidth := PHDNotify(AMsg.NMHdr)^.PItem^.cxy;
DoColumnResizing(PHDNotify(AMsg.NMHdr)^.Item, vColWidth);
end;
end;
end;
end.