Changeset 21 for trunk/Packages/Common/UListViewSort.pas
- Timestamp:
- May 8, 2019, 12:11:40 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UListViewSort.pas
r15 r21 9 9 uses 10 10 {$IFDEF Windows}Windows, CommCtrl, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils, 11 Controls, DateUtils, Dialogs, SpecializedList, Forms, Grids, StdCtrls, ExtCtrls,11 Controls, DateUtils, Dialogs, fgl, Forms, Grids, StdCtrls, ExtCtrls, 12 12 LclIntf, LMessages, LclType, LResources; 13 13 … … 52 52 {$ENDIF} 53 53 public 54 List: T ListObject;55 Source: T ListObject;54 List: TFPGObjectList<TObject>; 55 Source: TFPGObjectList<TObject>; 56 56 constructor Create(AOwner: TComponent); override; 57 57 destructor Destroy; override; … … 98 98 end; 99 99 100 { TListViewEx } 101 102 TListViewEx = class(TWinControl) 103 private 104 FFilter: TListViewFilter; 105 FListView: TListView; 106 FListViewSort: TListViewSort; 107 procedure ResizeHanlder; 108 public 109 constructor Create(TheOwner: TComponent); override; 110 destructor Destroy; override; 111 published 112 property ListView: TListView read FListView write FListView; 113 property ListViewSort: TListViewSort read FListViewSort write FListViewSort; 114 property Filter: TListViewFilter read FFilter write FFilter; 115 property Visible; 116 end; 117 100 118 procedure Register; 101 119 … … 105 123 procedure Register; 106 124 begin 107 RegisterComponents('Common', [TListViewSort, TListViewFilter]); 125 RegisterComponents('Common', [TListViewSort, TListViewFilter, TListViewEx]); 126 end; 127 128 { TListViewEx } 129 130 procedure TListViewEx.ResizeHanlder; 131 begin 132 end; 133 134 constructor TListViewEx.Create(TheOwner: TComponent); 135 begin 136 inherited Create(TheOwner); 137 Filter := TListViewFilter.Create(Self); 138 Filter.Parent := Self; 139 Filter.Align := alBottom; 140 ListView := TListView.Create(Self); 141 ListView.Parent := Self; 142 ListView.Align := alClient; 143 ListViewSort := TListViewSort.Create(Self); 144 ListViewSort.ListView := ListView; 145 end; 146 147 destructor TListViewEx.Destroy; 148 begin 149 inherited Destroy; 108 150 end; 109 151 … … 142 184 var 143 185 I: Integer; 186 R: TRect; 144 187 begin 145 188 with FStringGrid1 do begin 146 Options := Options - [goEditing, goAlwaysShowEditor];147 //Columns.Clear;148 189 while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1); 149 190 while Columns.Count < ListView.Columns.Count do Columns.Add; 150 191 for I := 0 to ListView.Columns.Count - 1 do begin 151 192 Columns[I].Width := ListView.Columns[I].Width; 193 if Selection.Left = I then begin 194 R := CellRect(I, 0); 195 Editor.Left := R.Left + 2; 196 Editor.Width := R.Width - 4; 197 end; 152 198 end; 153 Options := Options + [goEditing, goAlwaysShowEditor];154 199 end; 155 200 end; … … 274 319 end; 275 320 321 var 322 ListViewSortCompare: TCompareEvent; 323 324 function ListViewCompare(const Item1, Item2: TObject): Integer; 325 begin 326 Result := ListViewSortCompare(Item1, Item2); 327 end; 328 276 329 procedure TListViewSort.Sort(Compare: TCompareEvent); 277 330 begin 331 // TODO: Because TFLGObjectList compare handler is not class method, 332 // it is necessary to use simple function compare handler with local variable 333 ListViewSortCompare := Compare; 278 334 if (List.Count > 0) then 279 List.Sort( Compare);335 List.Sort(ListViewCompare); 280 336 end; 281 337 … … 340 396 begin 341 397 inherited; 342 List := T ListObject.Create;343 List. OwnsObjects := False;398 List := TFPGObjectList<TObject>.Create; 399 List.FreeObjects := False; 344 400 end; 345 401 … … 381 437 ItemLeft := Item.Left; 382 438 ItemLeft := 23; // Windows 7 workaround 383 439 384 440 Rect1.Left := ItemLeft - CheckWidth - BiasLeft + 1 + XBias; 385 441 //ShowMessage(IntToStr(Tp1.Y) + ', ' + IntToStr(BiasTop) + ', ' + IntToStr(XBias)); … … 480 536 FHeaderHandle := ListView_GetHeader(FListView.Handle); 481 537 for I := 0 to FListView.Columns.Count - 1 do begin 538 {$push}{$warn 5057 off} 482 539 FillChar(Item, SizeOf(THDItem), 0); 540 {$pop} 483 541 Item.Mask := HDI_FORMAT; 484 542 Header_GetItem(FHeaderHandle, I, Item);
Note:
See TracChangeset
for help on using the changeset viewer.