Implements column autosizing for TListView in Carbon

git-svn-id: trunk@27827 -
This commit is contained in:
sekelsenmat 2010-10-24 07:56:36 +00:00
parent 30b65050e7
commit 1323d7f8d1
2 changed files with 17 additions and 4 deletions

View File

@ -78,7 +78,7 @@ type
procedure SetMinWidth(AMinWidth: Integer);
procedure SetMaxWidth(AMaxWidth: Integer);
procedure SetVisible(AVisible: Boolean);
procedure SetWidth(AWidth: Integer);
procedure SetWidth(AWidth: Integer; AAutoSize: Boolean);
property TextWithIcon: Boolean read fTextWithIcon write fTextWithIcon;
end;
@ -581,9 +581,22 @@ begin
else Remove;
end;
procedure TCarbonListColumn.SetWidth(AWidth: Integer);
procedure TCarbonListColumn.SetWidth(AWidth: Integer; AAutoSize: Boolean);
var
lBmp: TBitmap;
begin
FWidth := AWidth;
// Implements Column Autosizing
if AAutoSize then
begin
lBmp := TBitmap.Create;
// The standard Mac listview font is quite bigger then the standard TCanvas font
// plus, we also need an extra spacing
FWidth := lBmp.Canvas.TextWidth(FListColumn.Caption) * 2;
lBmp.Free;
end
else
FWidth := AWidth;
if FVisible then SetHeaderWidth(FWidth);
end;

View File

@ -356,7 +356,7 @@ begin
if not CheckHandle(ALV, Self, 'ColumnSetWidth') then Exit;
Column := TCarbonListView(ALV.Handle).GetColumn(AIndex);
if Column <> nil then Column.SetWidth(AWidth); // Avoids crash
if Column <> nil then Column.SetWidth(AWidth, AColumn.AutoSize); // Avoids crash
end;
class procedure TCarbonWSCustomListView.ColumnSetVisible(const ALV: TCustomListView;