Changeset 100 for trunk/Packages/Common
- Timestamp:
- Aug 31, 2016, 9:57:15 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UListViewSort.pas
r74 r100 18 18 TCompareEvent = function (Item1, Item2: TObject): Integer of object; 19 19 TListFilterEvent = procedure (ListViewSort: TListViewSort) of object; 20 21 { TListViewSort } 20 22 21 23 TListViewSort = class(TComponent) … … 28 30 FColumn: Integer; 29 31 FOrder: TSortOrder; 32 FOldListViewWindowProc: TWndMethod; 33 FOnColumnWidthChanged: TNotifyEvent; 34 procedure DoColumnBeginResize(const AColIndex: Integer); 35 procedure DoColumnResized(const AColIndex: Integer); 36 procedure DoColumnResizing(const AColIndex, AWidth: Integer); 30 37 procedure SetListView(const Value: TListView); 31 38 procedure ColumnClick(Sender: TObject; Column: TListColumn); … … 40 47 procedure SetColumn(const Value: Integer); 41 48 procedure SetOrder(const Value: TSortOrder); 49 procedure NewListViewWindowProc(var AMsg: TMessage); 42 50 public 43 51 List: TListObject; … … 58 66 property OnCustomDraw: TLVCustomDrawItemEvent read FOnCustomDraw 59 67 write FOnCustomDraw; 68 property OnColumnWidthChanged: TNotifyEvent read FOnColumnWidthChanged 69 write FOnColumnWidthChanged; 60 70 property Column: Integer read FColumn write SetColumn; 61 71 property Order: TSortOrder read FOrder write SetOrder; … … 69 79 FStringGrid1: TStringGrid; 70 80 procedure DoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 81 procedure DoOnResize(Sender: TObject); 71 82 public 72 83 constructor Create(AOwner: TComponent); override; … … 102 113 end; 103 114 115 procedure TListViewFilter.DoOnResize(Sender: TObject); 116 begin 117 FStringGrid1.DefaultRowHeight := FStringGrid1.Height; 118 end; 119 104 120 constructor TListViewFilter.Create(AOwner: TComponent); 105 121 begin … … 116 132 goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll]; 117 133 FStringGrid1.OnKeyUp := DoOnKeyUp; 134 FStringGrid1.OnResize := DoOnResize; 118 135 end; 119 136 … … 163 180 { TListViewSort } 164 181 182 procedure TListViewSort.NewListViewWindowProc(var AMsg: TMessage); 183 var 184 vColWidth: Integer; 185 vMsgNotify: TWMNotify absolute AMsg; 186 Code: Integer; 187 begin 188 // call the old WindowProc of ListView 189 FOldListViewWindowProc(AMsg); 190 191 // Currently we care only with WM_NOTIFY message 192 if AMsg.Msg = WM_NOTIFY then 193 begin 194 Code := PHDNotify(vMsgNotify.NMHdr)^.Hdr.Code; 195 case Code of 196 HDN_ENDTRACKA, HDN_ENDTRACKW: 197 DoColumnResized(PHDNotify(vMsgNotify.NMHdr)^.Item); 198 199 HDN_BEGINTRACKA, HDN_BEGINTRACKW: 200 DoColumnBeginResize(PHDNotify(vMsgNotify.NMHdr)^.Item); 201 202 HDN_TRACKA, HDN_TRACKW: 203 begin 204 vColWidth := -1; 205 if (PHDNotify(vMsgNotify.NMHdr)^.PItem<>nil) 206 and (PHDNotify(vMsgNotify.NMHdr)^.PItem^.Mask and HDI_WIDTH <> 0) 207 then 208 vColWidth := PHDNotify(vMsgNotify.NMHdr)^.PItem^.cxy; 209 210 DoColumnResizing(PHDNotify(vMsgNotify.NMHdr)^.Item, vColWidth); 211 end; 212 end; 213 end; 214 end; 215 216 procedure TListViewSort.DoColumnBeginResize(const AColIndex: Integer); 217 begin 218 end; 219 220 procedure TListViewSort.DoColumnResizing(const AColIndex, AWidth: Integer); 221 begin 222 end; 223 224 procedure TListViewSort.DoColumnResized(const AColIndex: Integer); 225 begin 226 if Assigned(FOnColumnWidthChanged) then 227 FOnColumnWidthChanged(Self); 228 end; 165 229 166 230 procedure TListViewSort.ColumnClick(Sender: TObject; Column: TListColumn); … … 189 253 procedure TListViewSort.SetListView(const Value: TListView); 190 254 begin 255 if FListView = Value then Exit; 256 if Assigned(FListView) then 257 ListView.WindowProc := FOldListViewWindowProc; 191 258 FListView := Value; 192 259 FListView.OnColumnClick := ColumnClick; 193 260 FListView.OnCustomDrawItem := ListViewCustomDrawItem; 194 261 FListView.OnClick := ListViewClick; 262 FOldListViewWindowProc := FListView.WindowProc; 263 FListView.WindowProc := NewListViewWindowProc; 195 264 end; 196 265
Note:
See TracChangeset
for help on using the changeset viewer.