Cocoa: avoid sending CustomDraw messages to ListBox/CheckListBox

they only support DrawItem messages
This commit is contained in:
rich2014 2024-08-14 20:26:21 +08:00
parent 43ab1946ea
commit fc8387d1fc
4 changed files with 48 additions and 13 deletions

View File

@ -88,6 +88,13 @@ type
property CocoaOnlyState: Boolean read IsCocoaOnlyState write SetCocoaOnlyState;
end;
{
currently the following callbacks implement IListViewCallBack,
need to be considered before modification:
1. TLCLListViewCallback
2. TLCLListBoxCallback
3. TLCLCheckboxListCallback
}
{ IListViewCallBack }
IListViewCallBack = interface(ICommonCallback)
@ -101,8 +108,9 @@ type
procedure SetItemCheckedAt( row: Integer; CheckState: Integer);
function shouldSelectionChange(NewSel: Integer): Boolean;
procedure ColumnClicked(ACol: Integer);
function commonDrawItem( row: Integer; ctx: TCocoaContext; const r: TRect; state: TOwnerDrawState ): Boolean;
function listViewCustomDraw( row: Integer; col: Integer; ctx: TCocoaContext; state: TCustomDrawState ): Boolean;
function drawItem( row: Integer; ctx: TCocoaContext; const r: TRect; state: TOwnerDrawState ): Boolean;
function customDraw( row: Integer; col: Integer; ctx: TCocoaContext; state: TCustomDrawState ): Boolean;
function isCustomDrawSupported: Boolean;
procedure GetRowHeight(rowidx: Integer; var height: Integer);
function GetBorderStyle: TBorderStyle;
function onAddSubview( aView:NSView ): Boolean;

View File

@ -42,10 +42,11 @@ type
procedure selectOne(ARow: Integer; isSelected:Boolean );
function shouldSelectionChange(NewSel: Integer): Boolean;
procedure ColumnClicked(ACol: Integer);
function commonDrawItem( row: Integer; ctx: TCocoaContext; const r: TRect;
function drawItem( row: Integer; ctx: TCocoaContext; const r: TRect;
state: TOwnerDrawState): Boolean;
function listViewCustomDraw( row: Integer; col: Integer;
function customDraw( row: Integer; col: Integer;
ctx: TCocoaContext; state: TCustomDrawState ): Boolean;
function isCustomDrawSupported: Boolean;
procedure GetRowHeight(rowidx: Integer; var h: Integer);
function GetBorderStyle: TBorderStyle;
function onAddSubview(aView: NSView): Boolean;
@ -567,7 +568,7 @@ begin
TCustomListViewAccess(Target).InitializeWnd;
end;
function TLCLListViewCallback.commonDrawItem( row: Integer; ctx: TCocoaContext;
function TLCLListViewCallback.drawItem( row: Integer; ctx: TCocoaContext;
const r: TRect; state: TOwnerDrawState ): Boolean;
var
Mess: TLMDrawListItem;
@ -584,7 +585,7 @@ begin
Result:= False;
end;
function TLCLListViewCallback.listViewCustomDraw(row: Integer; col: Integer;
function TLCLListViewCallback.customDraw(row: Integer; col: Integer;
ctx: TCocoaContext; state: TCustomDrawState ): Boolean;
var
ALV: TCustomListViewAccess;
@ -607,5 +608,10 @@ begin
Result:= cdrSkipDefault in drawResult;
end;
function TLCLListViewCallback.isCustomDrawSupported: Boolean;
begin
Result:= True;
end;
end.

View File

@ -75,6 +75,17 @@ type
procedure dealloc; override;
end;
{
1. TCocoaTableListView related need to support
TListView/TListBox/TCheckListBox, etc.
2. the differences between these controls can be considered to be
implemented in the callback.
3. however, after careful consideration, we tried to keep the original
intention of the callback, and added TCocoaTableViewProcessor to
isolate these differences.
}
{ TCocoaTableViewProcessor }
TCocoaTableViewProcessor = class
function isInitializing( tv: NSTableView ): Boolean; virtual; abstract;
procedure onReloadData( tv: NSTableView ); virtual; abstract;
@ -502,7 +513,7 @@ begin
if isChecked(self,row) then
Include(ItemState, odChecked);
Result:= callback.commonDrawItem(row, ctx, NSRectToRect(clipRect), ItemState);
Result:= callback.drawItem(row, ctx, NSRectToRect(clipRect), ItemState);
finally
ctx.Free;
end;
@ -515,7 +526,11 @@ var
state: TCustomDrawState;
begin
Result:= False;
if not Assigned(callback) then Exit;
if NOT Assigned(callback) then
Exit;
if NOT callback.isCustomDrawSupported then
Exit;
ctx := TCocoaContext.Create(NSGraphicsContext.currentContext);
ctx.InitDraw(Round(clipRect.size.width), Round(clipRect.size.height));
try
@ -527,7 +542,7 @@ begin
if isChecked(self,row) then
Include(state, cdsChecked);
Result:= callback.listViewCustomDraw(row, col, ctx, state);
Result:= callback.customDraw(row, col, ctx, state);
finally
ctx.Free;
end;

View File

@ -287,10 +287,11 @@ type
procedure SetItemCheckedAt( row: Integer; isChecked: Integer); virtual;
function shouldSelectionChange(NewSel: Integer): Boolean; virtual;
procedure ColumnClicked(ACol: Integer); virtual;
function commonDrawItem( row: Integer; ctx: TCocoaContext; const r: TRect;
function drawItem( row: Integer; ctx: TCocoaContext; const r: TRect;
state: TOwnerDrawState ): Boolean; virtual;
function listViewCustomDraw( row: Integer; col: Integer;
function customDraw( row: Integer; col: Integer;
ctx: TCocoaContext; state: TCustomDrawState ): Boolean; virtual;
function isCustomDrawSupported: Boolean; virtual;
procedure GetRowHeight(rowidx: integer; var h: Integer); virtual;
function GetBorderStyle: TBorderStyle;
function onAddSubview(aView: NSView): Boolean;
@ -668,7 +669,7 @@ begin
// not needed
end;
function TLCLListBoxCallback.commonDrawItem( row: Integer; ctx: TCocoaContext;
function TLCLListBoxCallback.drawItem( row: Integer; ctx: TCocoaContext;
const r: TRect; state: TOwnerDrawState ): Boolean;
var
DrawStruct: TDrawListItemStruct;
@ -685,12 +686,17 @@ begin
Result:= True;
end;
function TLCLListBoxCallback.listViewCustomDraw(row: Integer; col: Integer;
function TLCLListBoxCallback.customDraw(row: Integer; col: Integer;
ctx: TCocoaContext; state: TCustomDrawState ): Boolean;
begin
Result:= False;
end;
function TLCLListBoxCallback.isCustomDrawSupported: Boolean;
begin
Result:= False;
end;
procedure TLCLListBoxCallback.GetRowHeight(rowidx: integer; var h: Integer);
begin
if TCustomListBox(Target).Style = lbOwnerDrawVariable then