Changeset 38 for trunk/Components/Common/UListViewSort.pas
- Timestamp:
- Apr 18, 2019, 3:34:38 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/Common/UListViewSort.pas
r34 r38 9 9 uses 10 10 {$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, 12 12 LclIntf, LMessages, LclType, LResources; 13 13 … … 52 52 {$ENDIF} 53 53 public 54 List: T ListObject;55 Source: T ListObject;54 List: TFPGObjectList<TObject>; 55 Source: TFPGObjectList<TObject>; 56 56 constructor Create(AOwner: TComponent); override; 57 57 destructor Destroy; override; … … 81 81 FOnChange: TNotifyEvent; 82 82 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); 85 85 public 86 86 constructor Create(AOwner: TComponent); override; … … 98 98 end; 99 99 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 100 118 procedure Register; 101 119 … … 105 123 procedure Register; 106 124 begin 107 RegisterComponents('Common', [TListViewSort, TListViewFilter]); 125 RegisterComponents('Common', [TListViewSort, TListViewFilter, TListViewEx]); 126 end; 127 128 { TListViewEx } 129 130 procedure TListViewEx.ResizeHanlder; 131 begin 132 end; 133 134 constructor TListViewEx.Create(TheOwner: TComponent); 135 begin 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; 145 end; 146 147 destructor TListViewEx.Destroy; 148 begin 149 inherited Destroy; 108 150 end; 109 151 110 152 { TListViewFilter } 111 153 112 procedure TListViewFilter. DoOnKeyUp(Sender: TObject; var Key: Word;154 procedure TListViewFilter.GridDoOnKeyUp(Sender: TObject; var Key: Word; 113 155 Shift: TShiftState); 114 156 begin … … 117 159 end; 118 160 119 procedure TListViewFilter. DoOnResize(Sender: TObject);161 procedure TListViewFilter.GridDoOnResize(Sender: TObject); 120 162 begin 121 163 FStringGrid1.DefaultRowHeight := FStringGrid1.Height; … … 135 177 FStringGrid1.Options := [goFixedHorzLine, goFixedVertLine, goVertLine, 136 178 goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll]; 137 FStringGrid1.OnKeyUp := DoOnKeyUp;138 FStringGrid1.OnResize := DoOnResize;179 FStringGrid1.OnKeyUp := GridDoOnKeyUp; 180 FStringGrid1.OnResize := GridDoOnResize; 139 181 end; 140 182 … … 142 184 var 143 185 I: Integer; 186 R: TRect; 144 187 begin 145 188 with FStringGrid1 do begin 146 //Columns.Clear;147 189 while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1); 148 190 while Columns.Count < ListView.Columns.Count do Columns.Add; 149 191 for I := 0 to ListView.Columns.Count - 1 do begin 150 192 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; 151 198 end; 152 199 end; … … 197 244 if AMsg.Msg = WM_NOTIFY then 198 245 begin 199 Code := PHDNotify(vMsgNotify.NMHdr)^.Hdr.Code;246 Code := NMHDR(PHDNotify(vMsgNotify.NMHdr)^.Hdr).Code; 200 247 case Code of 201 248 HDN_ENDTRACKA, HDN_ENDTRACKW: … … 272 319 end; 273 320 321 var 322 ListViewSortCompare: TCompareEvent; 323 324 function ListViewCompare(const Item1, Item2: TObject): Integer; 325 begin 326 Result := ListViewSortCompare(Item1, Item2); 327 end; 328 274 329 procedure TListViewSort.Sort(Compare: TCompareEvent); 275 330 begin 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; 276 334 if (List.Count > 0) then 277 List.Sort( Compare);335 List.Sort(ListViewCompare); 278 336 end; 279 337 … … 338 396 begin 339 397 inherited; 340 List := T ListObject.Create;341 List. OwnsObjects := False;398 List := TFPGObjectList<TObject>.Create; 399 List.FreeObjects := False; 342 400 end; 343 401 … … 353 411 TP1: TPoint; 354 412 XBias, YBias: Integer; 355 OldColor: TColor; 413 PenColor: TColor; 414 BrushColor: TColor; 356 415 BiasTop, BiasLeft: Integer; 357 416 Rect1: TRect; … … 365 424 Item.Left := 0; 366 425 GetCheckBias(XBias, YBias, BiasTop, BiasLeft, ListView); 367 OldColor := ListView.Canvas.Pen.Color; 426 PenColor := ListView.Canvas.Pen.Color; 427 BrushColor := ListView.Canvas.Brush.Color; 368 428 //TP1 := Item.GetPosition; 369 429 lRect := Item.DisplayRect(drBounds); // Windows 7 workaround … … 377 437 ItemLeft := Item.Left; 378 438 ItemLeft := 23; // Windows 7 workaround 379 439 380 440 Rect1.Left := ItemLeft - CheckWidth - BiasLeft + 1 + XBias; 381 441 //ShowMessage(IntToStr(Tp1.Y) + ', ' + IntToStr(BiasTop) + ', ' + IntToStr(XBias)); … … 408 468 end; 409 469 //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; 412 472 end; 413 473 … … 476 536 FHeaderHandle := ListView_GetHeader(FListView.Handle); 477 537 for I := 0 to FListView.Columns.Count - 1 do begin 538 {$push}{$warn 5057 off} 478 539 FillChar(Item, SizeOf(THDItem), 0); 540 {$pop} 479 541 Item.Mask := HDI_FORMAT; 480 542 Header_GetItem(FHeaderHandle, I, Item);
Note:
See TracChangeset
for help on using the changeset viewer.