carbon: allow to set grayed status for checkboxes. #21136

git-svn-id: trunk@34915 -
This commit is contained in:
dmitry 2012-01-25 02:42:00 +00:00
parent 105f704391
commit b17a03f253
2 changed files with 46 additions and 1 deletions

View File

@ -37,13 +37,17 @@ uses
LCLMessageGlue, LCLType, Graphics; LCLMessageGlue, LCLType, Graphics;
type type
TUpdateValueEvent = procedure (Sender: TObject; CurrentValue: Integer; var AValue: Integer) of object;
{ TCarbonCustomCheckBox } { TCarbonCustomCheckBox }
TCarbonCustomCheckBox = class(TCarbonControl) TCarbonCustomCheckBox = class(TCarbonControl)
private private
fSupressNotify : Boolean; fSupressNotify : Boolean;
LastState: Integer;
isSetState: Boolean;
public public
UpdateValue: TUpdateValueEvent;
class function GetValidEvents: TCarbonControlEvents; override; class function GetValidEvents: TCarbonControlEvents; override;
procedure Hit(AControlPart: ControlPartCode); override; procedure Hit(AControlPart: ControlPartCode); override;
procedure ValueChanged; override; procedure ValueChanged; override;
@ -146,7 +150,17 @@ end;
Value changed event handler Value changed event handler
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCarbonCustomCheckBox.ValueChanged; procedure TCarbonCustomCheckBox.ValueChanged;
var
NewState: Integer;
RS: Integer;
begin 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 if not fSupressNotify then
LCLSendChangedMsg(LCLObject) LCLSendChangedMsg(LCLObject)
else else
@ -171,8 +185,11 @@ end;
procedure TCarbonCustomCheckBox.SetState(AState: Integer; NotifyChangeState: Boolean); procedure TCarbonCustomCheckBox.SetState(AState: Integer; NotifyChangeState: Boolean);
begin begin
if RetrieveState=AState then Exit; if RetrieveState=AState then Exit;
isSetState:=True;
fSupressNotify := not NotifyChangeState; fSupressNotify := not NotifyChangeState;
SetControl32BitValue(ControlRef(Widget), AState); SetControl32BitValue(ControlRef(Widget), AState);
LastState:=AState;
isSetState:=False;
end; end;
{ TCarbonCheckBox } { TCarbonCheckBox }

View File

@ -197,6 +197,8 @@ type
{ TCarbonWSCustomCheckBox } { TCarbonWSCustomCheckBox }
TCarbonWSCustomCheckBox = class(TWSCustomCheckBox) TCarbonWSCustomCheckBox = class(TWSCustomCheckBox)
public
class procedure UpdateValue(Sender: TObject; OldValue: Integer; var ANewValue: Integer);
published published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override; class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override;
@ -1060,6 +1062,28 @@ end;
{ TCarbonWSCustomCheckBox } { 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 Method: TCarbonWSCustomCheckBox.CreateHandle
Params: AWinControl - LCL control Params: AWinControl - LCL control
@ -1070,8 +1094,12 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
class function TCarbonWSCustomCheckBox.CreateHandle(const AWinControl: TWinControl; class function TCarbonWSCustomCheckBox.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; const AParams: TCreateParams): TLCLIntfHandle;
var
cb : TCarbonCheckBox;
begin begin
Result := TLCLIntfHandle(TCarbonCheckBox.Create(AWinControl, AParams)); cb:=TCarbonCheckBox.Create(AWinControl, AParams);
cb.UpdateValue:=@UpdateValue;
Result := TLCLIntfHandle(cb);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------