mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 13:59:31 +02:00
Cocoa/ComboBox: csOwnerDrawVariable style supported
This commit is contained in:
parent
fcd3e2ca62
commit
8d50905d77
@ -211,6 +211,7 @@ type
|
||||
procedure ComboBoxSelectionDidChange;
|
||||
procedure ComboBoxSelectionIsChanging;
|
||||
|
||||
procedure GetRowHeight(rowidx: integer; var h: Integer);
|
||||
procedure ComboBoxDrawItem(itemIndex: Integer; ctx: TCocoaContext;
|
||||
const r: TRect; isSelected: Boolean);
|
||||
end;
|
||||
@ -317,7 +318,7 @@ type
|
||||
TCocoaReadOnlyComboBox = objcclass(NSPopUpButton)
|
||||
private
|
||||
_textColorAttribs: NSDictionary;
|
||||
_itemHeight: Integer;
|
||||
_defaultItemHeight: Integer;
|
||||
public
|
||||
//Owner: TCustomComboBox;
|
||||
callback: IComboboxCallBack;
|
||||
@ -332,8 +333,9 @@ type
|
||||
function initWithFrame(frameRect: NSRect): id; override;
|
||||
procedure dealloc; override;
|
||||
|
||||
function lclGetItemHeight: Integer message 'lclGetItemHeight';
|
||||
procedure lclSetItemHeight(itemHeight: Integer ); message 'lclSetItemHeight:';
|
||||
function lclGetItemHeight( row: Integer ): Integer; message 'lclGetItemHeight:';
|
||||
function lclGetDefaultItemHeight: Integer; message 'lclGetDefaultItemHeight';
|
||||
procedure lclSetDefaultItemHeight(itemHeight: Integer); message 'lclSetItemHeight:';
|
||||
|
||||
function acceptsFirstResponder: LCLObjCBoolean; override;
|
||||
function lclGetCallback: ICommonCallback; override;
|
||||
@ -524,7 +526,8 @@ begin
|
||||
|
||||
if FOwner.isOwnerDrawn then
|
||||
begin
|
||||
menuItem := TCocoaReadOnlyView.alloc.initWithFrame( NSMakeRect(0,0, FOwner.frame.size.width, FOwner.lclGetItemHeight) );
|
||||
menuItem := TCocoaReadOnlyView.alloc.initWithFrame(
|
||||
NSMakeRect(0,0, FOwner.frame.size.width, FOwner.lclGetItemHeight(index)) );
|
||||
menuItem.itemIndex := Index;
|
||||
menuItem.combobox := FOwner;
|
||||
|
||||
@ -1597,7 +1600,7 @@ end;
|
||||
function TCocoaReadOnlyComboBox.initWithFrame(frameRect: NSRect): id;
|
||||
begin
|
||||
Result:=inherited initWithFrame(frameRect);
|
||||
_itemHeight:= CocoaConfigComboBox.readOnly.item.defaultHeight;
|
||||
_defaultItemHeight:= CocoaConfigComboBox.readOnly.item.defaultHeight;
|
||||
end;
|
||||
|
||||
procedure TCocoaReadOnlyComboBox.dealloc;
|
||||
@ -1608,17 +1611,25 @@ begin
|
||||
inherited dealloc;
|
||||
end;
|
||||
|
||||
function TCocoaReadOnlyComboBox.lclGetItemHeight: Integer;
|
||||
function TCocoaReadOnlyComboBox.lclGetDefaultItemHeight: Integer;
|
||||
begin
|
||||
Result:= _itemHeight;
|
||||
Result:= _defaultItemHeight;
|
||||
end;
|
||||
|
||||
procedure TCocoaReadOnlyComboBox.lclSetItemHeight(itemHeight: Integer);
|
||||
function TCocoaReadOnlyComboBox.lclGetItemHeight( row: Integer ): Integer;
|
||||
begin
|
||||
if self.isOwnerMeasure and Assigned(self.callback) then
|
||||
self.callback.GetRowHeight( row, Result )
|
||||
else
|
||||
Result:= _defaultItemHeight;
|
||||
end;
|
||||
|
||||
procedure TCocoaReadOnlyComboBox.lclSetDefaultItemHeight(itemHeight: Integer);
|
||||
begin
|
||||
if itemHeight <= 0 then
|
||||
_itemHeight:= CocoaConfigComboBox.readOnly.item.defaultHeight
|
||||
_defaultItemHeight:= CocoaConfigComboBox.readOnly.item.defaultHeight
|
||||
else
|
||||
_itemHeight:= itemHeight;
|
||||
_defaultItemHeight:= itemHeight;
|
||||
end;
|
||||
|
||||
function TCocoaReadOnlyComboBox.lclGetCallback: ICommonCallback;
|
||||
|
@ -86,6 +86,7 @@ type
|
||||
procedure ComboBoxSelectionDidChange;
|
||||
procedure ComboBoxSelectionIsChanging;
|
||||
|
||||
procedure GetRowHeight(rowidx: integer; var h: Integer);
|
||||
procedure ComboBoxDrawItem(itemIndex: Integer; ctx: TCocoaContext;
|
||||
const r: TRect; isSelected: Boolean);
|
||||
end;
|
||||
@ -824,6 +825,9 @@ end;
|
||||
|
||||
{ TLCLComboboxCallback }
|
||||
|
||||
type
|
||||
TCustomComboBoxAccess = class(TCustomComboBox);
|
||||
|
||||
procedure TLCLComboboxCallback.ComboBoxWillPopUp;
|
||||
begin
|
||||
isShowPopup := true;
|
||||
@ -846,6 +850,11 @@ begin
|
||||
|
||||
end;
|
||||
|
||||
procedure TLCLComboboxCallback.GetRowHeight(rowidx: integer; var h: Integer);
|
||||
begin
|
||||
TCustomComboBoxAccess(Target).MeasureItem(rowidx, h);
|
||||
end;
|
||||
|
||||
procedure TLCLComboboxCallback.ComboBoxDrawItem(itemIndex: Integer;
|
||||
ctx: TCocoaContext; const r: TRect; isSelected: Boolean);
|
||||
var
|
||||
@ -1940,11 +1949,6 @@ end;
|
||||
|
||||
{ TCocoaWSCustomComboBox }
|
||||
|
||||
type
|
||||
TCustomComboBoxAccess = class(TCustomComboBox)
|
||||
end;
|
||||
|
||||
|
||||
class function TCocoaWSCustomComboBox.getNSText(const ACustomComboBox: TCustomComboBox): NSText;
|
||||
var
|
||||
control: NSControl;
|
||||
@ -1975,7 +1979,7 @@ begin
|
||||
TComboBoxAsyncHelper.SetLastIndex(rocmb);
|
||||
rocmb.callback:=TLCLComboboxCallback.Create(rocmb, AWinControl);
|
||||
Result:=TLCLHandle(rocmb);
|
||||
rocmb.lclSetItemHeight( TCustomComboBoxAccess(AWinControl).ItemHeight );
|
||||
rocmb.lclSetDefaultItemHeight( TCustomComboBoxAccess(AWinControl).ItemHeight );
|
||||
rocmb.isOwnerDrawn := ComboBoxIsOwnerDrawn(TCustomComboBox(AWinControl).Style);
|
||||
rocmb.isOwnerMeasure := ComboBoxIsVariable(TCustomComboBox(AWinControl).Style);
|
||||
end
|
||||
@ -2219,7 +2223,7 @@ begin
|
||||
end;
|
||||
|
||||
if ComboBoxStyleIsReadOnly(ACustomComboBox.Style) then
|
||||
Result:=TCocoaReadOnlyComboBox(ACustomComboBox.Handle).lclGetItemHeight
|
||||
Result:=TCocoaReadOnlyComboBox(ACustomComboBox.Handle).lclGetDefaultItemHeight
|
||||
else
|
||||
Result:=Round(TCocoaComboBox(ACustomComboBox.Handle).itemHeight);
|
||||
end;
|
||||
@ -2231,7 +2235,7 @@ begin
|
||||
Exit;
|
||||
|
||||
if ComboBoxStyleIsReadOnly(ACustomComboBox.Style) then
|
||||
TCocoaReadOnlyComboBox(ACustomComboBox.Handle).lclSetItemHeight(AItemHeight)
|
||||
TCocoaReadOnlyComboBox(ACustomComboBox.Handle).lclSetDefaultItemHeight(AItemHeight)
|
||||
else
|
||||
TCocoaComboBox(ACustomComboBox.Handle).setItemHeight(AItemHeight);
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user