mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 20:44:03 +02:00
Cocoa: fix OwnerDraw in TCheckListBox #41100
This commit is contained in:
parent
ce91d6cb54
commit
17e6884e13
@ -8,7 +8,8 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
LCLType, Graphics, Controls, ComCtrls,
|
LCLType, Graphics, Controls, ComCtrls,
|
||||||
CocoaAll, CocoaPrivate, CocoaCallback, CocoaWSCommon, CocoaGDIObjects;
|
CocoaAll, CocoaPrivate, CocoaCallback, CocoaWSCommon, CocoaGDIObjects,
|
||||||
|
CocoaUtils;
|
||||||
|
|
||||||
type
|
type
|
||||||
{
|
{
|
||||||
@ -97,6 +98,7 @@ type
|
|||||||
procedure onReloadData( tv: NSTableView ); virtual; abstract;
|
procedure onReloadData( tv: NSTableView ); virtual; abstract;
|
||||||
procedure onSelectOneItem( tv: NSTableView; selection: NSIndexSet ); virtual; abstract;
|
procedure onSelectOneItem( tv: NSTableView; selection: NSIndexSet ); virtual; abstract;
|
||||||
procedure onSelectionChanged( tv: NSTableView ); virtual; abstract;
|
procedure onSelectionChanged( tv: NSTableView ); virtual; abstract;
|
||||||
|
procedure onOwnerDrawItem( rowView: NSView ); virtual abstract;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaTableListControlProcessor }
|
{ TCocoaTableListControlProcessor }
|
||||||
@ -107,6 +109,7 @@ type
|
|||||||
public
|
public
|
||||||
procedure onReloadData( tv: NSTableView ); override;
|
procedure onReloadData( tv: NSTableView ); override;
|
||||||
procedure onSelectOneItem( tv: NSTableView; selection: NSIndexSet ); override;
|
procedure onSelectOneItem( tv: NSTableView; selection: NSIndexSet ); override;
|
||||||
|
procedure onOwnerDrawItem( rowView: NSView ); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaListControlStringList }
|
{ TCocoaListControlStringList }
|
||||||
@ -204,6 +207,11 @@ begin
|
|||||||
lclcb.selectionIndexSet.addIndexes( selection );
|
lclcb.selectionIndexSet.addIndexes( selection );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaTableListControlProcessor.onOwnerDrawItem( rowView: NSView );
|
||||||
|
begin
|
||||||
|
hideAllSubviews( rowView );
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCocoaListControlStringList }
|
{ TCocoaListControlStringList }
|
||||||
|
|
||||||
procedure TCocoaListControlStringList.Changed;
|
procedure TCocoaListControlStringList.Changed;
|
||||||
|
@ -90,6 +90,7 @@ type
|
|||||||
procedure addSubview(aView: NSView); override;
|
procedure addSubview(aView: NSView); override;
|
||||||
procedure dealloc; override;
|
procedure dealloc; override;
|
||||||
|
|
||||||
|
function lclGetPorcessor: TCocoaTableViewProcessor; message 'lclGetPorcessor';
|
||||||
procedure lclSetProcessor( processor: TCocoaTableViewProcessor ); message 'lclSetProcessor:';
|
procedure lclSetProcessor( processor: TCocoaTableViewProcessor ); message 'lclSetProcessor:';
|
||||||
procedure lclSetCheckBoxes( checkBoxes: Boolean); message 'lclSetCheckBoxes:';
|
procedure lclSetCheckBoxes( checkBoxes: Boolean); message 'lclSetCheckBoxes:';
|
||||||
function lclHasCheckBoxes: Boolean; message 'lclHasCheckBoxes';
|
function lclHasCheckBoxes: Boolean; message 'lclHasCheckBoxes';
|
||||||
@ -320,15 +321,6 @@ begin
|
|||||||
Result := TCocoaTableListView.alloc;
|
Result := TCocoaTableListView.alloc;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure hideAllSubviews( parent: NSView );
|
|
||||||
var
|
|
||||||
view: NSView;
|
|
||||||
begin
|
|
||||||
for view in parent.subviews do
|
|
||||||
view.setHidden( True );
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
function updateNSTextFieldWithTFont( cocoaField: NSTextField; lclFont: TFont ):
|
function updateNSTextFieldWithTFont( cocoaField: NSTextField; lclFont: TFont ):
|
||||||
Boolean;
|
Boolean;
|
||||||
var
|
var
|
||||||
@ -385,14 +377,15 @@ begin
|
|||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
done:= self.tableView.lclCallDrawItem( row , self.bounds.size, dirtyRect );
|
done:= self.tableView.lclCallDrawItem( row, self.bounds.size, dirtyRect );
|
||||||
|
|
||||||
if done then begin
|
if done then begin
|
||||||
// the Cocoa default drawing cannot be skipped in NSTableView,
|
// the Cocoa default drawing cannot be skipped in NSTableView,
|
||||||
// we can only hide the CellViews to get the same effect.
|
// we can only hide the CellViews to get the same effect.
|
||||||
// in the Lazarus IDE, there is a ListBox with OwnerDraw in Project-Forms,
|
// in the Lazarus IDE, there is a ListBox with OwnerDraw in Project-Forms,
|
||||||
// it's a case where the default drawing must be skipped.
|
// it's a case where the default drawing must be skipped.
|
||||||
hideAllSubviews( self );
|
if Assigned(self.tableView.lclGetPorcessor) then
|
||||||
|
self.tableView.lclGetPorcessor.onOwnerDrawItem( self );
|
||||||
end else begin
|
end else begin
|
||||||
drawNSViewBackground( self, tableView.lclGetCanvas.Brush );
|
drawNSViewBackground( self, tableView.lclGetCanvas.Brush );
|
||||||
inherited drawRect( dirtyRect );
|
inherited drawRect( dirtyRect );
|
||||||
@ -477,6 +470,11 @@ begin
|
|||||||
FreeAndNil( _processor );
|
FreeAndNil( _processor );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCocoaTableListView.lclGetPorcessor: TCocoaTableViewProcessor;
|
||||||
|
begin
|
||||||
|
Result:= _processor;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCocoaTableListView.lclSetProcessor( processor: TCocoaTableViewProcessor);
|
procedure TCocoaTableListView.lclSetProcessor( processor: TCocoaTableViewProcessor);
|
||||||
begin
|
begin
|
||||||
_processor:= processor;
|
_processor:= processor;
|
||||||
|
@ -25,6 +25,8 @@ type
|
|||||||
const
|
const
|
||||||
NSNullRect : NSRect = (origin:(x:0; y:0); size:(width:0; height:0));
|
NSNullRect : NSRect = (origin:(x:0; y:0); size:(width:0; height:0));
|
||||||
|
|
||||||
|
procedure hideAllSubviews( parent: NSView );
|
||||||
|
|
||||||
function GetNSSize(width, height: CGFloat): NSSize; inline;
|
function GetNSSize(width, height: CGFloat): NSSize; inline;
|
||||||
|
|
||||||
function GetNSPoint(x,y: single): NSPoint; inline;
|
function GetNSPoint(x,y: single): NSPoint; inline;
|
||||||
@ -161,6 +163,14 @@ function AllocCursorFromCursorByDegrees(src: NSCursor; degrees: double): NSCurso
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
procedure hideAllSubviews( parent: NSView );
|
||||||
|
var
|
||||||
|
view: NSView;
|
||||||
|
begin
|
||||||
|
for view in parent.subviews do
|
||||||
|
view.setHidden( True );
|
||||||
|
end;
|
||||||
|
|
||||||
procedure ApplicationWillShowModal;
|
procedure ApplicationWillShowModal;
|
||||||
begin
|
begin
|
||||||
// Any place that would attempt to use Cocoa-native modality.
|
// Any place that would attempt to use Cocoa-native modality.
|
||||||
|
@ -29,8 +29,8 @@ uses
|
|||||||
// Widgetset
|
// Widgetset
|
||||||
WSCheckLst, WSLCLClasses,
|
WSCheckLst, WSLCLClasses,
|
||||||
// LCL Cocoa
|
// LCL Cocoa
|
||||||
CocoaWSCommon, CocoaPrivate, CocoaCallback, CocoaWSStdCtrls,
|
CocoaWSCommon, CocoaPrivate, CocoaConfig, CocoaGDIObjects,
|
||||||
CocoaListControl, CocoaTables, CocoaScrollers, CocoaWSScrollers;
|
CocoaWSStdCtrls, CocoaListControl, CocoaTables, CocoaScrollers, CocoaWSScrollers;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -43,6 +43,14 @@ type
|
|||||||
checklist: TCustomCheckListBox;
|
checklist: TCustomCheckListBox;
|
||||||
constructor Create(AOwner: NSObject; ATarget: TWinControl; AHandleView: NSView); override;
|
constructor Create(AOwner: NSObject; ATarget: TWinControl; AHandleView: NSView); override;
|
||||||
procedure SetItemCheckedAt( row: Integer; CheckState: Integer); override;
|
procedure SetItemCheckedAt( row: Integer; CheckState: Integer); override;
|
||||||
|
function drawItem(row: Integer; ctx: TCocoaContext; const r: TRect;
|
||||||
|
state: TOwnerDrawState): Boolean; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaTableCheckListBoxProcessor }
|
||||||
|
|
||||||
|
TCocoaTableCheckListBoxProcessor = class( TCocoaTableListBoxProcessor )
|
||||||
|
procedure onOwnerDrawItem(rowView: NSView); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWSCustomCheckListBox }
|
{ TCocoaWSCustomCheckListBox }
|
||||||
@ -52,6 +60,7 @@ type
|
|||||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
|
||||||
class function GetState(const ACheckListBox: TCustomCheckListBox; const AIndex: integer): TCheckBoxState; override;
|
class function GetState(const ACheckListBox: TCustomCheckListBox; const AIndex: integer): TCheckBoxState; override;
|
||||||
class procedure SetState(const ACheckListBox: TCustomCheckListBox; const AIndex: integer; const AState: TCheckBoxState); override;
|
class procedure SetState(const ACheckListBox: TCustomCheckListBox; const AIndex: integer; const AState: TCheckBoxState); override;
|
||||||
|
class function GetCheckWidth(const ACheckListBox: TCustomCheckListBox): integer; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -77,6 +86,38 @@ begin
|
|||||||
LCLSendChangedMsg( self.Target, row );
|
LCLSendChangedMsg( self.Target, row );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TLCLCheckboxListCallback.drawItem(row: Integer; ctx: TCocoaContext;
|
||||||
|
const r: TRect; state: TOwnerDrawState): Boolean;
|
||||||
|
var
|
||||||
|
rectReducedLeftSpacing: TRect;
|
||||||
|
lv: TCocoaTableListView;
|
||||||
|
itemView: NSView;
|
||||||
|
begin
|
||||||
|
rectReducedLeftSpacing:= r;
|
||||||
|
lv:= TCocoaTableListView( self.Owner );
|
||||||
|
if Assigned(lv) then begin
|
||||||
|
itemView:= lv.viewAtColumn_row_makeIfNecessary( 0, row, false );
|
||||||
|
if Assigned(itemView) then
|
||||||
|
rectReducedLeftSpacing.Left:= Round( itemView.frame.origin.x );
|
||||||
|
end;
|
||||||
|
Result:= inherited drawItem(row, ctx, rectReducedLeftSpacing, state);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaTableCheckListBoxProcessor }
|
||||||
|
|
||||||
|
procedure TCocoaTableCheckListBoxProcessor.onOwnerDrawItem(rowView: NSView);
|
||||||
|
var
|
||||||
|
itemView: TCocoaTableListItem;
|
||||||
|
begin
|
||||||
|
itemView:= TCocoaTableListItem( rowView.subviews.objectAtIndex(0) );
|
||||||
|
if NOT Assigned(itemView) then
|
||||||
|
Exit;
|
||||||
|
if Assigned(itemView.imageView) then
|
||||||
|
itemView.imageView.setHidden( True );
|
||||||
|
if Assigned(itemView.textField) then
|
||||||
|
itemView.textField.setHidden( True );
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCocoaWSCustomCheckListBox }
|
{ TCocoaWSCustomCheckListBox }
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -101,7 +142,7 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
processor:= TCocoaTableListBoxProcessor.Create;
|
processor:= TCocoaTableCheckListBoxProcessor.Create;
|
||||||
list.lclSetProcessor( processor );
|
list.lclSetProcessor( processor );
|
||||||
list.callback := TLCLCheckboxListCallback.CreateWithView(list, AWinControl);
|
list.callback := TLCLCheckboxListCallback.CreateWithView(list, AWinControl);
|
||||||
list.lclSetCheckboxes(true);
|
list.lclSetCheckboxes(true);
|
||||||
@ -189,4 +230,10 @@ begin
|
|||||||
cocoaTLV.reloadDataForRow_column( AIndex, 0 );
|
cocoaTLV.reloadDataForRow_column( AIndex, 0 );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TCocoaWSCustomCheckListBox.GetCheckWidth(
|
||||||
|
const ACheckListBox: TCustomCheckListBox): integer;
|
||||||
|
begin
|
||||||
|
Result:= Round( CocoaConfigListView.vsList.item.checkBoxOccupiedWidth );
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user