mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 14:09:16 +02:00
Cocoa/ListView: in vsReport, turn Magic Numbers into configurable named variables
This commit is contained in:
parent
d9ab162b23
commit
9c2c0a7ec7
@ -9,6 +9,50 @@ uses
|
|||||||
CocoaAll, Cocoa_Extra, CocoaConst;
|
CocoaAll, Cocoa_Extra, CocoaConst;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TCocoaConfigVSReportRow = record
|
||||||
|
defaultHeight: Integer;
|
||||||
|
imageLineSpacing: Integer;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigVSReportColumn = record
|
||||||
|
controlSpacing: Integer;
|
||||||
|
textFieldMinWidth: Integer;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigVSReportColumnAutoFit = record
|
||||||
|
// for performance, when the column divider is double-clicked to automatically
|
||||||
|
// calculate the column width, the maximum number of rows calculated
|
||||||
|
maxCalcRows: Integer;
|
||||||
|
// min Column Width when the column divider is double-clicked
|
||||||
|
minWidth: Double;
|
||||||
|
// additional width for header
|
||||||
|
headerAdditionalWidth: Double;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigVSReport = record
|
||||||
|
// default NSTableViewStyle
|
||||||
|
tableViewStyle: NSTableViewStyle;
|
||||||
|
row: TCocoaConfigVSReportRow;
|
||||||
|
column: TCocoaConfigVSReportColumn;
|
||||||
|
columnAutoFit: TCocoaConfigVSReportColumnAutoFit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigListView = record
|
||||||
|
vsReport: TCocoaConfigVSReport;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
CocoaConfigListView: TCocoaConfigListView = (
|
||||||
|
vsReport: (
|
||||||
|
tableViewStyle: NSTableViewStyleAutomatic;
|
||||||
|
row: ( defaultHeight: 16; imageLineSpacing: 4*2 );
|
||||||
|
column: ( controlSpacing: 4; textFieldMinWidth: 16 );
|
||||||
|
columnAutoFit: ( maxCalcRows: 100; minWidth: 20; headerAdditionalWidth: 4 );
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
// on macOS, the FocusRing takes up extra space, which may cause strange
|
// on macOS, the FocusRing takes up extra space, which may cause strange
|
||||||
// display in some cases. it may block other controls, or be partially cut off.
|
// display in some cases. it may block other controls, or be partially cut off.
|
||||||
// for example, in the Lazarus IDE - About dialog, the FocusRing of the
|
// for example, in the Lazarus IDE - About dialog, the FocusRing of the
|
||||||
@ -116,16 +160,6 @@ var
|
|||||||
CocoaAlwaysPresentNotification : Boolean = True;
|
CocoaAlwaysPresentNotification : Boolean = True;
|
||||||
|
|
||||||
|
|
||||||
// default NSTableViewStyle
|
|
||||||
CocoaTableViewStyle : NSTableViewStyle = NSTableViewStyleAutomatic;
|
|
||||||
|
|
||||||
// for performance, when the column divider is double-clicked to automatically
|
|
||||||
// calculate the column width, the maximum number of rows calculated
|
|
||||||
CocoaTableColumnAutoFitWidthCalcRows : Integer = 100;
|
|
||||||
|
|
||||||
// min Column Width when the column divider is double-clicked
|
|
||||||
CocoaTableColumnAutoFitWidthMin: Double = 20;
|
|
||||||
|
|
||||||
// for compatiblity with LCL 1.8 release. The macOS base is 72ppi
|
// for compatiblity with LCL 1.8 release. The macOS base is 72ppi
|
||||||
CocoaBasePPI : Integer = 96;
|
CocoaBasePPI : Integer = 96;
|
||||||
|
|
||||||
|
@ -249,9 +249,6 @@ function LCLCoordToRow(tbl: NSTableView; X,Y: Integer): Integer;
|
|||||||
function LCLGetItemRect(tbl: NSTableView; row, col: Integer; var r: TRect): Boolean;
|
function LCLGetItemRect(tbl: NSTableView; row, col: Integer; var r: TRect): Boolean;
|
||||||
function LCLGetTopRow(tbl: NSTableView): Integer;
|
function LCLGetTopRow(tbl: NSTableView): Integer;
|
||||||
|
|
||||||
const
|
|
||||||
DefaultRowHeight = 16; // per "rowHeight" property docs
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -683,7 +680,7 @@ function TCocoaTableListView.initWithFrame(frameRect: NSRect): id;
|
|||||||
begin
|
begin
|
||||||
Result:=inherited initWithFrame(frameRect);
|
Result:=inherited initWithFrame(frameRect);
|
||||||
if NSAppkitVersionNumber >= NSAppKitVersionNumber11_0 then
|
if NSAppkitVersionNumber >= NSAppKitVersionNumber11_0 then
|
||||||
setStyle( CocoaConfig.CocoaTableViewStyle );
|
setStyle( CocoaConfigListView.vsReport.tableViewStyle );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaTableListView.mouseDown(event: NSEvent);
|
procedure TCocoaTableListView.mouseDown(event: NSEvent);
|
||||||
@ -784,17 +781,18 @@ end;
|
|||||||
function TCocoaTableListView.tableView_heightOfRow(tableView: NSTableView;
|
function TCocoaTableListView.tableView_heightOfRow(tableView: NSTableView;
|
||||||
row: NSInteger): CGFloat;
|
row: NSInteger): CGFloat;
|
||||||
var
|
var
|
||||||
h : integer;
|
h: Integer;
|
||||||
begin
|
begin
|
||||||
h := CustomRowHeight;
|
h:= self.CustomRowHeight;
|
||||||
if h = 0 then h := DefaultRowHeight;
|
if h = 0 then
|
||||||
|
h:= CocoaConfigListView.vsReport.row.defaultHeight;
|
||||||
|
|
||||||
if isDynamicRowHeight and Assigned(self.callback) then
|
if isDynamicRowHeight and Assigned(self.callback) then begin
|
||||||
begin
|
self.callback.GetRowHeight( row, h );
|
||||||
self.callback.GetRowHeight(Integer(row), h);
|
|
||||||
if h<=0 then h:=1; // must be positive (non-zero)
|
if h<=0 then h:=1; // must be positive (non-zero)
|
||||||
end;
|
end;
|
||||||
Result := h;
|
|
||||||
|
Result:= h;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaTableListView.tableView_sizeToFitWidthOfColumn(
|
function TCocoaTableListView.tableView_sizeToFitWidthOfColumn(
|
||||||
@ -809,10 +807,11 @@ var
|
|||||||
tableColumn: NSTableColumn;
|
tableColumn: NSTableColumn;
|
||||||
currentWidth: CGFloat;
|
currentWidth: CGFloat;
|
||||||
begin
|
begin
|
||||||
Result:= CocoaConfig.CocoaTableColumnAutoFitWidthMin;
|
Result:= CocoaConfigListView.vsReport.columnAutoFit.minWidth;
|
||||||
tableColumn:= NSTableColumn( self.tableColumns.objectAtIndex(column) );
|
tableColumn:= NSTableColumn( self.tableColumns.objectAtIndex(column) );
|
||||||
tableColumn.sizeToFit;
|
tableColumn.sizeToFit;
|
||||||
currentWidth:= tableColumn.width + 4;
|
currentWidth:= tableColumn.width +
|
||||||
|
CocoaConfigListView.vsReport.columnAutoFit.headerAdditionalWidth;
|
||||||
if currentWidth > Result then
|
if currentWidth > Result then
|
||||||
Result:= currentWidth;
|
Result:= currentWidth;
|
||||||
|
|
||||||
@ -820,18 +819,18 @@ begin
|
|||||||
if totalCount = 0 then
|
if totalCount = 0 then
|
||||||
Exit;
|
Exit;
|
||||||
|
|
||||||
if totalCount <= CocoaConfig.CocoaTableColumnAutoFitWidthCalcRows then begin
|
if totalCount <= CocoaConfigListView.vsReport.columnAutoFit.maxCalcRows then begin
|
||||||
startIndex:= 0;
|
startIndex:= 0;
|
||||||
endIndex:= totalCount - 1;
|
endIndex:= totalCount - 1;
|
||||||
end else begin
|
end else begin
|
||||||
startIndex:= self.rowsInRect(self.visibleRect).location;
|
startIndex:= self.rowsInRect(self.visibleRect).location;
|
||||||
endIndex:= startIndex + CocoaConfig.CocoaTableColumnAutoFitWidthCalcRows div 2;
|
endIndex:= startIndex + CocoaConfigListView.vsReport.columnAutoFit.maxCalcRows div 2;
|
||||||
if endIndex > totalCount - 1 then
|
if endIndex > totalCount - 1 then
|
||||||
endIndex:= totalCount - 1;
|
endIndex:= totalCount - 1;
|
||||||
startIndex:= endIndex - CocoaConfig.CocoaTableColumnAutoFitWidthCalcRows + 1;
|
startIndex:= endIndex - CocoaConfigListView.vsReport.columnAutoFit.maxCalcRows + 1;
|
||||||
if startIndex < 0 then
|
if startIndex < 0 then
|
||||||
startIndex:= 0;
|
startIndex:= 0;
|
||||||
endIndex:= startIndex + CocoaConfig.CocoaTableColumnAutoFitWidthCalcRows - 1;
|
endIndex:= startIndex + CocoaConfigListView.vsReport.columnAutoFit.maxCalcRows - 1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
for row:=startIndex to endIndex do begin
|
for row:=startIndex to endIndex do begin
|
||||||
@ -1117,9 +1116,11 @@ var
|
|||||||
begin
|
begin
|
||||||
width:= self.textField.fittingSize.width;
|
width:= self.textField.fittingSize.width;
|
||||||
if Assigned(_checkBox) then
|
if Assigned(_checkBox) then
|
||||||
width:= width + _checkBox.frame.size.width + 4;
|
width:= width + _checkBox.frame.size.width +
|
||||||
|
CocoaConfigListView.vsReport.column.controlSpacing;
|
||||||
if Assigned(self.imageView) then
|
if Assigned(self.imageView) then
|
||||||
width:= width + self.imageView.frame.size.width + 4;
|
width:= width + self.imageView.frame.size.width +
|
||||||
|
CocoaConfigListView.vsReport.column.controlSpacing;
|
||||||
Result.width:= width;
|
Result.width:= width;
|
||||||
Result.height:= self.frame.size.height;
|
Result.height:= self.frame.size.height;
|
||||||
end;
|
end;
|
||||||
@ -1277,7 +1278,7 @@ begin
|
|||||||
aFrame.origin.y:= round( (rowHeight - aFrame.size.height ) / 2 );
|
aFrame.origin.y:= round( (rowHeight - aFrame.size.height ) / 2 );
|
||||||
_checkBox.setFrameOrigin( aFrame.origin );
|
_checkBox.setFrameOrigin( aFrame.origin );
|
||||||
|
|
||||||
aFrame.origin.x:= 4;
|
aFrame.origin.x:= CocoaConfigListView.vsReport.column.controlSpacing;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Assigned(self.imageView) then begin
|
if Assigned(self.imageView) then begin
|
||||||
@ -1286,7 +1287,7 @@ begin
|
|||||||
aFrame.size:= tv.iconSize;
|
aFrame.size:= tv.iconSize;
|
||||||
self.imageView.setFrame( aFrame );
|
self.imageView.setFrame( aFrame );
|
||||||
|
|
||||||
aFrame.origin.x:= aFrame.origin.x + 4;
|
aFrame.origin.x:= aFrame.origin.x + CocoaConfigListView.vsReport.column.controlSpacing;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Assigned(self.textField) then begin
|
if Assigned(self.textField) then begin
|
||||||
@ -1295,8 +1296,8 @@ begin
|
|||||||
aFrame.origin.y:= round( (rowHeight - self.textField.frame.size.height) / 2 );
|
aFrame.origin.y:= round( (rowHeight - self.textField.frame.size.height) / 2 );
|
||||||
aFrame.size.width:= _column.width - aFrame.origin.x;
|
aFrame.size.width:= _column.width - aFrame.origin.x;
|
||||||
aFrame.size.height:= self.textField.frame.size.height;
|
aFrame.size.height:= self.textField.frame.size.height;
|
||||||
if aFrame.size.width < 16 then
|
if aFrame.size.width < CocoaConfigListView.vsReport.column.textFieldMinWidth then
|
||||||
aFrame.size.width:= 16;
|
aFrame.size.width:= CocoaConfigListView.vsReport.column.textFieldMinWidth;
|
||||||
self.textField.setFrame( aFrame );
|
self.textField.setFrame( aFrame );
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1852,7 +1853,8 @@ begin
|
|||||||
|
|
||||||
_tableView.iconSize.Width:= AValue.Width;
|
_tableView.iconSize.Width:= AValue.Width;
|
||||||
_tableView.iconSize.Height:= AValue.Height;
|
_tableView.iconSize.Height:= AValue.Height;
|
||||||
_tableView.CustomRowHeight:= AValue.Height + 8;
|
_tableView.CustomRowHeight:= AValue.Height +
|
||||||
|
CocoaConfigListView.vsReport.row.imageLineSpacing;
|
||||||
|
|
||||||
_tableView.reloadData;
|
_tableView.reloadData;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user