Changeset 130 for ListViewSort
- Timestamp:
- Jan 19, 2011, 11:07:07 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ListViewSort/UListViewSort.pas
r99 r130 6 6 7 7 uses 8 Windows, Types, Classes, ComCtrls, Contnrs, Graphics, SysUtils, StdCtrls, Controls,9 DateUtils, CommCtrl;8 Windows, Types, Classes, ComCtrls, Contnrs, Graphics, SysUtils, StdCtrls, 9 Controls, DateUtils, CommCtrl, Dialogs, SpecializedList; 10 10 11 11 type … … 28 28 procedure SetListView(const Value: TListView); 29 29 procedure ColumnClick(Sender: TObject; Column: TListColumn); 30 procedure QuickSort(SortList: TObjectList; L, R: Integer;31 SCompare: TCompareEvent);32 30 procedure Sort(Compare: TCompareEvent); 33 31 procedure DrawCheckMark(Item: TListItem; Checked: Boolean); … … 41 39 procedure SetOrder(const Value: TSortOrder); 42 40 public 43 List: T ObjectList;44 Source: T ObjectList;41 List: TListObject; 42 Source: TListObject; 45 43 constructor Create; 46 44 destructor Destroy; override; … … 100 98 begin 101 99 if (List.Count > 0) then 102 QuickSort(List, 0, List.Count - 1, Compare); 103 end; 104 105 procedure TListViewSort.QuickSort(SortList: TObjectList; L, R: Integer; 106 SCompare: TCompareEvent); 107 var 108 I, J: Integer; 109 P, T: Pointer; 110 begin 111 repeat 112 I := L; 113 J := R; 114 P := SortList[(L + R) shr 1]; 115 repeat 116 while SCompare(SortList[I], P) < 0 do 117 Inc(I); 118 while SCompare(SortList[J], P) > 0 do 119 Dec(J); 120 if I <= J then 121 begin 122 T := SortList[I]; 123 SortList[I] := SortList[J]; 124 SortList[J] := T; 125 Inc(I); 126 Dec(J); 127 end; 128 until I > J; 129 if L < J then 130 QuickSort(SortList, L, J, SCompare); 131 L := I; 132 until I >= R; 133 end; 134 100 List.Sort(Compare); 101 end; 135 102 136 103 procedure TListViewSort.Refresh; … … 143 110 ListView.Items.Count := List.Count; 144 111 if Assigned(FOnCompareItem) then Sort(FOnCompareItem); 112 ListView.Items[-1]; // Workaround for not show first row if selected 145 113 ListView.Refresh; 114 // Workaround for not working item selection on first row 115 if not Assigned(ListView.Selected) then begin 116 ListView.Items.Count := 0; 117 ListView.Items.Count := List.Count; 118 end; 119 //if ListView.Items.Count > 0 then 120 // ListView.Items[0].Selected := True; 121 //ListView.Selected := nil; 146 122 UpdateColumns; 147 123 end; 148 124 149 125 const 150 W_64: Word= 64; {Width of thumbnail in ICON view mode}151 H_64: Word= 64; {Height of thumbnail size}152 CheckWidth: Word= 14; {Width of check mark box}153 CheckHeight: Word= 14; {Height of checkmark}154 CheckBiasTop: Word= 2; {This aligns the checkbox to be in centered}155 CheckBiasLeft: Word= 3; {In the row of the list item display}126 W_64: Integer = 64; {Width of thumbnail in ICON view mode} 127 H_64: Integer = 64; {Height of thumbnail size} 128 CheckWidth: Integer = 14; {Width of check mark box} 129 CheckHeight: Integer = 14; {Height of checkmark} 130 CheckBiasTop: Integer = 2; {This aligns the checkbox to be in centered} 131 CheckBiasLeft: Integer = 3; {In the row of the list item display} 156 132 157 133 function TListViewSort.CompareBoolean(Value1, Value2: Boolean): Integer; … … 184 160 constructor TListViewSort.Create; 185 161 begin 186 List := T ObjectList.Create;162 List := TListObject.Create; 187 163 List.OwnsObjects := False; 188 164 end; … … 202 178 BiasTop, BiasLeft: Integer; 203 179 Rect1: TRect; 204 begin 180 lRect: TRect; 181 ItemLeft: Integer; 182 begin 183 Item.Left := 0; 205 184 GetCheckBias(XBias, YBias, BiasTop, BiasLeft, ListView); 206 185 OldColor := ListView.Canvas.Pen.Color; 207 TP1 := Item.GetPosition; 186 //TP1 := Item.GetPosition; 187 lRect := Item.DisplayRect(drBounds); // Windows 7 workaround 188 TP1.X := lRect.Left; 189 TP1.Y := lRect.Top; 190 //ShowMessage(IntToStr(Item.Index) + ', ' + IntToStr(GetScrollPos(Item.ListView.Handle, SB_VERT)) + ' ' + 191 // IntToHex(Integer(Item), 8) + ', ' + IntToStr(TP1.X) + ', ' + IntToStr(TP1.Y)); 192 208 193 // if Checked then 209 194 ListView.Canvas.Brush.Color := clWhite; 210 Rect1.Left := Item.Left - CheckWidth - BiasLeft + 1 + XBias; 195 ItemLeft := Item.Left; 196 ItemLeft := 23; // Windows 7 workaround 197 198 Rect1.Left := ItemLeft - CheckWidth - BiasLeft + 1 + XBias; 199 //ShowMessage(IntToStr(Tp1.Y) + ', ' + IntToStr(BiasTop) + ', ' + IntToStr(XBias)); 211 200 Rect1.Top := Tp1.Y + BiasTop + 1 + YBias; 212 Rect1.Right := Item .Left - BiasLeft - 1 + XBias;201 Rect1.Right := ItemLeft - BiasLeft - 1 + XBias; 213 202 Rect1.Bottom := Tp1.Y + BiasTop + CheckHeight - 1 + YBias; 203 //ShowMessage(IntToStr(Rect1.Left) + ', ' + IntToStr(Rect1.Top) + ', ' + IntToStr(Rect1.Right) + ', ' + IntToStr(Rect1.Bottom)); 204 214 205 ListView.Canvas.FillRect(Rect1); 215 206 //if Checked then ListView.Canvas.Brush.Color := clBlack … … 220 211 if Checked then begin 221 212 ListView.Canvas.Pen.Color := clBlack; 222 ListView.Canvas.MoveTo(Item .Left - BiasLeft - 2 + XBias - 2,213 ListView.Canvas.MoveTo(ItemLeft - BiasLeft - 2 + XBias - 2, 223 214 Tp1.Y + BiasTop + 3 + YBias); 224 ListView.Canvas.LineTo(Item .Left - BiasLeft - (CheckWidth div 2) + XBias,215 ListView.Canvas.LineTo(ItemLeft - BiasLeft - (CheckWidth div 2) + XBias, 225 216 Tp1.Y + BiasTop + (CheckHeight - 4) + YBias); 226 ListView.Canvas.LineTo(Item .Left - BiasLeft - (CheckWidth - 3) + XBias,217 ListView.Canvas.LineTo(ItemLeft - BiasLeft - (CheckWidth - 3) + XBias, 227 218 Tp1.Y + BiasTop + (CheckHeight div 2) + YBias - 1); 228 219 229 ListView.Canvas.MoveTo(Item .Left - BiasLeft - 2 - 1 + XBias - 2,220 ListView.Canvas.MoveTo(ItemLeft - BiasLeft - 2 - 1 + XBias - 2, 230 221 Tp1.Y + BiasTop + 3 + YBias); 231 ListView.Canvas.LineTo(Item .Left - BiasLeft - (CheckWidth div 2) - 1 + XBias,222 ListView.Canvas.LineTo(ItemLeft - BiasLeft - (CheckWidth div 2) - 1 + XBias, 232 223 Tp1.Y + BiasTop + (CheckHeight - 4) + YBias); 233 ListView.Canvas.LineTo(Item .Left - BiasLeft - (CheckWidth - 3) - 1 + XBias,224 ListView.Canvas.LineTo(ItemLeft - BiasLeft - (CheckWidth - 3) - 1 + XBias, 234 225 Tp1.Y + BiasTop + (CheckHeight div 2) + YBias - 1); 235 226 end; 236 ListView.Canvas.Brush.Color := ListView.Color; 227 //ListView.Canvas.Brush.Color := ListView.Color; 228 ListView.Canvas.Brush.Color := clWindow; 237 229 ListView.Canvas.Pen.Color := OldColor; 238 230 end; … … 260 252 Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean); 261 253 begin 262 if ListView.Checkboxes then 263 DrawCheckMark(Item, Item.Checked); 264 if Assigned(FOnCustomDraw) then 265 FOnCustomDraw(Sender, Item, State, DefaultDraw); 254 if Assigned(Item) then begin 255 if ListView.Checkboxes then 256 DrawCheckMark(Item, Item.Checked); 257 if Assigned(FOnCustomDraw) then 258 FOnCustomDraw(Sender, Item, State, DefaultDraw); 259 end; 266 260 end; 267 261 … … 270 264 Item: TListItem; 271 265 Pos: TPoint; 266 DefaultDraw: Boolean; 272 267 begin 273 268 Pos := ListView.ScreenToClient(Mouse.CursorPos); 274 269 Item := ListView.GetItemAt(Pos.X, Pos.Y); 270 //ShowMessage(IntToStr(Item.Index) + ', ' + IntToStr(Pos.X) + ', ' + IntToStr(Pos.Y)); 275 271 if Assigned(Item) and (Pos.X < 20) then begin 272 276 273 Item.Checked := not Item.Checked; 277 ListView.UpdateItems(Item.Index, Item.Index);274 //ShowMessage(IntToStr(Item.Index) + ', ' +BoolToStr(Item.Checked)); 278 275 if Assigned(ListView.OnChange) then 279 276 ListView.OnChange(Self, Item, ctState); 277 DefaultDraw := False; 278 ListViewCustomDrawItem(ListView, Item, [], DefaultDraw); 279 //ListView.UpdateItems(Item.Index, Item.Index); 280 280 end; 281 281 end;
Note:
See TracChangeset
for help on using the changeset viewer.