Ignore:
Timestamp:
Nov 29, 2023, 2:35:44 PM (12 months ago)
Author:
chronos
Message:
  • Modified: HighDpi branch updated to trunk version.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • branches/highdpi/Packages/Common/ListViewSort.pas

    r462 r463  
    1 unit UListViewSort;
     1unit ListViewSort;
    22
    33// Date: 2019-05-17
    4 
    5 {$mode delphi}
    64
    75interface
     
    97uses
    108  UDpiControls, {$IFDEF Windows}Windows, CommCtrl, LMessages, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils,
    11   Controls, DateUtils, Dialogs, fgl, Forms, Grids, StdCtrls, ExtCtrls,
    12   LclIntf, LclType, LResources;
     9  Controls, DateUtils, Dialogs, Forms, Grids, StdCtrls, ExtCtrls,
     10  LclIntf, LclType, LResources, Generics.Collections, Generics.Defaults;
    1311
    1412type
     
    1917  TCompareEvent = function (Item1, Item2: TObject): Integer of object;
    2018  TListFilterEvent = procedure (ListViewSort: TListViewSort) of object;
     19
     20  TObjects = TObjectList<TObject>;
    2121
    2222  { TListViewSort }
     
    2727    FOnCompareItem: TCompareEvent;
    2828    FOnFilter: TListFilterEvent;
    29     FOnCustomDraw: TLVCustomDrawItemEvent;
     29    FOnCustomDraw: TDpiLVCustomDrawItemEvent;
    3030    {$IFDEF Windows}FHeaderHandle: HWND;{$ENDIF}
    3131    FColumn: Integer;
     
    4242    procedure GetCheckBias(var XBias, YBias, BiasTop, BiasLeft: Integer;
    4343      const ListView: TDpiListView);
    44     procedure ListViewCustomDrawItem(Sender: TCustomListView;
     44    procedure ListViewCustomDrawItem(Sender: TDpiCustomListView;
    4545      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    4646    procedure ListViewClick(Sender: TObject);
     
    5252    {$ENDIF}
    5353  public
    54     List: TFPGObjectList<TObject>;
    55     Source: TFPGObjectList<TObject>;
     54    Source: TObjects;
     55    List: TObjects;
    5656    constructor Create(AOwner: TComponent); override;
    5757    destructor Destroy; override;
     
    6767    property OnFilter: TListFilterEvent read FOnFilter
    6868      write FOnFilter;
    69     property OnCustomDraw: TLVCustomDrawItemEvent read FOnCustomDraw
     69    property OnCustomDraw: TDpiLVCustomDrawItemEvent read FOnCustomDraw
    7070      write FOnCustomDraw;
    7171    property OnColumnWidthChanged: TNotifyEvent read FOnColumnWidthChanged
     
    8181    FOnChange: TNotifyEvent;
    8282    FStringGrid1: TDpiStringGrid;
     83    procedure DoOnChange;
    8384    procedure GridDoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    8485    procedure GridDoOnResize(Sender: TObject);
     
    9091    function TextEnteredColumn(Index: Integer): Boolean;
    9192    function GetColValue(Index: Integer): string;
     93    procedure Reset;
    9294    property StringGrid: TDpiStringGrid read FStringGrid1 write FStringGrid1;
    9395  published
     
    147149destructor TListViewEx.Destroy;
    148150begin
    149   inherited Destroy;
     151  inherited;
    150152end;
    151153
    152154{ TListViewFilter }
     155
     156procedure TListViewFilter.DoOnChange;
     157begin
     158  if Assigned(FOnChange) then FOnChange(Self);
     159end;
    153160
    154161procedure TListViewFilter.GridDoOnKeyUp(Sender: TObject; var Key: Word;
    155162  Shift: TShiftState);
    156163begin
    157   if Assigned(FOnChange) then
    158     FOnChange(Self);
     164  DoOnChange;
    159165end;
    160166
     
    229235end;
    230236
     237procedure TListViewFilter.Reset;
     238var
     239  I: Integer;
     240begin
     241  with StringGrid do
     242  for I := 0 to ColCount - 1 do
     243    Cells[I, 0] := '';
     244  DoOnChange;
     245end;
     246
    231247{ TListViewSort }
    232248
     
    322338  ListViewSortCompare: TCompareEvent;
    323339
    324 function ListViewCompare(const Item1, Item2: TObject): Integer;
     340function ListViewCompare(constref Item1, Item2: TObject): Integer;
    325341begin
    326342  Result := ListViewSortCompare(Item1, Item2);
     
    333349  ListViewSortCompare := Compare;
    334350  if (List.Count > 0) then
    335     List.Sort(ListViewCompare);
     351    List.Sort(TComparer<TObject>.Construct(ListViewCompare));
    336352end;
    337353
     
    339355begin
    340356  if Assigned(FOnFilter) then FOnFilter(Self)
    341   else if Assigned(Source) then
    342     List.Assign(Source) else
     357  else if Assigned(Source) then begin
    343358    List.Clear;
     359    List.AddRange(Source);
     360  end else List.Clear;
    344361  if ListView.Items.Count <> List.Count then
    345362    ListView.Items.Count := List.Count;
     
    396413begin
    397414  inherited;
    398   List := TFPGObjectList<TObject>.Create;
    399   List.FreeObjects := False;
     415  List := TObjects.Create;
     416  List.OwnsObjects := False;
    400417end;
    401418
    402419destructor TListViewSort.Destroy;
    403420begin
    404   List.Free;
     421  FreeAndNil(List);
    405422  inherited;
    406423end;
     
    491508end;
    492509
    493 procedure TListViewSort.ListViewCustomDrawItem(Sender: TCustomListView;
     510procedure TListViewSort.ListViewCustomDrawItem(Sender: TDpiCustomListView;
    494511  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    495512begin
Note: See TracChangeset for help on using the changeset viewer.