Recent

Author Topic: TListBox / TCheckListBox lead spacing and margin fix  (Read 403 times)

rossh_lz

  • New Member
  • *
  • Posts: 20
TListBox / TCheckListBox lead spacing and margin fix
« on: February 09, 2022, 09:02:36 pm »
With macOS 11 and more, the OS added a large leading margin to the NSTableView, which is the base component for Lazarus TListBox, TCheckListBox, TListView, and probably others.

The change is described https://wiki.freepascal.org/macOS_Big_Sur_changes_for_developers#Table_Views and shown below.

The new default style value uses the widest spacing available, and is quite excessive.  This can be brought back to normal with the following code changes.

In /Applications/Lazarus/lcl/interfaces/cocoa/cocoa_extra.pas add or change to this:
Code: Pascal  [Select][+][-]
  1. const
  2.   // 11.0
  3.   NSTableViewStyleAutomatic = 0;
  4.   NSTableViewStyleFullWidth = 1;
  5.   NSTableViewStyleInset = 2;
  6.   NSTableViewStyleSourceList = 3;
  7.   NSTableViewStylePlain = 4;  
  8.  
  9. type
  10.   NSTableViewStyle = NSInteger;    // 11.0  
  11.  
  12.   NSTableViewFix = objccategory external (NSTableView)
  13.     // 11.0
  14.     procedure setStyle(newValue: NSTableViewStyle); message 'setStyle:';
  15.     function style: NSTableViewStyle; message 'style';
  16.     function effectiveStyle: NSTableViewStyle; message 'effectiveStyle';
  17.   end;

In /Applications/Lazarus/lcl/interfaces/cocoa/cocoatables.pas  adjust existing function to read
Code: Pascal  [Select][+][-]
  1. function TCocoaTableListView.initWithFrame(frameRect: NSRect): id;
  2. begin
  3.   Result:=inherited initWithFrame(frameRect);
  4.   // 11.0 - fix for column alignment
  5.   if (NSAppkitVersionNumber >= NSAppKitVersionNumber11_0) then
  6.     setStyle(NSTableViewStyleFullWidth);
  7. end;
« Last Edit: February 09, 2022, 09:05:34 pm by rossh_lz »

 

TinyPortal © 2005-2018