mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-16 08:00:30 +01:00
carbon: allow to set grayed status for checkboxes. #21136
git-svn-id: trunk@34915 -
This commit is contained in:
parent
105f704391
commit
b17a03f253
@ -37,13 +37,17 @@ uses
|
||||
LCLMessageGlue, LCLType, Graphics;
|
||||
|
||||
type
|
||||
TUpdateValueEvent = procedure (Sender: TObject; CurrentValue: Integer; var AValue: Integer) of object;
|
||||
|
||||
{ TCarbonCustomCheckBox }
|
||||
|
||||
TCarbonCustomCheckBox = class(TCarbonControl)
|
||||
private
|
||||
fSupressNotify : Boolean;
|
||||
LastState: Integer;
|
||||
isSetState: Boolean;
|
||||
public
|
||||
UpdateValue: TUpdateValueEvent;
|
||||
class function GetValidEvents: TCarbonControlEvents; override;
|
||||
procedure Hit(AControlPart: ControlPartCode); override;
|
||||
procedure ValueChanged; override;
|
||||
@ -146,7 +150,17 @@ end;
|
||||
Value changed event handler
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TCarbonCustomCheckBox.ValueChanged;
|
||||
var
|
||||
NewState: Integer;
|
||||
RS: Integer;
|
||||
begin
|
||||
if not isSetState and Assigned(UpdateValue) then begin
|
||||
RS:=RetrieveState;
|
||||
NewState:=RS;
|
||||
UpdateValue(Self, LastState, NewState);
|
||||
if NewState<>RS then SetValue(NewState);
|
||||
end;
|
||||
LastState:=RetrieveState;
|
||||
if not fSupressNotify then
|
||||
LCLSendChangedMsg(LCLObject)
|
||||
else
|
||||
@ -171,8 +185,11 @@ end;
|
||||
procedure TCarbonCustomCheckBox.SetState(AState: Integer; NotifyChangeState: Boolean);
|
||||
begin
|
||||
if RetrieveState=AState then Exit;
|
||||
isSetState:=True;
|
||||
fSupressNotify := not NotifyChangeState;
|
||||
SetControl32BitValue(ControlRef(Widget), AState);
|
||||
LastState:=AState;
|
||||
isSetState:=False;
|
||||
end;
|
||||
|
||||
{ TCarbonCheckBox }
|
||||
|
||||
@ -197,6 +197,8 @@ type
|
||||
{ TCarbonWSCustomCheckBox }
|
||||
|
||||
TCarbonWSCustomCheckBox = class(TWSCustomCheckBox)
|
||||
public
|
||||
class procedure UpdateValue(Sender: TObject; OldValue: Integer; var ANewValue: Integer);
|
||||
published
|
||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||
class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override;
|
||||
@ -1060,6 +1062,28 @@ end;
|
||||
|
||||
{ TCarbonWSCustomCheckBox }
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonWSCustomCheckBox.CreateHandle
|
||||
Params: Sender - CarbonCheckBox
|
||||
OldValue - the previous value of the checkbox
|
||||
NewValue - the value of the check box, about to be set
|
||||
|
||||
Updates the value, to be Mixed state, if AllowGray is on the TCustomCheckBox
|
||||
The method is called, only if the it's being updated by User, rather than
|
||||
explicit SetState method
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TCarbonWSCustomCheckBox.UpdateValue(Sender: TObject; OldValue: Integer; var ANewValue: Integer);
|
||||
var
|
||||
cb: TCarbonCheckBox;
|
||||
begin
|
||||
cb:=TCarbonCheckBox(Sender);
|
||||
if (TCustomCheckBox(cb.LCLObject).AllowGrayed) and (OldValue=kControlCheckBoxUncheckedValue)
|
||||
and (ANewValue=kControlCheckBoxCheckedValue) then
|
||||
begin
|
||||
ANewValue:=kControlCheckBoxMixedValue;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonWSCustomCheckBox.CreateHandle
|
||||
Params: AWinControl - LCL control
|
||||
@ -1070,8 +1094,12 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
class function TCarbonWSCustomCheckBox.CreateHandle(const AWinControl: TWinControl;
|
||||
const AParams: TCreateParams): TLCLIntfHandle;
|
||||
var
|
||||
cb : TCarbonCheckBox;
|
||||
begin
|
||||
Result := TLCLIntfHandle(TCarbonCheckBox.Create(AWinControl, AParams));
|
||||
cb:=TCarbonCheckBox.Create(AWinControl, AParams);
|
||||
cb.UpdateValue:=@UpdateValue;
|
||||
Result := TLCLIntfHandle(cb);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user