mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 00:59:15 +02:00
cocoa: adding the check for min and max values of the spin edit. If they are the same, pretend we don't have any boundires
(cherry picked from commit 1bef01e030
)
This commit is contained in:
parent
95c87a711d
commit
5e1fcd37e0
@ -29,6 +29,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
// rtl+ftl
|
// rtl+ftl
|
||||||
Types, Classes, SysUtils,
|
Types, Classes, SysUtils,
|
||||||
|
Math, // needed for MinDouble, MaxDouble
|
||||||
CGGeometry,
|
CGGeometry,
|
||||||
// Libs
|
// Libs
|
||||||
MacOSAll, CocoaAll, CocoaUtils, CocoaGDIObjects,
|
MacOSAll, CocoaAll, CocoaUtils, CocoaGDIObjects,
|
||||||
@ -408,7 +409,7 @@ type
|
|||||||
//Spin: TCustomFloatSpinEdit;
|
//Spin: TCustomFloatSpinEdit;
|
||||||
procedure dealloc; override;
|
procedure dealloc; override;
|
||||||
function updateStepper: boolean; message 'updateStepper';
|
function updateStepper: boolean; message 'updateStepper';
|
||||||
procedure UpdateControl(min, max, inc, avalue: double; ADecimalPlaces: Integer); message 'UpdateControl:::::';
|
procedure UpdateControl(min, max, inc, avalue: double; ADecimalPlaces: Integer; checkMinMax: Boolean); message 'UpdateControl::::::';
|
||||||
procedure lclCreateSubcontrols(const AParams: TCreateParams); message 'lclCreateSubControls:';
|
procedure lclCreateSubcontrols(const AParams: TCreateParams); message 'lclCreateSubControls:';
|
||||||
procedure lclReleaseSubcontrols; message 'lclReleaseSubcontrols';
|
procedure lclReleaseSubcontrols; message 'lclReleaseSubcontrols';
|
||||||
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:';
|
||||||
@ -1951,7 +1952,18 @@ begin
|
|||||||
Result := false;
|
Result := false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaSpinEdit.UpdateControl(min, max, inc, avalue: double; ADecimalPlaces: Integer);
|
|
||||||
|
// * value - the current value to be selected. Note: it will be adjusted
|
||||||
|
// to "min" and "max", if "checkMinMax" is set to true
|
||||||
|
// * min, max - minimum maximum values allowed. for NSStepper, there's no "unlimited"
|
||||||
|
// check. "Something" should be set as minimum and maximum
|
||||||
|
// * checkMinMax - indicates if the min and max values should be verified.
|
||||||
|
// in LCL is Min = Max then there's not boundries check applied
|
||||||
|
// Since "min" and "max" are doubles, it's safer to use a booleanFlag
|
||||||
|
// so the comparison is done by the caller, rather than using approximation
|
||||||
|
// * inc - incremeantal value to be used when "up" or "down" are pressed
|
||||||
|
// * DecimalPlaces - the number of decimals to used when showing the value
|
||||||
|
procedure TCocoaSpinEdit.UpdateControl(min, max, inc, avalue: double; ADecimalPlaces: Integer; checkMinMax: Boolean);
|
||||||
var
|
var
|
||||||
notifyChange : Boolean;
|
notifyChange : Boolean;
|
||||||
v : double;
|
v : double;
|
||||||
@ -1959,16 +1971,28 @@ begin
|
|||||||
Stepper.setIncrement(inc);
|
Stepper.setIncrement(inc);
|
||||||
|
|
||||||
v := avalue;
|
v := avalue;
|
||||||
if v < min then v := min
|
if checkMinMax then
|
||||||
else if v > max then v := max;
|
begin
|
||||||
|
if v < min then v := min
|
||||||
|
else if v > max then v := max;
|
||||||
|
end;
|
||||||
|
|
||||||
notifyChange := (v <> Stepper.doubleValue) or (decimalPlaces <> ADecimalPlaces);
|
notifyChange := (v <> Stepper.doubleValue) or (decimalPlaces <> ADecimalPlaces);
|
||||||
|
|
||||||
// set min/max after checking for notify change
|
// set min/max after checking for notify change
|
||||||
// .doubleValue would be adjusted by setting min/max
|
// .doubleValue would be adjusted by setting min/max
|
||||||
decimalPlaces := ADecimalPlaces;
|
decimalPlaces := ADecimalPlaces;
|
||||||
Stepper.setMinValue(min);
|
if checkMinMax then begin
|
||||||
Stepper.setMaxValue(max);
|
Stepper.setMinValue(min);
|
||||||
|
Stepper.setMaxValue(max);
|
||||||
|
end else begin
|
||||||
|
// "Math" unit declared MaxDouble and MinDouble constants
|
||||||
|
// however, using setMinValue to MinDouble, seems to be ignored
|
||||||
|
// and Cocoa falls back to the default "0". not sure why.
|
||||||
|
// Instead using -MaxDouble.
|
||||||
|
Stepper.setMinValue(-MaxDouble);
|
||||||
|
Stepper.setMaxValue(+MaxDouble);
|
||||||
|
end;
|
||||||
|
|
||||||
if notifychange then
|
if notifychange then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user