Changeset 100


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.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/AcronymDecoder.lpi

    r97 r100  
    212212      <local>
    213213        <FormatVersion Value="1"/>
     214        <CommandLineParams Value="&quot;c:\Users\h160817\Projects\fpc\Acronym Decoder\trunk\Example acronyms.adp&quot;"/>
    214215      </local>
    215216    </RunParams>
  • trunk/Forms/UFormAcronyms.lfm

    r85 r100  
    5353  object StatusBar1: TStatusBar
    5454    Left = 0
    55     Height = 28
    56     Top = 530
     55    Height = 24
     56    Top = 534
    5757    Width = 740
    5858    Panels = <   
     
    6868    Left = 0
    6969    Height = 26
    70     Top = 504
     70    Top = 508
    7171    Width = 740
    7272    Align = alBottom
     
    9696    OnCompareItem = ListViewSort1CompareItem
    9797    OnFilter = ListViewSort1Filter
     98    OnColumnWidthChanged = ListViewSort1ColumnWidthChanged
    9899    Column = 0
    99100    Order = soUp
  • trunk/Forms/UFormAcronyms.pas

    r97 r100  
    4545      Selected: Boolean);
    4646    procedure ListViewFilter1Change(Sender: TObject);
     47    procedure ListViewSort1ColumnWidthChanged(Sender: TObject);
    4748    function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
    4849    procedure ListViewSort1Filter(ListViewSort: TListViewSort);
     
    235236end;
    236237
     238procedure TFormAcronyms.ListViewSort1ColumnWidthChanged(Sender: TObject);
     239begin
     240  ListViewFilter1.UpdateFromListView(ListViewAcronyms);
     241end;
     242
    237243function TFormAcronyms.ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
    238244begin
  • trunk/Forms/UFormImportSources.lfm

    r85 r100  
    307307    OnCompareItem = ListViewSort1CompareItem
    308308    OnFilter = ListViewSort1Filter
     309    OnColumnWidthChanged = ListViewSort1ColumnWidthChanged
    309310    Column = 0
    310311    Order = soNone
  • trunk/Forms/UFormImportSources.pas

    r97 r100  
    5656      Selected: Boolean);
    5757    procedure ListViewFilter1Change(Sender: TObject);
     58    procedure ListViewSort1ColumnWidthChanged(Sender: TObject);
    5859    function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
    5960    procedure ListViewSort1Filter(ListViewSort: TListViewSort);
     
    128129end;
    129130
     131procedure TFormImportSources.ListViewSort1ColumnWidthChanged(Sender: TObject);
     132begin
     133  ListViewFilter1.UpdateFromListView(ListView1);
     134end;
     135
    130136function TFormImportSources.ListViewSort1CompareItem(Item1, Item2: TObject
    131137  ): Integer;
     
    235241var
    236242  NewImportSource: TImportSource;
    237   I: Integer;
    238243begin
    239244  if Assigned(ListView1.Selected) then begin
  • trunk/Forms/UFormMain.lfm

    r97 r100  
    11object FormMain: TFormMain
    2   Left = 603
     2  Left = 454
    33  Height = 446
    4   Top = 342
     4  Top = 401
    55  Width = 782
    66  Caption = 'Acronym Decoder'
    7   ClientHeight = 421
     7  ClientHeight = 422
    88  ClientWidth = 782
    99  Menu = MainMenu1
     
    1717  object Panel1: TPanel
    1818    Left = 0
    19     Height = 395
     19    Height = 396
    2020    Top = 26
    2121    Width = 782
    2222    Align = alClient
    2323    BevelOuter = bvNone
    24     ClientHeight = 395
     24    ClientHeight = 396
    2525    ClientWidth = 782
    2626    TabOrder = 1
    2727    object CheckBoxExactMath: TCheckBox
    2828      Left = 8
    29       Height = 24
     29      Height = 21
    3030      Top = 3
    31       Width = 104
     31      Width = 102
    3232      Caption = 'Exact match'
    3333      OnChange = CheckBoxExactMathChange
     
    4444    object ListViewAcronyms: TListView
    4545      Left = 8
    46       Height = 323
     46      Height = 324
    4747      Top = 64
    4848      Width = 767
     
    14341434    OnCompareItem = ListViewSort1CompareItem
    14351435    OnFilter = ListViewSort1Filter
     1436    OnColumnWidthChanged = ListViewSort1ColumnWidthChanged
    14361437    Column = 0
    14371438    Order = soUp
  • trunk/Forms/UFormMain.pas

    r98 r100  
    116116      Selected: Boolean);
    117117    procedure ListViewFilter1Change(Sender: TObject);
     118    procedure ListViewSort1ColumnWidthChanged(Sender: TObject);
    118119    function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
    119120    procedure ListViewSort1Filter(ListViewSort: TListViewSort);
     
    452453begin
    453454  UpdateAcronymsList;
     455end;
     456
     457procedure TFormMain.ListViewSort1ColumnWidthChanged(Sender: TObject);
     458begin
     459  ListViewFilter1.UpdateFromListView(ListViewAcronyms);
    454460end;
    455461
  • 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.