Changeset 25 for trunk/Packages/Common/UListViewSort.pas
- Timestamp:
- Sep 10, 2022, 6:54:43 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UListViewSort.pas
r15 r25 1 1 unit UListViewSort; 2 2 3 // Date: 2010-11-03 4 5 {$mode delphi} 3 // Date: 2019-05-17 6 4 7 5 interface 8 6 9 7 uses 10 {$IFDEF Windows}Windows, CommCtrl, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils,11 Controls, DateUtils, Dialogs, SpecializedList,Forms, Grids, StdCtrls, ExtCtrls,12 LclIntf, L Messages, LclType, LResources;8 {$IFDEF Windows}Windows, CommCtrl, LMessages, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils, 9 Controls, DateUtils, Dialogs, Forms, Grids, StdCtrls, ExtCtrls, 10 LclIntf, LclType, LResources, Generics.Collections, Generics.Defaults; 13 11 14 12 type … … 19 17 TCompareEvent = function (Item1, Item2: TObject): Integer of object; 20 18 TListFilterEvent = procedure (ListViewSort: TListViewSort) of object; 19 20 TObjects = TObjectList<TObject>; 21 21 22 22 { TListViewSort } … … 52 52 {$ENDIF} 53 53 public 54 List: TListObject;55 Source: TListObject;54 Source: TObjects; 55 List: TObjects; 56 56 constructor Create(AOwner: TComponent); override; 57 57 destructor Destroy; override; … … 81 81 FOnChange: TNotifyEvent; 82 82 FStringGrid1: TStringGrid; 83 procedure DoOnChange; 83 84 procedure GridDoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 84 85 procedure GridDoOnResize(Sender: TObject); … … 90 91 function TextEnteredColumn(Index: Integer): Boolean; 91 92 function GetColValue(Index: Integer): string; 93 procedure Reset; 92 94 property StringGrid: TStringGrid read FStringGrid1 write FStringGrid1; 93 95 published … … 98 100 end; 99 101 102 { TListViewEx } 103 104 TListViewEx = class(TWinControl) 105 private 106 FFilter: TListViewFilter; 107 FListView: TListView; 108 FListViewSort: TListViewSort; 109 procedure ResizeHanlder; 110 public 111 constructor Create(TheOwner: TComponent); override; 112 destructor Destroy; override; 113 published 114 property ListView: TListView read FListView write FListView; 115 property ListViewSort: TListViewSort read FListViewSort write FListViewSort; 116 property Filter: TListViewFilter read FFilter write FFilter; 117 property Visible; 118 end; 119 100 120 procedure Register; 101 121 … … 105 125 procedure Register; 106 126 begin 107 RegisterComponents('Common', [TListViewSort, TListViewFilter]); 127 RegisterComponents('Common', [TListViewSort, TListViewFilter, TListViewEx]); 128 end; 129 130 { TListViewEx } 131 132 procedure TListViewEx.ResizeHanlder; 133 begin 134 end; 135 136 constructor TListViewEx.Create(TheOwner: TComponent); 137 begin 138 inherited Create(TheOwner); 139 Filter := TListViewFilter.Create(Self); 140 Filter.Parent := Self; 141 Filter.Align := alBottom; 142 ListView := TListView.Create(Self); 143 ListView.Parent := Self; 144 ListView.Align := alClient; 145 ListViewSort := TListViewSort.Create(Self); 146 ListViewSort.ListView := ListView; 147 end; 148 149 destructor TListViewEx.Destroy; 150 begin 151 inherited; 108 152 end; 109 153 110 154 { TListViewFilter } 155 156 procedure TListViewFilter.DoOnChange; 157 begin 158 if Assigned(FOnChange) then FOnChange(Self); 159 end; 111 160 112 161 procedure TListViewFilter.GridDoOnKeyUp(Sender: TObject; var Key: Word; 113 162 Shift: TShiftState); 114 163 begin 115 if Assigned(FOnChange) then 116 FOnChange(Self); 164 DoOnChange; 117 165 end; 118 166 … … 142 190 var 143 191 I: Integer; 192 R: TRect; 144 193 begin 145 194 with FStringGrid1 do begin 146 Options := Options - [goEditing, goAlwaysShowEditor];147 //Columns.Clear;148 195 while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1); 149 196 while Columns.Count < ListView.Columns.Count do Columns.Add; 150 197 for I := 0 to ListView.Columns.Count - 1 do begin 151 198 Columns[I].Width := ListView.Columns[I].Width; 199 if Selection.Left = I then begin 200 R := CellRect(I, 0); 201 Editor.Left := R.Left + 2; 202 Editor.Width := R.Width - 4; 203 end; 152 204 end; 153 Options := Options + [goEditing, goAlwaysShowEditor];154 205 end; 155 206 end; … … 182 233 Result := StringGrid.Cells[Index, 0] 183 234 else Result := ''; 235 end; 236 237 procedure TListViewFilter.Reset; 238 var 239 I: Integer; 240 begin 241 with StringGrid do 242 for I := 0 to ColCount - 1 do 243 Cells[I, 0] := ''; 244 DoOnChange; 184 245 end; 185 246 … … 274 335 end; 275 336 337 var 338 ListViewSortCompare: TCompareEvent; 339 340 function ListViewCompare(constref Item1, Item2: TObject): Integer; 341 begin 342 Result := ListViewSortCompare(Item1, Item2); 343 end; 344 276 345 procedure TListViewSort.Sort(Compare: TCompareEvent); 277 346 begin 347 // TODO: Because TFLGObjectList compare handler is not class method, 348 // it is necessary to use simple function compare handler with local variable 349 ListViewSortCompare := Compare; 278 350 if (List.Count > 0) then 279 List.Sort( Compare);351 List.Sort(TComparer<TObject>.Construct(ListViewCompare)); 280 352 end; 281 353 … … 283 355 begin 284 356 if Assigned(FOnFilter) then FOnFilter(Self) 285 else if Assigned(Source) then 286 List.Assign(Source) else 357 else if Assigned(Source) then begin 287 358 List.Clear; 359 List.AddRange(Source); 360 end else List.Clear; 288 361 if ListView.Items.Count <> List.Count then 289 362 ListView.Items.Count := List.Count; … … 340 413 begin 341 414 inherited; 342 List := T ListObject.Create;415 List := TObjects.Create; 343 416 List.OwnsObjects := False; 344 417 end; … … 346 419 destructor TListViewSort.Destroy; 347 420 begin 348 List.Free;421 FreeAndNil(List); 349 422 inherited; 350 423 end; … … 381 454 ItemLeft := Item.Left; 382 455 ItemLeft := 23; // Windows 7 workaround 383 456 384 457 Rect1.Left := ItemLeft - CheckWidth - BiasLeft + 1 + XBias; 385 458 //ShowMessage(IntToStr(Tp1.Y) + ', ' + IntToStr(BiasTop) + ', ' + IntToStr(XBias)); … … 480 553 FHeaderHandle := ListView_GetHeader(FListView.Handle); 481 554 for I := 0 to FListView.Columns.Count - 1 do begin 555 {$push}{$warn 5057 off} 482 556 FillChar(Item, SizeOf(THDItem), 0); 557 {$pop} 483 558 Item.Mask := HDI_FORMAT; 484 559 Header_GetItem(FHeaderHandle, I, Item);
Note:
See TracChangeset
for help on using the changeset viewer.