mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 03:19:25 +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;
|
FWidth: Integer;
|
||||||
FIndex: Integer; // index of TListColumn
|
FIndex: Integer; // index of TListColumn
|
||||||
fTextWithIcon: Boolean;
|
fTextWithIcon: Boolean;
|
||||||
|
FAutoSize: Boolean;
|
||||||
|
|
||||||
procedure UpdateHeader;
|
procedure UpdateHeader;
|
||||||
function GetHeaderWidth: UInt16;
|
function GetHeaderWidth: UInt16;
|
||||||
@ -72,13 +73,14 @@ type
|
|||||||
public
|
public
|
||||||
function GetWidth: Integer;
|
function GetWidth: Integer;
|
||||||
procedure SetAlignment(AAlignment: TAlignment);
|
procedure SetAlignment(AAlignment: TAlignment);
|
||||||
// TODO: SetAutoSize
|
procedure SetAutoSize(AValue: Boolean);
|
||||||
procedure SetCaption(const ACaption: String);
|
procedure SetCaption(const ACaption: String);
|
||||||
procedure SetImageIndex(AImageIndex: Integer);
|
procedure SetImageIndex(AImageIndex: Integer);
|
||||||
procedure SetMinWidth(AMinWidth: Integer);
|
procedure SetMinWidth(AMinWidth: Integer);
|
||||||
procedure SetMaxWidth(AMaxWidth: Integer);
|
procedure SetMaxWidth(AMaxWidth: Integer);
|
||||||
procedure SetVisible(AVisible: Boolean);
|
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;
|
property TextWithIcon: Boolean read fTextWithIcon write fTextWithIcon;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -186,6 +188,7 @@ type
|
|||||||
procedure MoveColumn(AOldIndex, ANewIndex: Integer; const AColumn: TListColumn);
|
procedure MoveColumn(AOldIndex, ANewIndex: Integer; const AColumn: TListColumn);
|
||||||
procedure UpdateColumnIndex;
|
procedure UpdateColumnIndex;
|
||||||
procedure UpdateColumnView; virtual;
|
procedure UpdateColumnView; virtual;
|
||||||
|
procedure AutoSizeColumns;
|
||||||
|
|
||||||
procedure ClearItems;
|
procedure ClearItems;
|
||||||
procedure DeleteItem(AIndex: Integer);
|
procedure DeleteItem(AIndex: Integer);
|
||||||
@ -543,6 +546,11 @@ begin
|
|||||||
if FVisible then UpdateHeader;
|
if FVisible then UpdateHeader;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCarbonListColumn.SetAutoSize(AValue: Boolean);
|
||||||
|
begin
|
||||||
|
FAutoSize := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCarbonListColumn.SetCaption(const ACaption: String);
|
procedure TCarbonListColumn.SetCaption(const ACaption: String);
|
||||||
begin
|
begin
|
||||||
FreeCFString(FDesc.headerBtnDesc.titleString);
|
FreeCFString(FDesc.headerBtnDesc.titleString);
|
||||||
@ -583,21 +591,11 @@ begin
|
|||||||
else Remove;
|
else Remove;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCarbonListColumn.SetWidth(AWidth: Integer; AAutoSize: Boolean);
|
procedure TCarbonListColumn.SetWidth(AWidth: Integer);
|
||||||
var
|
var
|
||||||
lBmp: TBitmap;
|
lBmp: TBitmap;
|
||||||
begin
|
begin
|
||||||
// Implements Column Autosizing
|
FWidth := AWidth;
|
||||||
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);
|
if FVisible then SetHeaderWidth(FWidth);
|
||||||
end;
|
end;
|
||||||
@ -1496,6 +1494,29 @@ begin
|
|||||||
|
|
||||||
end;
|
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);
|
procedure TCarbonDataBrowser.DeleteItem(AIndex: Integer);
|
||||||
var
|
var
|
||||||
Item : DataBrowserItemID;
|
Item : DataBrowserItemID;
|
||||||
|
@ -103,7 +103,7 @@ type
|
|||||||
class procedure ColumnInsert(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn); override;
|
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 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 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 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 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;
|
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);
|
TCarbonListView(ALV.Handle).GetColumn(AIndex).SetAlignment(AAlignment);
|
||||||
end;
|
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;
|
class procedure TCarbonWSCustomListView.ColumnSetCaption(const ALV: TCustomListView;
|
||||||
const AIndex: Integer; const AColumn: TListColumn; const ACaption: String);
|
const AIndex: Integer; const AColumn: TListColumn; const ACaption: String);
|
||||||
begin
|
begin
|
||||||
@ -559,7 +568,8 @@ begin
|
|||||||
if not CheckHandle(ALV, Self, 'ColumnSetWidth') then Exit;
|
if not CheckHandle(ALV, Self, 'ColumnSetWidth') then Exit;
|
||||||
|
|
||||||
Column := TCarbonListView(ALV.Handle).GetColumn(AIndex);
|
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;
|
end;
|
||||||
|
|
||||||
class procedure TCarbonWSCustomListView.ColumnSetVisible(const ALV: TCustomListView;
|
class procedure TCarbonWSCustomListView.ColumnSetVisible(const ALV: TCustomListView;
|
||||||
|
Loading…
Reference in New Issue
Block a user