cocoa: Fixes bug #31192, unable to type multi-digit value in float spin edit

git-svn-id: trunk@54391 -
This commit is contained in:
sekelsenmat 2017-03-12 20:49:34 +00:00
parent bf0939e320
commit 3fc7fc4a5d

View File

@ -850,11 +850,13 @@ type
NumberFormatter: NSNumberFormatter; NumberFormatter: NSNumberFormatter;
Spin: TCustomFloatSpinEdit; Spin: TCustomFloatSpinEdit;
procedure dealloc; override; procedure dealloc; override;
procedure UpdateValueFromCocoa(); message 'UpdateValueFromCocoa';
procedure UpdateControl(ASpinEdit: TCustomFloatSpinEdit); message 'UpdateControl:'; procedure UpdateControl(ASpinEdit: TCustomFloatSpinEdit); message 'UpdateControl:';
procedure CreateSubcontrols(ASpinEdit: TCustomFloatSpinEdit; const AParams: TCreateParams); message 'CreateSubControls:AParams:'; procedure CreateSubcontrols(ASpinEdit: TCustomFloatSpinEdit; const AParams: TCreateParams); message 'CreateSubControls:AParams:';
procedure PositionSubcontrols(const ALeft, ATop, AWidth, AHeight: Integer); message 'PositionSubcontrols:ATop:AWidth:AHeight:'; procedure PositionSubcontrols(const ALeft, ATop, AWidth, AHeight: Integer); message 'PositionSubcontrols:ATop:AWidth:AHeight:';
procedure StepperChanged(sender: NSObject); message 'StepperChanged:'; procedure StepperChanged(sender: NSObject); message 'StepperChanged:';
function GetFieldEditor: TCocoaFieldEditor; message 'GetFieldEditor'; function GetFieldEditor: TCocoaFieldEditor; message 'GetFieldEditor';
procedure textDidEndEditing(notification: NSNotification); message 'textDidEndEditing:'; override;
// NSTextFieldDelegateProtocol // NSTextFieldDelegateProtocol
procedure controlTextDidChange(obj: NSNotification); override; procedure controlTextDidChange(obj: NSNotification); override;
// lcl // lcl
@ -3932,6 +3934,18 @@ begin
inherited dealloc; inherited dealloc;
end; end;
procedure TCocoaSpinEdit.UpdateValueFromCocoa();
var
lValid: Boolean = False;
lValue: String;
lFloat: Double;
begin
lValue := CocoaUtils.NSStringToString(stringValue());
lValid := SysUtils.TryStrToFloat(lValue, lFloat);
if lValid then
Spin.Value := lFloat;
end;
procedure TCocoaSpinEdit.UpdateControl(ASpinEdit: TCustomFloatSpinEdit); procedure TCocoaSpinEdit.UpdateControl(ASpinEdit: TCustomFloatSpinEdit);
begin begin
Stepper.setMaxValue(ASpinEdit.MaxValue); Stepper.setMaxValue(ASpinEdit.MaxValue);
@ -4024,15 +4038,16 @@ begin
end; end;
end; end;
procedure TCocoaSpinEdit.controlTextDidChange(obj: NSNotification); procedure TCocoaSpinEdit.textDidEndEditing(notification: NSNotification);
var
lValid: Boolean = False;
lValue: String;
lFloat: Double;
begin begin
lValue := CocoaUtils.NSStringToString(stringValue()); UpdateValueFromCocoa();
lValid := SysUtils.TryStrToFloat(lValue, lFloat); inherited textDidEndEditing(notification);
Spin.Value := lFloat; end;
procedure TCocoaSpinEdit.controlTextDidChange(obj: NSNotification);
begin
// This was causing bug 31192
//UpdateValueFromCocoa();
end; end;
function TCocoaSpinEdit.acceptsFirstResponder: Boolean; function TCocoaSpinEdit.acceptsFirstResponder: Boolean;