From 9cfcdf24c5ef0a312030d13ad03e88f3ccd139c1 Mon Sep 17 00:00:00 2001 From: dmitry Date: Thu, 25 Jul 2019 14:36:31 +0000 Subject: [PATCH] cocoa: storing LCL title separately, so WS function would return the original value set. #35884 git-svn-id: trunk@61619 - --- lcl/interfaces/cocoa/cocoawsstdctrls.pas | 34 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pas b/lcl/interfaces/cocoa/cocoawsstdctrls.pas index 98fcb79a11..566399d8c8 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pas +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pas @@ -219,6 +219,7 @@ type TLCLButtonCallback = class(TLCLCommonCallback, IButtonCallback) public + LCLTitle: string; procedure ButtonClick; virtual; procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); override; procedure GetAllowMixedState(var allowed: Boolean); virtual; @@ -721,10 +722,30 @@ begin cf.release; end; +function GetButtonCallback(btn: NSButton): TLCLButtonCallback; +var + cb : ICommonCallback; + obj : TObject; +begin + Result := nil; + if not Assigned(btn) then Exit; + cb := btn.lclGetCallback; + if not Assigned(cb) then Exit; + obj := cb.GetCallbackObject; + if (not Assigned(obj)) or (not (obj is TLCLButtonCallback)) then Exit; + Result := TLCLButtonCallback(obj); +end; class procedure TCocoaWSButton.SetText(const AWinControl: TWinControl; const AText: String); +var + btn : NSButton; + cbo : TLCLButtonCallback; begin - NSButton(AWinControl.Handle).setTitle(ControlTitleToNSStr(AText)); + btn := NSButton(AWinControl.Handle); + btn.setTitle(ControlTitleToNSStr(AText)); + cbo := GetButtonCallback(btn); + if Assigned(cbo) then + cbo.LCLTitle := AText; end; class function TCocoaWSButton.GetText(const AWinControl: TWinControl; @@ -732,12 +753,19 @@ class function TCocoaWSButton.GetText(const AWinControl: TWinControl; var btn: NSButton; lStr: NSString; + cbo : TLCLButtonCallback; begin Result := AWinControl.HandleAllocated; if not Result then Exit; btn := NSButton(AWinControl.Handle); - lStr := btn.title(); - AText := NSStringToString(lStr); + cbo := GetButtonCallback(btn); + if Assigned(cbo) then + AText := cbo.LCLTitle + else + begin + lStr := btn.title(); + AText := NSStringToString(lStr); + end; end; class function TCocoaWSButton.GetTextLen(const AWinControl: TWinControl;