mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 00:20:24 +02:00
lcl-cocoa: Further implements SpinEdit, now clicking changes the value
git-svn-id: trunk@46628 -
This commit is contained in:
parent
2356ca7325
commit
a0642273b5
@ -760,16 +760,19 @@ type
|
||||
callback: ICommonCallback;
|
||||
Stepper: NSStepper;
|
||||
Edit: NSTextField;
|
||||
Spin: TCustomFloatSpinEdit;
|
||||
procedure dealloc; override;
|
||||
procedure UpdateControl(ASpinEdit: TCustomFloatSpinEdit); message 'UpdateControl:';
|
||||
procedure CreateSubcontrols(ASpinEdit: TCustomFloatSpinEdit; const AParams: TCreateParams); message 'CreateSubControls:AParams:';
|
||||
procedure ActionHandler(sender: NSObject); message 'ActionHandler:';
|
||||
procedure StepperChanged(sender: NSObject); message 'StepperChanged:';
|
||||
function acceptsFirstResponder: Boolean; override;
|
||||
function becomeFirstResponder: Boolean; override;
|
||||
function resignFirstResponder: Boolean; override;
|
||||
function lclGetCallback: ICommonCallback; override;
|
||||
procedure lclClearCallback; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
// NSViewFix
|
||||
function fittingSize: NSSize; override;
|
||||
end;
|
||||
|
||||
|
||||
@ -3347,6 +3350,9 @@ begin
|
||||
Stepper.setMinValue(ASpinEdit.MinValue);
|
||||
Stepper.setIncrement(ASpinEdit.Increment);
|
||||
Stepper.setDoubleValue(ASpinEdit.Value);
|
||||
|
||||
// update the UI too
|
||||
StepperChanged(Self);
|
||||
end;
|
||||
|
||||
procedure TCocoaSpinEdit.CreateSubcontrols(ASpinEdit: TCustomFloatSpinEdit; const AParams: TCreateParams);
|
||||
@ -3355,9 +3361,7 @@ const
|
||||
var
|
||||
lParams: TCreateParams;
|
||||
begin
|
||||
// General control setup
|
||||
setTarget(Self);
|
||||
setAction(objcselector('ActionHandler:'));
|
||||
Spin := ASpinEdit;
|
||||
|
||||
// Now creates the subcontrols
|
||||
lParams := AParams;
|
||||
@ -3368,19 +3372,26 @@ begin
|
||||
lParams.Width := DEFAULT_STEPPER_WIDTH;
|
||||
lParams.X := AParams.Width - DEFAULT_STEPPER_WIDTH;
|
||||
Stepper := NSStepper.alloc.lclInitWithCreateParams(lParams);
|
||||
Stepper.setValueWraps(False);
|
||||
|
||||
lParams.Width := AParams.Width - DEFAULT_STEPPER_WIDTH;
|
||||
lParams.X := 0;
|
||||
Edit := NSTextField.alloc.lclInitWithCreateParams(lParams);
|
||||
|
||||
// Change event for the stepper
|
||||
Stepper.setTarget(Self);
|
||||
Stepper.setAction(objcselector('StepperChanged:'));
|
||||
end;
|
||||
|
||||
procedure TCocoaSpinEdit.ActionHandler(sender: NSObject);
|
||||
procedure TCocoaSpinEdit.StepperChanged(sender: NSObject);
|
||||
var
|
||||
lStr: NSString;
|
||||
lNSStr: NSString;
|
||||
lStr: string;
|
||||
begin
|
||||
lStr := CocoaUtils.NSStringUtf8(Format('%f', [Stepper.doubleValue()]));
|
||||
Edit.setStringValue(lStr);
|
||||
lStr.release;
|
||||
lStr := Format('%.*f', [Spin.DecimalPlaces, Stepper.doubleValue()]);
|
||||
lNSStr := CocoaUtils.NSStringUtf8(lStr);
|
||||
Edit.setStringValue(lNSStr);
|
||||
lNSStr.release;
|
||||
end;
|
||||
|
||||
function TCocoaSpinEdit.acceptsFirstResponder: Boolean;
|
||||
@ -3417,5 +3428,12 @@ begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCocoaSpinEdit.fittingSize: NSSize;
|
||||
begin
|
||||
Result.width := -1;
|
||||
Edit.sizeToFit();
|
||||
Result.height := Edit.bounds.size.height;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -1219,20 +1219,19 @@ class procedure TCocoaWSWinControl.GetPreferredSize(
|
||||
const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer;
|
||||
WithThemeSpace: Boolean);
|
||||
var
|
||||
Obj: NSObject;
|
||||
lView: NSView;
|
||||
Size: NSSize;
|
||||
begin
|
||||
if AWinControl.HandleAllocated then
|
||||
if not AWinControl.HandleAllocated then Exit;
|
||||
|
||||
lView := CocoaUtils.GetNSObjectView(NSObject(AWinControl.Handle));
|
||||
if lView = nil then Exit;
|
||||
|
||||
if lView.respondsToSelector(objcselector('fittingSize')) then
|
||||
begin
|
||||
Obj := NSObject(AWinControl.Handle);
|
||||
{
|
||||
if Obj.isKindOfClass_(NSView) and obj.respondsToSelector(objcselector('fittingSize')) then
|
||||
begin
|
||||
Size := NSView(Obj).fittingSize;
|
||||
PreferredWidth := Round(Size.width);
|
||||
PreferredHeight := Round(Size.height);
|
||||
end;
|
||||
}
|
||||
Size := lView.fittingSize();
|
||||
PreferredWidth := Round(Size.width);
|
||||
PreferredHeight := Round(Size.height);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user