mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 20:39:14 +02:00
Cocoa/ListView: turn Magic Numbers into configurable named variables
This commit is contained in:
commit
ee92dc809b
@ -43,7 +43,7 @@ type
|
|||||||
function isSupportIcon: Boolean; virtual;
|
function isSupportIcon: Boolean; virtual;
|
||||||
procedure onUpdateItemSize( baseSize: NSSize ); virtual; abstract;
|
procedure onUpdateItemSize( baseSize: NSSize ); virtual; abstract;
|
||||||
procedure onUpdateItemLayout( cocoaItem: TCocoaCollectionItem ); virtual; abstract;
|
procedure onUpdateItemLayout( cocoaItem: TCocoaCollectionItem ); virtual; abstract;
|
||||||
procedure onAdjustTextEditor( lv: TCocoaListView ); virtual;
|
procedure onAdjustTextEditor( lv: TCocoaListView; var aFrame: NSRect ); virtual; abstract;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaCollectionItemView }
|
{ TCocoaCollectionItemView }
|
||||||
@ -210,7 +210,7 @@ type
|
|||||||
procedure resetSize; override;
|
procedure resetSize; override;
|
||||||
procedure onUpdateItemSize( baseSize: NSSize ); override;
|
procedure onUpdateItemSize( baseSize: NSSize ); override;
|
||||||
procedure onUpdateItemLayout( cocoaItem: TCocoaCollectionItem ); override;
|
procedure onUpdateItemLayout( cocoaItem: TCocoaCollectionItem ); override;
|
||||||
procedure onAdjustTextEditor( lv: TCocoaListView ); override;
|
procedure onAdjustTextEditor( lv: TCocoaListView; var aFrame: NSRect ); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaListView_CollectionView_SmallIconHandler }
|
{ TCocoaListView_CollectionView_SmallIconHandler }
|
||||||
@ -218,6 +218,7 @@ type
|
|||||||
procedure resetSize; override;
|
procedure resetSize; override;
|
||||||
procedure onUpdateItemSize( baseSize: NSSize ); override;
|
procedure onUpdateItemSize( baseSize: NSSize ); override;
|
||||||
procedure onUpdateItemLayout( cocoaItem: TCocoaCollectionItem ); override;
|
procedure onUpdateItemLayout( cocoaItem: TCocoaCollectionItem ); override;
|
||||||
|
procedure onAdjustTextEditor( lv: TCocoaListView; var aFrame: NSRect ); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaListView_CollectionView_ListHandler }
|
{ TCocoaListView_CollectionView_ListHandler }
|
||||||
@ -226,6 +227,7 @@ type
|
|||||||
function isSupportIcon: Boolean; override;
|
function isSupportIcon: Boolean; override;
|
||||||
procedure onUpdateItemSize( baseSize: NSSize ); override;
|
procedure onUpdateItemSize( baseSize: NSSize ); override;
|
||||||
procedure onUpdateItemLayout( cocoaItem: TCocoaCollectionItem ); override;
|
procedure onUpdateItemLayout( cocoaItem: TCocoaCollectionItem ); override;
|
||||||
|
procedure onAdjustTextEditor( lv: TCocoaListView; var aFrame: NSRect ); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function AllocCocoaCollectionView( style: TViewStyle ): TCocoaCollectionView;
|
function AllocCocoaCollectionView( style: TViewStyle ): TCocoaCollectionView;
|
||||||
@ -298,12 +300,6 @@ begin
|
|||||||
Result:= True;
|
Result:= True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaListView_CollectionView_StyleHandler.onAdjustTextEditor(
|
|
||||||
lv: TCocoaListView );
|
|
||||||
begin
|
|
||||||
lv.setCaptionAlignment( NSTextAlignmentLeft );
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TCocoaListView_CollectionView_LargeIconHandler }
|
{ TCocoaListView_CollectionView_LargeIconHandler }
|
||||||
|
|
||||||
procedure TCocoaListView_CollectionView_LargeIconHandler.resetSize;
|
procedure TCocoaListView_CollectionView_LargeIconHandler.resetSize;
|
||||||
@ -312,16 +308,17 @@ var
|
|||||||
minSize: NSSize;
|
minSize: NSSize;
|
||||||
begin
|
begin
|
||||||
layout:= NSCollectionViewFlowLayout(_collectionView.collectionViewLayout);
|
layout:= NSCollectionViewFlowLayout(_collectionView.collectionViewLayout);
|
||||||
minSize.width:= 64;
|
minSize.width:= CocoaConfigListView.vsIcon.item.minSize.width;
|
||||||
minSize.height:= 68;
|
minSize.height:= CocoaConfigListView.vsIcon.item.minSize.height;
|
||||||
|
|
||||||
if self.hasCheckBoxes then
|
if self.hasCheckBoxes then
|
||||||
minSize.width:= minSize.width + 24;
|
minSize.width:= minSize.width +
|
||||||
|
CocoaConfigListView.vsIcon.item.checkBoxOccupiedWidth;
|
||||||
|
|
||||||
TCocoaCollectionView(_collectionView).itemSize:= minSize;
|
TCocoaCollectionView(_collectionView).itemSize:= minSize;
|
||||||
layout.setItemSize( minSize );
|
layout.setItemSize( minSize );
|
||||||
layout.setMinimumInteritemSpacing( 4 );
|
layout.setMinimumInteritemSpacing( CocoaConfigListView.vsIcon.interitemSpacing );
|
||||||
layout.setMinimumLineSpacing( 4 );
|
layout.setMinimumLineSpacing( CocoaConfigListView.vsIcon.lineSpacing );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaListView_CollectionView_LargeIconHandler.onUpdateItemSize(
|
procedure TCocoaListView_CollectionView_LargeIconHandler.onUpdateItemSize(
|
||||||
@ -331,20 +328,25 @@ var
|
|||||||
begin
|
begin
|
||||||
cv:= TCocoaCollectionView(_collectionView);
|
cv:= TCocoaCollectionView(_collectionView);
|
||||||
cv.iconSize:= baseSize;
|
cv.iconSize:= baseSize;
|
||||||
if cv.iconSize.Width < 32 then
|
if cv.iconSize.Width < CocoaConfigListView.vsIcon.imageView.minSize.width then
|
||||||
cv.iconSize.Width:= 32;
|
cv.iconSize.Width:= CocoaConfigListView.vsIcon.imageView.minSize.width;
|
||||||
if cv.iconSize.Height < 32 then
|
if cv.iconSize.Height < CocoaConfigListView.vsIcon.imageView.minSize.height then
|
||||||
cv.iconSize.Height:= 32;
|
cv.iconSize.Height:= CocoaConfigListView.vsIcon.imageView.minSize.height;
|
||||||
|
|
||||||
cv.itemSize.Width:= 10 + cv.iconSize.Width + 10;
|
cv.itemSize.Width:= cv.iconSize.Width +
|
||||||
cv.itemSize.Height:= 10 + cv.iconSize.Height + 2 + 14 + 10;
|
CocoaConfigListView.vsIcon.imageView.padding * 2;
|
||||||
if cv.itemSize.Width < 64 then
|
cv.itemSize.Height:= cv.iconSize.Height +
|
||||||
cv.itemSize.Width:= 64;
|
CocoaConfigListView.vsIcon.imageView.padding * 2 +
|
||||||
if cv.itemSize.Height < 68 then
|
CocoaConfigListView.vsIcon.item.controlSpacing +
|
||||||
cv.itemSize.Height:= 68;
|
CocoaConfigListView.vsIcon.textField.defaultHeight;
|
||||||
|
if cv.itemSize.Width < CocoaConfigListView.vsIcon.item.minSize.width then
|
||||||
|
cv.itemSize.Width:= CocoaConfigListView.vsIcon.item.minSize.width;
|
||||||
|
if cv.itemSize.Height < CocoaConfigListView.vsIcon.item.minSize.height then
|
||||||
|
cv.itemSize.Height:= CocoaConfigListView.vsIcon.item.minSize.height;
|
||||||
|
|
||||||
if self.hasCheckBoxes then
|
if self.hasCheckBoxes then
|
||||||
cv.itemSize.Width:= cv.itemSize.Width + 24;
|
cv.itemSize.Width:= cv.itemSize.Width +
|
||||||
|
CocoaConfigListView.vsIcon.item.checkBoxOccupiedWidth;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaListView_CollectionView_LargeIconHandler.onUpdateItemLayout(
|
procedure TCocoaListView_CollectionView_LargeIconHandler.onUpdateItemLayout(
|
||||||
@ -352,41 +354,56 @@ procedure TCocoaListView_CollectionView_LargeIconHandler.onUpdateItemLayout(
|
|||||||
var
|
var
|
||||||
cv: TCocoaCollectionView;
|
cv: TCocoaCollectionView;
|
||||||
aFrame: NSRect;
|
aFrame: NSRect;
|
||||||
|
textField: NSTextField;
|
||||||
|
imageView: NSImageView;
|
||||||
checkBox: NSButton;
|
checkBox: NSButton;
|
||||||
begin
|
begin
|
||||||
|
textField:= cocoaItem.textField;
|
||||||
|
imageView:= cocoaItem.imageView;
|
||||||
checkBox:= cocoaItem.checkBox;
|
checkBox:= cocoaItem.checkBox;
|
||||||
cv:= TCocoaCollectionView(_collectionView);
|
cv:= TCocoaCollectionView(_collectionView);
|
||||||
|
|
||||||
aFrame.origin.x:= round( (cv.itemSize.Width - cv.iconSize.Width) / 2 );
|
aFrame.origin.x:= round( (cv.itemSize.Width - cv.iconSize.Width) / 2 );
|
||||||
aFrame.origin.y:= cv.itemSize.Height - cv.iconSize.Height - 10;
|
aFrame.origin.y:= cv.itemSize.Height - cv.iconSize.Height -
|
||||||
|
CocoaConfigListView.vsIcon.imageView.padding;
|
||||||
aFrame.size:= cv.iconSize;
|
aFrame.size:= cv.iconSize;
|
||||||
if Assigned(checkBox) then
|
if Assigned(checkBox) then
|
||||||
aFrame.origin.x:= aFrame.origin.x + 12;
|
aFrame.origin.x:= aFrame.origin.x +
|
||||||
cocoaItem.imageView.setFrame( aFrame );
|
CocoaConfigListView.vsIcon.item.checkBoxOccupiedWidth / 2;
|
||||||
|
imageView.setFrame( aFrame );
|
||||||
|
|
||||||
cocoaItem.textField.sizeToFit;
|
textField.sizeToFit;
|
||||||
|
aFrame.size.height:= textField.frame.size.height;
|
||||||
|
aFrame.origin.y:= round( (aFrame.origin.y-aFrame.size.height) / 2 );
|
||||||
aFrame.origin.x:= 0;
|
aFrame.origin.x:= 0;
|
||||||
aFrame.origin.y:= 6;
|
|
||||||
if Assigned(checkBox) then
|
if Assigned(checkBox) then
|
||||||
aFrame.origin.x:= aFrame.origin.x + 24;
|
aFrame.origin.x:= aFrame.origin.x + CocoaConfigListView.vsIcon.item.checkBoxOccupiedWidth;
|
||||||
aFrame.size.width:= cv.itemSize.Width - aFrame.origin.x;
|
aFrame.size.width:= cv.itemSize.Width - aFrame.origin.x;
|
||||||
aFrame.size.height:= cocoaItem.textField.frame.size.height;
|
textField.setFrame( aFrame );
|
||||||
cocoaItem.textField.setAlignment( NSTextAlignmentCenter );
|
textField.setAlignment( CocoaConfigListView.vsIcon.item.textFieldAlignment );
|
||||||
cocoaItem.textField.setFrame( aFrame );
|
|
||||||
|
|
||||||
if Assigned(checkBox) then begin
|
if Assigned(checkBox) then begin
|
||||||
aFrame.size.width:= 18;
|
checkBox.sizeToFit;
|
||||||
aFrame.size.height:= 18;
|
aFrame.size:= checkBox.frame.size;
|
||||||
aFrame.origin.x:= 6;
|
aFrame.origin.x:= CocoaConfigListView.vsIcon.item.checkBoxOccupiedWidth -
|
||||||
aFrame.origin.y:= round( (cv.itemSize.Height - aFrame.size.height ) / 2 + 5 );
|
checkBox.frame.size.width;
|
||||||
|
aFrame.origin.y:= round( (cv.itemSize.Height-aFrame.size.height) / 2 );
|
||||||
checkBox.setFrame( aFrame );
|
checkBox.setFrame( aFrame );
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaListView_CollectionView_LargeIconHandler.onAdjustTextEditor(
|
procedure TCocoaListView_CollectionView_LargeIconHandler.onAdjustTextEditor(
|
||||||
lv: TCocoaListView );
|
lv: TCocoaListView; var aFrame: NSRect );
|
||||||
|
var
|
||||||
|
offset: Double; // FocusRing Occupied
|
||||||
begin
|
begin
|
||||||
lv.setCaptionAlignment( NSTextAlignmentCenter );
|
lv.setCaptionAlignment( CocoaConfigListView.vsIcon.item.textFieldAlignment );
|
||||||
|
|
||||||
|
offset:= 1;
|
||||||
|
if NOT hasCheckBoxes then
|
||||||
|
offset:= offset + 1;
|
||||||
|
aFrame.origin.x:= aFrame.origin.x + offset;
|
||||||
|
aFrame.size.Width:= aFrame.size.Width - offset*2;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaListView_CollectionView_SmallIconHandler }
|
{ TCocoaListView_CollectionView_SmallIconHandler }
|
||||||
@ -397,40 +414,47 @@ var
|
|||||||
minSize: NSSize;
|
minSize: NSSize;
|
||||||
begin
|
begin
|
||||||
layout:= NSCollectionViewFlowLayout(_collectionView.collectionViewLayout);
|
layout:= NSCollectionViewFlowLayout(_collectionView.collectionViewLayout);
|
||||||
minSize.width:= 150;
|
minSize.width:= CocoaConfigListView.vsSmallIcon.item.minSize.width;
|
||||||
minSize.height:= 28;
|
minSize.height:= CocoaConfigListView.vsSmallIcon.item.minSize.height;
|
||||||
if self.hasCheckBoxes then
|
if self.hasCheckBoxes then
|
||||||
minSize.width:= minSize.width + 24;
|
minSize.width:= minSize.width + CocoaConfigListView.vsSmallIcon.item.checkBoxOccupiedWidth;
|
||||||
|
|
||||||
TCocoaCollectionView(_collectionView).itemSize:= minSize;
|
TCocoaCollectionView(_collectionView).itemSize:= minSize;
|
||||||
layout.setItemSize( minSize );
|
layout.setItemSize( minSize );
|
||||||
layout.setMinimumInteritemSpacing( 10 );
|
layout.setMinimumInteritemSpacing( CocoaConfigListView.vsSmallIcon.interitemSpacing );
|
||||||
layout.setMinimumLineSpacing( 0 );
|
layout.setMinimumLineSpacing( CocoaConfigListView.vsSmallIcon.lineSpacing );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaListView_CollectionView_SmallIconHandler.onUpdateItemSize(
|
procedure TCocoaListView_CollectionView_SmallIconHandler.onUpdateItemSize(
|
||||||
baseSize: NSSize);
|
baseSize: NSSize);
|
||||||
var
|
var
|
||||||
cv: TCocoaCollectionView;
|
cv: TCocoaCollectionView;
|
||||||
textWidth: Integer;
|
textWidth: CGFloat;
|
||||||
begin
|
begin
|
||||||
cv:= TCocoaCollectionView(_collectionView);
|
cv:= TCocoaCollectionView(_collectionView);
|
||||||
cv.iconSize:= baseSize;
|
cv.iconSize:= baseSize;
|
||||||
if cv.iconSize.Width < 16 then
|
if cv.iconSize.Width < CocoaConfigListView.vsSmallIcon.imageView.minSize.width then
|
||||||
cv.iconSize.Width:= 16;
|
cv.iconSize.Width:= CocoaConfigListView.vsSmallIcon.imageView.minSize.width;
|
||||||
if cv.iconSize.Height < 16 then
|
if cv.iconSize.Height < CocoaConfigListView.vsSmallIcon.imageView.minSize.height then
|
||||||
cv.iconSize.Height:= 16;
|
cv.iconSize.Height:= CocoaConfigListView.vsSmallIcon.imageView.minSize.height;
|
||||||
|
|
||||||
textWidth:= Round( cv.iconSize.Width * 3 );
|
textWidth:= Round( cv.iconSize.Width *
|
||||||
if textWidth < 128 then
|
CocoaConfigListView.vsSmallIcon.textField.iconWidthFactor +
|
||||||
textWidth:= 128;
|
CocoaConfigListView.vsSmallIcon.textField.baseWidth );
|
||||||
cv.itemSize.Width:= 6 + cv.iconSize.Width + 2 + textWidth + 6;
|
if textWidth < CocoaConfigListView.vsSmallIcon.textField.minWidth then
|
||||||
cv.itemSize.Height:= 4 + cv.iconSize.Height + 4;
|
textWidth:= CocoaConfigListView.vsSmallIcon.textField.minWidth;
|
||||||
if cv.itemSize.Height < 28 then
|
cv.itemSize.Width:= cv.iconSize.Width +
|
||||||
cv.itemSize.Height:= 28;
|
CocoaConfigListView.vsSmallIcon.item.controlSpacing +
|
||||||
|
textWidth +
|
||||||
|
CocoaConfigListView.vsSmallIcon.imageView.padding * 2;
|
||||||
|
cv.itemSize.Height:= cv.iconSize.Height +
|
||||||
|
CocoaConfigListView.vsSmallIcon.imageView.padding * 2;
|
||||||
|
if cv.itemSize.Height < CocoaConfigListView.vsSmallIcon.item.minSize.height then
|
||||||
|
cv.itemSize.Height:= CocoaConfigListView.vsSmallIcon.item.minSize.height;
|
||||||
|
|
||||||
if self.hasCheckBoxes then
|
if self.hasCheckBoxes then
|
||||||
cv.itemSize.width:= cv.itemSize.width + 24;
|
cv.itemSize.width:= cv.itemSize.width +
|
||||||
|
CocoaConfigListView.vsSmallIcon.item.checkBoxOccupiedWidth;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaListView_CollectionView_SmallIconHandler.onUpdateItemLayout(
|
procedure TCocoaListView_CollectionView_SmallIconHandler.onUpdateItemLayout(
|
||||||
@ -438,32 +462,48 @@ procedure TCocoaListView_CollectionView_SmallIconHandler.onUpdateItemLayout(
|
|||||||
var
|
var
|
||||||
cv: TCocoaCollectionView;
|
cv: TCocoaCollectionView;
|
||||||
aFrame: NSRect;
|
aFrame: NSRect;
|
||||||
|
textField: NSTextField;
|
||||||
|
imageView: NSImageView;
|
||||||
checkBox: NSButton;
|
checkBox: NSButton;
|
||||||
begin
|
begin
|
||||||
|
textField:= cocoaItem.textField;
|
||||||
|
imageView:= cocoaItem.imageView;
|
||||||
checkBox:= cocoaItem.checkBox;
|
checkBox:= cocoaItem.checkBox;
|
||||||
cv:= TCocoaCollectionView(_collectionView);
|
cv:= TCocoaCollectionView(_collectionView);
|
||||||
|
|
||||||
aFrame.origin.x:= 6;
|
aFrame:= NSZeroRect;
|
||||||
aFrame.origin.y:= round( (cv.itemSize.Height - cv.iconSize.Height) / 2 );
|
|
||||||
aFrame.size:= cv.iconSize;
|
|
||||||
if Assigned(checkBox) then
|
|
||||||
aFrame.origin.x:= aFrame.origin.x + 24;
|
|
||||||
cocoaItem.imageView.setFrame( aFrame );
|
|
||||||
|
|
||||||
cocoaItem.textField.sizeToFit;
|
|
||||||
aFrame.origin.x:= aFrame.origin.x + aFrame.size.width + 2;
|
|
||||||
aFrame.origin.y:= round( (cv.itemSize.Height - cocoaItem.textField.frame.size.height) / 2 );
|
|
||||||
aFrame.size.width:= cv.itemSize.Width - aFrame.origin.x - 4;
|
|
||||||
aFrame.size.height:= cocoaItem.textField.frame.size.height;
|
|
||||||
cocoaItem.textField.setFrame( aFrame );
|
|
||||||
|
|
||||||
if Assigned(checkBox) then begin
|
if Assigned(checkBox) then begin
|
||||||
aFrame.size.width:= 18;
|
checkBox.sizeToFit;
|
||||||
aFrame.size.height:= 18;
|
aFrame.size:= checkBox.frame.size;
|
||||||
aFrame.origin.x:= 6;
|
aFrame.origin.x:= CocoaConfigListView.vsSmallIcon.item.checkBoxOccupiedWidth -
|
||||||
|
checkBox.frame.size.width;
|
||||||
aFrame.origin.y:= round( (cv.itemSize.Height - aFrame.size.height ) / 2 );
|
aFrame.origin.y:= round( (cv.itemSize.Height - aFrame.size.height ) / 2 );
|
||||||
checkBox.setFrame( aFrame );
|
checkBox.setFrame( aFrame );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
aFrame.origin.x:= aFrame.origin.x + aFrame.size.width +
|
||||||
|
CocoaConfigListView.vsSmallIcon.imageView.padding +
|
||||||
|
CocoaConfigListView.vsSmallIcon.item.controlSpacing;
|
||||||
|
aFrame.origin.y:= round( (cv.itemSize.Height - cv.iconSize.height) / 2 );
|
||||||
|
aFrame.size:= cv.iconSize;
|
||||||
|
imageView.setFrame( aFrame );
|
||||||
|
|
||||||
|
textField.sizeToFit;
|
||||||
|
aFrame.origin.x:= aFrame.origin.x + aFrame.size.width +
|
||||||
|
CocoaConfigListView.vsSmallIcon.item.controlSpacing;
|
||||||
|
aFrame.origin.y:= round( (cv.itemSize.Height - textField.frame.size.height) / 2 );
|
||||||
|
aFrame.size.width:= cv.itemSize.Width - aFrame.origin.x -
|
||||||
|
CocoaConfigListView.vsSmallIcon.item.controlSpacing;
|
||||||
|
aFrame.size.height:= textField.frame.size.height;
|
||||||
|
textField.setFrame( aFrame );
|
||||||
|
textField.setAlignment( CocoaConfigListView.vsSmallIcon.item.textFieldAlignment );
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaListView_CollectionView_SmallIconHandler.onAdjustTextEditor(
|
||||||
|
lv: TCocoaListView; var aFrame: NSRect );
|
||||||
|
begin
|
||||||
|
lv.setCaptionAlignment( CocoaConfigListView.vsSmallIcon.item.textFieldAlignment );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaListView_CollectionView_ListHandler }
|
{ TCocoaListView_CollectionView_ListHandler }
|
||||||
@ -475,15 +515,15 @@ var
|
|||||||
minSize: NSSize;
|
minSize: NSSize;
|
||||||
begin
|
begin
|
||||||
layout:= NSCollectionViewFlowLayout(_collectionView.collectionViewLayout);
|
layout:= NSCollectionViewFlowLayout(_collectionView.collectionViewLayout);
|
||||||
minSize.width:= 146;
|
minSize.width:= CocoaConfigListView.vsList.item.minSize.width;
|
||||||
minSize.height:= 24;
|
minSize.height:= CocoaConfigListView.vsList.item.minSize.height;
|
||||||
if self.hasCheckBoxes then
|
if self.hasCheckBoxes then
|
||||||
minSize.width:= minSize.width + 24;
|
minSize.width:= minSize.width + CocoaConfigListView.vsList.item.checkBoxOccupiedWidth;
|
||||||
|
|
||||||
TCocoaCollectionView(_collectionView).itemSize:= minSize;
|
TCocoaCollectionView(_collectionView).itemSize:= minSize;
|
||||||
layout.setItemSize( minSize );
|
layout.setItemSize( minSize );
|
||||||
layout.setMinimumInteritemSpacing( 0 );
|
layout.setMinimumInteritemSpacing( CocoaConfigListView.vsList.interitemSpacing );
|
||||||
layout.setMinimumLineSpacing( 10 );
|
layout.setMinimumLineSpacing( CocoaConfigListView.vsList.lineSpacing );
|
||||||
|
|
||||||
layout.setScrollDirection( NSCollectionViewScrollDirectionHorizontal );
|
layout.setScrollDirection( NSCollectionViewScrollDirectionHorizontal );
|
||||||
end;
|
end;
|
||||||
@ -501,29 +541,41 @@ end;
|
|||||||
procedure TCocoaListView_CollectionView_ListHandler.onUpdateItemLayout(
|
procedure TCocoaListView_CollectionView_ListHandler.onUpdateItemLayout(
|
||||||
cocoaItem: TCocoaCollectionItem);
|
cocoaItem: TCocoaCollectionItem);
|
||||||
var
|
var
|
||||||
checkBox: NSButton;
|
|
||||||
cv: TCocoaCollectionView;
|
cv: TCocoaCollectionView;
|
||||||
aFrame: NSRect;
|
aFrame: NSRect;
|
||||||
|
textField: NSTextField;
|
||||||
|
checkBox: NSButton;
|
||||||
begin
|
begin
|
||||||
|
textField:= cocoaItem.textField;
|
||||||
checkBox:= cocoaItem.checkBox;
|
checkBox:= cocoaItem.checkBox;
|
||||||
cv:= TCocoaCollectionView(_collectionView);
|
cv:= TCocoaCollectionView(_collectionView);
|
||||||
|
|
||||||
cocoaItem.textField.sizeToFit;
|
aFrame:= NSZeroRect;
|
||||||
aFrame.origin.x:= 4;
|
|
||||||
aFrame.origin.y:= round( (cv.itemSize.Height - cocoaItem.textField.frame.size.height) / 2 );
|
|
||||||
aFrame.size.width:= 138;
|
|
||||||
aFrame.size.height:= cocoaItem.textField.frame.size.height;
|
|
||||||
if Assigned(checkBox) then
|
|
||||||
aFrame.origin.x:= aFrame.origin.x + 24;
|
|
||||||
cocoaItem.textField.setFrame( aFrame );
|
|
||||||
|
|
||||||
if Assigned(checkBox) then begin
|
if Assigned(checkBox) then begin
|
||||||
aFrame.size.width:= 18;
|
checkBox.sizeToFit;
|
||||||
aFrame.size.height:= 18;
|
aFrame.size:= checkBox.frame.size;
|
||||||
aFrame.origin.x:= 6;
|
aFrame.origin.x:= CocoaConfigListView.vsList.item.checkBoxOccupiedWidth -
|
||||||
|
checkBox.frame.size.width;
|
||||||
aFrame.origin.y:= round( (cv.itemSize.Height - aFrame.size.height ) / 2 );
|
aFrame.origin.y:= round( (cv.itemSize.Height - aFrame.size.height ) / 2 );
|
||||||
checkBox.setFrame( aFrame );
|
checkBox.setFrame( aFrame );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
textField.sizeToFit;
|
||||||
|
aFrame.origin.x:= aFrame.origin.x + aFrame.size.width +
|
||||||
|
CocoaConfigListView.vsList.item.controlSpacing;
|
||||||
|
aFrame.origin.y:= round( (cv.itemSize.Height - textField.frame.size.height) / 2 );
|
||||||
|
aFrame.size.width:= cv.itemSize.Width - aFrame.origin.x -
|
||||||
|
CocoaConfigListView.vsList.item.controlSpacing;
|
||||||
|
aFrame.size.height:= textField.frame.size.height;
|
||||||
|
textField.setFrame( aFrame );
|
||||||
|
textField.setAlignment( CocoaConfigListView.vsList.item.textFieldAlignment );
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaListView_CollectionView_ListHandler.onAdjustTextEditor(
|
||||||
|
lv: TCocoaListView; var aFrame: NSRect );
|
||||||
|
begin
|
||||||
|
lv.setCaptionAlignment( CocoaConfigListView.vsList.item.textFieldAlignment );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaCollectionItem }
|
{ TCocoaCollectionItem }
|
||||||
@ -1089,9 +1141,9 @@ begin
|
|||||||
_listView.setCaptionFont( item.textField.font );
|
_listView.setCaptionFont( item.textField.font );
|
||||||
// to do: completely restore TFont
|
// to do: completely restore TFont
|
||||||
_listView.getLCLControlCanvas.Font.Height:= Round(item.textField.font.pointSize);
|
_listView.getLCLControlCanvas.Font.Height:= Round(item.textField.font.pointSize);
|
||||||
_collectionView.styleHandler.onAdjustTextEditor( _listView );
|
|
||||||
frame:= item.textField.frame;
|
frame:= item.textField.frame;
|
||||||
frame:= item.view.convertRect_toView( frame, _collectionView );
|
frame:= item.view.convertRect_toView( frame, _collectionView );
|
||||||
|
_collectionView.styleHandler.onAdjustTextEditor( _listView, frame );
|
||||||
end;
|
end;
|
||||||
drIcon:
|
drIcon:
|
||||||
begin
|
begin
|
||||||
|
@ -2,6 +2,7 @@ unit CocoaConfig;
|
|||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
{$modeswitch objectivec1}
|
{$modeswitch objectivec1}
|
||||||
|
{$include cocoadefines.inc}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@ -9,6 +10,132 @@ uses
|
|||||||
CocoaAll, Cocoa_Extra, CocoaConst;
|
CocoaAll, Cocoa_Extra, CocoaConst;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TCocoaConfigSize = record
|
||||||
|
width: Double;
|
||||||
|
height: Double;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigTableRow = record
|
||||||
|
defaultHeight: Integer;
|
||||||
|
imageLineSpacing: Integer;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigTableColumn = record
|
||||||
|
controlSpacing: Integer;
|
||||||
|
textFieldMinWidth: Integer;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigTableColumnAutoFit = 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;
|
||||||
|
|
||||||
|
TCocoaConfigTable = record
|
||||||
|
// default NSTableViewStyle
|
||||||
|
tableViewStyle: NSTableViewStyle;
|
||||||
|
row: TCocoaConfigTableRow;
|
||||||
|
column: TCocoaConfigTableColumn;
|
||||||
|
columnAutoFit: TCocoaConfigTableColumnAutoFit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigCollectionItem = record
|
||||||
|
minSize: TCocoaConfigSize;
|
||||||
|
controlSpacing: Double;
|
||||||
|
textFieldAlignment: NSTextAlignment;
|
||||||
|
checkBoxOccupiedWidth: Double;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigCollection = object
|
||||||
|
interitemSpacing: Double;
|
||||||
|
lineSpacing: Double;
|
||||||
|
item: TCocoaConfigCollectionItem;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigCollectionIconImageView = record
|
||||||
|
minSize: TCocoaConfigSize;
|
||||||
|
padding: Double;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigCollectionLargeIconTextField = record
|
||||||
|
defaultHeight: Double;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigCollectionSmallIconTextField = record
|
||||||
|
iconWidthFactor: Double;
|
||||||
|
baseWidth: Double;
|
||||||
|
minWidth: Double;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigCollectionIcon = object( TCocoaConfigCollection )
|
||||||
|
imageView: TCocoaConfigCollectionIconImageView;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigCollectionLargeIcon = object( TCocoaConfigCollectionIcon )
|
||||||
|
textField: TCocoaConfigCollectionLargeIconTextField;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigCollectionSmallIcon = object( TCocoaConfigCollectionIcon )
|
||||||
|
textField: TCocoaConfigCollectionSmallIconTextField;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCocoaConfigListView = record
|
||||||
|
vsReport: TCocoaConfigTable;
|
||||||
|
vsIcon: TCocoaConfigCollectionLargeIcon;
|
||||||
|
vsSmallIcon: TCocoaConfigCollectionSmallIcon;
|
||||||
|
vsList: TCocoaConfigCollection;
|
||||||
|
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 );
|
||||||
|
);
|
||||||
|
vsIcon: (
|
||||||
|
interitemSpacing: 4;
|
||||||
|
lineSpacing: 4;
|
||||||
|
item: (
|
||||||
|
minSize: ( width:64; height:68 );
|
||||||
|
controlSpacing: 2;
|
||||||
|
textFieldAlignment: {$ifdef USE_IOS_VALUES}1{$else}2{$endif}; // NSTextAlignmentCenter
|
||||||
|
checkBoxOccupiedWidth: 24
|
||||||
|
);
|
||||||
|
imageView: ( minSize: ( width: 32; height: 32 ); padding: 10; );
|
||||||
|
textField: ( defaultHeight: 15 );
|
||||||
|
);
|
||||||
|
vsSmallIcon: (
|
||||||
|
interitemSpacing: 10;
|
||||||
|
lineSpacing: 0;
|
||||||
|
item: (
|
||||||
|
minSize: ( width:150; height:28 );
|
||||||
|
controlSpacing: 2;
|
||||||
|
textFieldAlignment: 0; // NSTextAlignmentLeft
|
||||||
|
checkBoxOccupiedWidth: 24
|
||||||
|
);
|
||||||
|
imageView: ( minSize: ( width: 16; height: 16 ); padding: 4; );
|
||||||
|
textField: ( iconWidthFactor: 3; baseWidth: 0; minWidth: 128 );
|
||||||
|
);
|
||||||
|
vsList: (
|
||||||
|
interitemSpacing: 0;
|
||||||
|
lineSpacing: 10;
|
||||||
|
item: (
|
||||||
|
minSize: ( width:146; height:24 );
|
||||||
|
controlSpacing: 4;
|
||||||
|
textFieldAlignment: 0; // NSTextAlignmentLeft
|
||||||
|
checkBoxOccupiedWidth: 24
|
||||||
|
);
|
||||||
|
);
|
||||||
|
);
|
||||||
|
|
||||||
|
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 +243,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