mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-08 20:35:58 +02:00
carbon: implemented autosizing for listview / databrowser columns.patch by David Jenkins. issue #21745
git-svn-id: trunk@36961 -
This commit is contained in:
parent
e52ef19ca6
commit
b0314bb620
@ -50,6 +50,7 @@ type
|
||||
FWidth: Integer;
|
||||
FIndex: Integer; // index of TListColumn
|
||||
fTextWithIcon: Boolean;
|
||||
FAutoSize: Boolean;
|
||||
|
||||
procedure UpdateHeader;
|
||||
function GetHeaderWidth: UInt16;
|
||||
@ -72,13 +73,14 @@ type
|
||||
public
|
||||
function GetWidth: Integer;
|
||||
procedure SetAlignment(AAlignment: TAlignment);
|
||||
// TODO: SetAutoSize
|
||||
procedure SetAutoSize(AValue: Boolean);
|
||||
procedure SetCaption(const ACaption: String);
|
||||
procedure SetImageIndex(AImageIndex: Integer);
|
||||
procedure SetMinWidth(AMinWidth: Integer);
|
||||
procedure SetMaxWidth(AMaxWidth: Integer);
|
||||
procedure SetVisible(AVisible: Boolean);
|
||||
procedure SetWidth(AWidth: Integer; AAutoSize: Boolean);
|
||||
procedure SetWidth(AWidth: Integer);
|
||||
property AutoSize: Boolean read FAutoSize write SetAutoSize;
|
||||
property TextWithIcon: Boolean read fTextWithIcon write fTextWithIcon;
|
||||
end;
|
||||
|
||||
@ -186,6 +188,7 @@ type
|
||||
procedure MoveColumn(AOldIndex, ANewIndex: Integer; const AColumn: TListColumn);
|
||||
procedure UpdateColumnIndex;
|
||||
procedure UpdateColumnView; virtual;
|
||||
procedure AutoSizeColumns;
|
||||
|
||||
procedure ClearItems;
|
||||
procedure DeleteItem(AIndex: Integer);
|
||||
@ -543,6 +546,11 @@ begin
|
||||
if FVisible then UpdateHeader;
|
||||
end;
|
||||
|
||||
procedure TCarbonListColumn.SetAutoSize(AValue: Boolean);
|
||||
begin
|
||||
FAutoSize := AValue;
|
||||
end;
|
||||
|
||||
procedure TCarbonListColumn.SetCaption(const ACaption: String);
|
||||
begin
|
||||
FreeCFString(FDesc.headerBtnDesc.titleString);
|
||||
@ -583,21 +591,11 @@ begin
|
||||
else Remove;
|
||||
end;
|
||||
|
||||
procedure TCarbonListColumn.SetWidth(AWidth: Integer; AAutoSize: Boolean);
|
||||
procedure TCarbonListColumn.SetWidth(AWidth: Integer);
|
||||
var
|
||||
lBmp: TBitmap;
|
||||
begin
|
||||
// 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;
|
||||
FWidth := AWidth;
|
||||
|
||||
if FVisible then SetHeaderWidth(FWidth);
|
||||
end;
|
||||
@ -1496,6 +1494,29 @@ begin
|
||||
|
||||
end;
|
||||
|
||||
procedure TCarbonDataBrowser.AutoSizeColumns;
|
||||
var cnt, aCnt, tCnt: Integer;
|
||||
sWidth, aWidth: Integer;
|
||||
cRect: TRect;
|
||||
begin
|
||||
GetClientRect(cRect);
|
||||
sWidth := 0;
|
||||
aCnt := 0;
|
||||
tCnt := 0;
|
||||
while GetColumn(tCnt) <> nil do begin
|
||||
if GetColumn(tCnt).AutoSize then Inc(aCnt)
|
||||
else Inc(sWidth, GetColumn(tCnt).GetWidth);
|
||||
Inc(tCnt);
|
||||
end;
|
||||
|
||||
if aCnt > 0 then begin
|
||||
aWidth := ((cRect.Right - cRect.Left) - sWidth) div aCnt;
|
||||
for cnt := 0 to tCnt - 1 do
|
||||
if GetColumn(cnt).AutoSize then
|
||||
GetColumn(cnt).SetWidth(aWidth);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCarbonDataBrowser.DeleteItem(AIndex: Integer);
|
||||
var
|
||||
Item : DataBrowserItemID;
|
||||
|
@ -103,7 +103,7 @@ type
|
||||
class procedure ColumnInsert(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn); override;
|
||||
class procedure ColumnMove(const ALV: TCustomListView; const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn); override;
|
||||
class procedure ColumnSetAlignment(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAlignment: TAlignment); override;
|
||||
//class procedure ColumnSetAutoSize(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean); override;
|
||||
class procedure ColumnSetAutoSize(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean); override;
|
||||
class procedure ColumnSetCaption(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const ACaption: String); override;
|
||||
class procedure ColumnSetImage(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AImageIndex: Integer); override;
|
||||
class procedure ColumnSetMaxWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMaxWidth: Integer); override;
|
||||
@ -519,6 +519,15 @@ begin
|
||||
TCarbonListView(ALV.Handle).GetColumn(AIndex).SetAlignment(AAlignment);
|
||||
end;
|
||||
|
||||
class procedure TCarbonWSCustomListView.ColumnSetAutoSize(const ALV: TCustomListView;
|
||||
const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean);
|
||||
begin
|
||||
if not CheckHandle(ALV, Self, 'ColumnSetAutoSize') then Exit;
|
||||
|
||||
TCarbonListView(ALV.Handle).GetColumn(AIndex).SetAutoSize(AAutoSize);
|
||||
TCarbonListView(ALV.Handle).AutoSizeColumns;
|
||||
end;
|
||||
|
||||
class procedure TCarbonWSCustomListView.ColumnSetCaption(const ALV: TCustomListView;
|
||||
const AIndex: Integer; const AColumn: TListColumn; const ACaption: String);
|
||||
begin
|
||||
@ -559,7 +568,8 @@ begin
|
||||
if not CheckHandle(ALV, Self, 'ColumnSetWidth') then Exit;
|
||||
|
||||
Column := TCarbonListView(ALV.Handle).GetColumn(AIndex);
|
||||
if Column <> nil then Column.SetWidth(AWidth, AColumn.AutoSize); // Avoids crash
|
||||
if Column <> nil then Column.SetWidth(AWidth); // Avoids crash
|
||||
TCarbonListView(ALV.Handle).AutoSizeColumns;
|
||||
end;
|
||||
|
||||
class procedure TCarbonWSCustomListView.ColumnSetVisible(const ALV: TCustomListView;
|
||||
|
Loading…
Reference in New Issue
Block a user