Changeset 100 for trunk/Packages


Ignore:
Timestamp:
Aug 31, 2016, 9:57:15 AM (8 years ago)
Author:
chronos
Message:
  • Added: Resize ListView filter column width according ListView column width.
  • Fixed: Row height in ListView to respect visual styles.
File:
1 edited

Legend:

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

    r74 r100  
    1818  TCompareEvent = function (Item1, Item2: TObject): Integer of object;
    1919  TListFilterEvent = procedure (ListViewSort: TListViewSort) of object;
     20
     21  { TListViewSort }
    2022
    2123  TListViewSort = class(TComponent)
     
    2830    FColumn: Integer;
    2931    FOrder: TSortOrder;
     32    FOldListViewWindowProc: TWndMethod;
     33    FOnColumnWidthChanged: TNotifyEvent;
     34    procedure DoColumnBeginResize(const AColIndex: Integer);
     35    procedure DoColumnResized(const AColIndex: Integer);
     36    procedure DoColumnResizing(const AColIndex, AWidth: Integer);
    3037    procedure SetListView(const Value: TListView);
    3138    procedure ColumnClick(Sender: TObject; Column: TListColumn);
     
    4047    procedure SetColumn(const Value: Integer);
    4148    procedure SetOrder(const Value: TSortOrder);
     49    procedure NewListViewWindowProc(var AMsg: TMessage);
    4250  public
    4351    List: TListObject;
     
    5866    property OnCustomDraw: TLVCustomDrawItemEvent read FOnCustomDraw
    5967      write FOnCustomDraw;
     68    property OnColumnWidthChanged: TNotifyEvent read FOnColumnWidthChanged
     69      write FOnColumnWidthChanged;
    6070    property Column: Integer read FColumn write SetColumn;
    6171    property Order: TSortOrder read FOrder write SetOrder;
     
    6979    FStringGrid1: TStringGrid;
    7080    procedure DoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
     81    procedure DoOnResize(Sender: TObject);
    7182  public
    7283    constructor Create(AOwner: TComponent); override;
     
    102113end;
    103114
     115procedure TListViewFilter.DoOnResize(Sender: TObject);
     116begin
     117  FStringGrid1.DefaultRowHeight := FStringGrid1.Height;
     118end;
     119
    104120constructor TListViewFilter.Create(AOwner: TComponent);
    105121begin
     
    116132    goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll];
    117133  FStringGrid1.OnKeyUp := DoOnKeyUp;
     134  FStringGrid1.OnResize := DoOnResize;
    118135end;
    119136
     
    163180{ TListViewSort }
    164181
     182procedure TListViewSort.NewListViewWindowProc(var AMsg: TMessage);
     183var
     184  vColWidth: Integer;
     185  vMsgNotify: TWMNotify absolute AMsg;
     186  Code: Integer;
     187begin
     188  // call the old WindowProc of ListView
     189  FOldListViewWindowProc(AMsg);
     190
     191  // Currently we care only with WM_NOTIFY message
     192  if AMsg.Msg = WM_NOTIFY then
     193  begin
     194    Code := PHDNotify(vMsgNotify.NMHdr)^.Hdr.Code;
     195    case Code of
     196      HDN_ENDTRACKA, HDN_ENDTRACKW:
     197        DoColumnResized(PHDNotify(vMsgNotify.NMHdr)^.Item);
     198
     199      HDN_BEGINTRACKA, HDN_BEGINTRACKW:
     200        DoColumnBeginResize(PHDNotify(vMsgNotify.NMHdr)^.Item);
     201
     202      HDN_TRACKA, HDN_TRACKW:
     203        begin
     204          vColWidth := -1;
     205          if (PHDNotify(vMsgNotify.NMHdr)^.PItem<>nil)
     206             and (PHDNotify(vMsgNotify.NMHdr)^.PItem^.Mask and HDI_WIDTH <> 0)
     207          then
     208            vColWidth := PHDNotify(vMsgNotify.NMHdr)^.PItem^.cxy;
     209
     210          DoColumnResizing(PHDNotify(vMsgNotify.NMHdr)^.Item, vColWidth);
     211        end;
     212    end;
     213  end;
     214end;
     215
     216procedure TListViewSort.DoColumnBeginResize(const AColIndex: Integer);
     217begin
     218end;
     219
     220procedure TListViewSort.DoColumnResizing(const AColIndex, AWidth: Integer);
     221begin
     222end;
     223
     224procedure TListViewSort.DoColumnResized(const AColIndex: Integer);
     225begin
     226  if Assigned(FOnColumnWidthChanged) then
     227    FOnColumnWidthChanged(Self);
     228end;
    165229
    166230procedure TListViewSort.ColumnClick(Sender: TObject; Column: TListColumn);
     
    189253procedure TListViewSort.SetListView(const Value: TListView);
    190254begin
     255  if FListView = Value then Exit;
     256  if Assigned(FListView) then
     257    ListView.WindowProc := FOldListViewWindowProc;
    191258  FListView := Value;
    192259  FListView.OnColumnClick := ColumnClick;
    193260  FListView.OnCustomDrawItem := ListViewCustomDrawItem;
    194261  FListView.OnClick := ListViewClick;
     262  FOldListViewWindowProc := FListView.WindowProc;
     263  FListView.WindowProc := NewListViewWindowProc;
    195264end;
    196265
Note: See TracChangeset for help on using the changeset viewer.