Ignore:
Timestamp:
Oct 27, 2016, 3:00:47 PM (8 years ago)
Author:
chronos
Message:
  • Added: Remember position and size of main form after close of application.
  • Modified: Updated Common package to latest version.
File:
1 edited

Legend:

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

    r72 r73  
    99uses
    1010  {$IFDEF Windows}Windows, CommCtrl, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils,
    11   Controls, DateUtils, Dialogs, SpecializedList, Forms, Grids, StdCtrls, ExtCtrls;
     11  Controls, DateUtils, Dialogs, SpecializedList, Forms, Grids, StdCtrls, ExtCtrls,
     12  LclIntf, LMessages, LclType, LResources;
    1213
    1314type
     
    1819  TCompareEvent = function (Item1, Item2: TObject): Integer of object;
    1920  TListFilterEvent = procedure (ListViewSort: TListViewSort) of object;
     21
     22  { TListViewSort }
    2023
    2124  TListViewSort = class(TComponent)
     
    2831    FColumn: Integer;
    2932    FOrder: TSortOrder;
     33    FOldListViewWindowProc: TWndMethod;
     34    FOnColumnWidthChanged: TNotifyEvent;
     35    procedure DoColumnBeginResize(const AColIndex: Integer);
     36    procedure DoColumnResized(const AColIndex: Integer);
     37    procedure DoColumnResizing(const AColIndex, AWidth: Integer);
    3038    procedure SetListView(const Value: TListView);
    3139    procedure ColumnClick(Sender: TObject; Column: TListColumn);
     
    4048    procedure SetColumn(const Value: Integer);
    4149    procedure SetOrder(const Value: TSortOrder);
     50    {$IFDEF WINDOWS}
     51    procedure NewListViewWindowProc(var AMsg: TMessage);
     52    {$ENDIF}
    4253  public
    4354    List: TListObject;
     
    5869    property OnCustomDraw: TLVCustomDrawItemEvent read FOnCustomDraw
    5970      write FOnCustomDraw;
     71    property OnColumnWidthChanged: TNotifyEvent read FOnColumnWidthChanged
     72      write FOnColumnWidthChanged;
    6073    property Column: Integer read FColumn write SetColumn;
    6174    property Order: TSortOrder read FOrder write SetOrder;
     
    6982    FStringGrid1: TStringGrid;
    7083    procedure DoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
     84    procedure DoOnResize(Sender: TObject);
    7185  public
    7286    constructor Create(AOwner: TComponent); override;
    7387    procedure UpdateFromListView(ListView: TListView);
    7488    function TextEntered: Boolean;
     89    function TextEnteredCount: Integer;
     90    function TextEnteredColumn(Index: Integer): Boolean;
    7591    function GetColValue(Index: Integer): string;
    7692    property StringGrid: TStringGrid read FStringGrid1 write FStringGrid1;
     
    7995    property Align;
    8096    property Anchors;
     97    property BorderSpacing;
    8198  end;
    8299
     
    98115  if Assigned(FOnChange) then
    99116    FOnChange(Self);
     117end;
     118
     119procedure TListViewFilter.DoOnResize(Sender: TObject);
     120begin
     121  FStringGrid1.DefaultRowHeight := FStringGrid1.Height;
    100122end;
    101123
     
    114136    goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll];
    115137  FStringGrid1.OnKeyUp := DoOnKeyUp;
     138  FStringGrid1.OnResize := DoOnResize;
    116139end;
    117140
     
    121144begin
    122145  with FStringGrid1 do begin
    123     Columns.Clear;
     146    //Columns.Clear;
    124147    while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1);
    125148    while Columns.Count < ListView.Columns.Count do Columns.Add;
     
    131154
    132155function TListViewFilter.TextEntered: Boolean;
     156begin
     157  Result := TextEnteredCount > 0;
     158end;
     159
     160function TListViewFilter.TextEnteredCount: Integer;
    133161var
    134162  I: Integer;
    135163begin
    136   Result := False;
     164  Result := 0;
    137165  for I := 0 to FStringGrid1.ColCount - 1 do begin
    138166    if FStringGrid1.Cells[I, 0] <> '' then begin
    139       Result := True;
    140       Break;
     167      Inc(Result);
    141168    end;
    142169  end;
     170end;
     171
     172function TListViewFilter.TextEnteredColumn(Index: Integer): Boolean;
     173begin
     174  Result := FStringGrid1.Cells[Index, 0] <> '';
    143175end;
    144176
     
    152184{ TListViewSort }
    153185
     186{$IFDEF WINDOWS}
     187procedure TListViewSort.NewListViewWindowProc(var AMsg: TMessage);
     188var
     189  vColWidth: Integer;
     190  vMsgNotify: TLMNotify absolute AMsg;
     191  Code: Integer;
     192begin
     193  // call the old WindowProc of ListView
     194  FOldListViewWindowProc(AMsg);
     195
     196  // Currently we care only with WM_NOTIFY message
     197  if AMsg.Msg = WM_NOTIFY then
     198  begin
     199    Code := PHDNotify(vMsgNotify.NMHdr)^.Hdr.Code;
     200    case Code of
     201      HDN_ENDTRACKA, HDN_ENDTRACKW:
     202        DoColumnResized(PHDNotify(vMsgNotify.NMHdr)^.Item);
     203
     204      HDN_BEGINTRACKA, HDN_BEGINTRACKW:
     205        DoColumnBeginResize(PHDNotify(vMsgNotify.NMHdr)^.Item);
     206
     207      HDN_TRACKA, HDN_TRACKW:
     208        begin
     209          vColWidth := -1;
     210          if (PHDNotify(vMsgNotify.NMHdr)^.PItem<>nil)
     211             and (PHDNotify(vMsgNotify.NMHdr)^.PItem^.Mask and HDI_WIDTH <> 0)
     212          then
     213            vColWidth := PHDNotify(vMsgNotify.NMHdr)^.PItem^.cxy;
     214
     215          DoColumnResizing(PHDNotify(vMsgNotify.NMHdr)^.Item, vColWidth);
     216        end;
     217    end;
     218  end;
     219end;
     220{$ENDIF}
     221
     222procedure TListViewSort.DoColumnBeginResize(const AColIndex: Integer);
     223begin
     224end;
     225
     226procedure TListViewSort.DoColumnResizing(const AColIndex, AWidth: Integer);
     227begin
     228end;
     229
     230procedure TListViewSort.DoColumnResized(const AColIndex: Integer);
     231begin
     232  if Assigned(FOnColumnWidthChanged) then
     233    FOnColumnWidthChanged(Self);
     234end;
    154235
    155236procedure TListViewSort.ColumnClick(Sender: TObject; Column: TListColumn);
     
    178259procedure TListViewSort.SetListView(const Value: TListView);
    179260begin
     261  if FListView = Value then Exit;
     262  if Assigned(FListView) then
     263    ListView.WindowProc := FOldListViewWindowProc;
    180264  FListView := Value;
    181265  FListView.OnColumnClick := ColumnClick;
    182266  FListView.OnCustomDrawItem := ListViewCustomDrawItem;
    183267  FListView.OnClick := ListViewClick;
     268  FOldListViewWindowProc := FListView.WindowProc;
     269  {$IFDEF WINDOWS}
     270  FListView.WindowProc := NewListViewWindowProc;
     271  {$ENDIF}
    184272end;
    185273
     
    198286  if ListView.Items.Count <> List.Count then
    199287    ListView.Items.Count := List.Count;
    200   if Assigned(FOnCompareItem) then Sort(FOnCompareItem);
     288  if Assigned(FOnCompareItem) and (Order <> soNone) then Sort(FOnCompareItem);
    201289  //ListView.Items[-1]; // Workaround for not show first row if selected
    202290  ListView.Refresh;
Note: See TracChangeset for help on using the changeset viewer.