Ignore:
Timestamp:
Apr 18, 2019, 3:34:38 PM (6 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Components/Common/UListViewSort.pas

    r34 r38  
    99uses
    1010  {$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,
    1212  LclIntf, LMessages, LclType, LResources;
    1313
     
    5252    {$ENDIF}
    5353  public
    54     List: TListObject;
    55     Source: TListObject;
     54    List: TFPGObjectList<TObject>;
     55    Source: TFPGObjectList<TObject>;
    5656    constructor Create(AOwner: TComponent); override;
    5757    destructor Destroy; override;
     
    8181    FOnChange: TNotifyEvent;
    8282    FStringGrid1: TStringGrid;
    83     procedure DoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    84     procedure DoOnResize(Sender: TObject);
     83    procedure GridDoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
     84    procedure GridDoOnResize(Sender: TObject);
    8585  public
    8686    constructor Create(AOwner: TComponent); override;
     
    9898  end;
    9999
     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
    100118procedure Register;
    101119
     
    105123procedure Register;
    106124begin
    107   RegisterComponents('Common', [TListViewSort, TListViewFilter]);
     125  RegisterComponents('Common', [TListViewSort, TListViewFilter, TListViewEx]);
     126end;
     127
     128{ TListViewEx }
     129
     130procedure TListViewEx.ResizeHanlder;
     131begin
     132end;
     133
     134constructor TListViewEx.Create(TheOwner: TComponent);
     135begin
     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;
     145end;
     146
     147destructor TListViewEx.Destroy;
     148begin
     149  inherited Destroy;
    108150end;
    109151
    110152{ TListViewFilter }
    111153
    112 procedure TListViewFilter.DoOnKeyUp(Sender: TObject; var Key: Word;
     154procedure TListViewFilter.GridDoOnKeyUp(Sender: TObject; var Key: Word;
    113155  Shift: TShiftState);
    114156begin
     
    117159end;
    118160
    119 procedure TListViewFilter.DoOnResize(Sender: TObject);
     161procedure TListViewFilter.GridDoOnResize(Sender: TObject);
    120162begin
    121163  FStringGrid1.DefaultRowHeight := FStringGrid1.Height;
     
    135177  FStringGrid1.Options := [goFixedHorzLine, goFixedVertLine, goVertLine,
    136178    goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll];
    137   FStringGrid1.OnKeyUp := DoOnKeyUp;
    138   FStringGrid1.OnResize := DoOnResize;
     179  FStringGrid1.OnKeyUp := GridDoOnKeyUp;
     180  FStringGrid1.OnResize := GridDoOnResize;
    139181end;
    140182
     
    142184var
    143185  I: Integer;
     186  R: TRect;
    144187begin
    145188  with FStringGrid1 do begin
    146     //Columns.Clear;
    147189    while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1);
    148190    while Columns.Count < ListView.Columns.Count do Columns.Add;
    149191    for I := 0 to ListView.Columns.Count - 1 do begin
    150192      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;
    151198    end;
    152199  end;
     
    197244  if AMsg.Msg = WM_NOTIFY then
    198245  begin
    199     Code := PHDNotify(vMsgNotify.NMHdr)^.Hdr.Code;
     246    Code := NMHDR(PHDNotify(vMsgNotify.NMHdr)^.Hdr).Code;
    200247    case Code of
    201248      HDN_ENDTRACKA, HDN_ENDTRACKW:
     
    272319end;
    273320
     321var
     322  ListViewSortCompare: TCompareEvent;
     323
     324function ListViewCompare(const Item1, Item2: TObject): Integer;
     325begin
     326  Result := ListViewSortCompare(Item1, Item2);
     327end;
     328
    274329procedure TListViewSort.Sort(Compare: TCompareEvent);
    275330begin
     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;
    276334  if (List.Count > 0) then
    277     List.Sort(Compare);
     335    List.Sort(ListViewCompare);
    278336end;
    279337
     
    338396begin
    339397  inherited;
    340   List := TListObject.Create;
    341   List.OwnsObjects := False;
     398  List := TFPGObjectList<TObject>.Create;
     399  List.FreeObjects := False;
    342400end;
    343401
     
    353411  TP1: TPoint;
    354412  XBias, YBias: Integer;
    355   OldColor: TColor;
     413  PenColor: TColor;
     414  BrushColor: TColor;
    356415  BiasTop, BiasLeft: Integer;
    357416  Rect1: TRect;
     
    365424  Item.Left := 0;
    366425  GetCheckBias(XBias, YBias, BiasTop, BiasLeft, ListView);
    367   OldColor := ListView.Canvas.Pen.Color;
     426  PenColor := ListView.Canvas.Pen.Color;
     427  BrushColor := ListView.Canvas.Brush.Color;
    368428  //TP1 := Item.GetPosition;
    369429  lRect := Item.DisplayRect(drBounds); // Windows 7 workaround
     
    377437  ItemLeft := Item.Left;
    378438  ItemLeft := 23; // Windows 7 workaround
    379  
     439
    380440  Rect1.Left := ItemLeft - CheckWidth - BiasLeft + 1 + XBias;
    381441  //ShowMessage(IntToStr(Tp1.Y) + ', ' + IntToStr(BiasTop) + ', ' + IntToStr(XBias));
     
    408468  end;
    409469  //ListView.Canvas.Brush.Color := ListView.Color;
    410   ListView.Canvas.Brush.Color := clWindow;
    411   ListView.Canvas.Pen.Color := OldColor;
     470  ListView.Canvas.Brush.Color := BrushColor;
     471  ListView.Canvas.Pen.Color := PenColor;
    412472end;
    413473
     
    476536    FHeaderHandle := ListView_GetHeader(FListView.Handle);
    477537    for I := 0 to FListView.Columns.Count - 1 do begin
     538      {$push}{$warn 5057 off}
    478539      FillChar(Item, SizeOf(THDItem), 0);
     540      {$pop}
    479541      Item.Mask := HDI_FORMAT;
    480542      Header_GetItem(FHeaderHandle, I, Item);
Note: See TracChangeset for help on using the changeset viewer.