qt: don't send LM_CHANGE messages when changing State of TRadioButton and TCheckBox programatically. Use Toggled signal instead of Clicked to notify of changes in TRadioButton. Part of 0017139 and 0017104

git-svn-id: trunk@27054 -
This commit is contained in:
blikblum 2010-08-10 17:49:43 +00:00
parent 1aa796b724
commit e50914e4bf
2 changed files with 41 additions and 27 deletions

View File

@ -460,7 +460,6 @@ type
procedure SignalReleased; cdecl; procedure SignalReleased; cdecl;
procedure SignalClicked(Checked: Boolean = False); cdecl; procedure SignalClicked(Checked: Boolean = False); cdecl;
procedure SignalClicked2; cdecl; procedure SignalClicked2; cdecl;
procedure SignalToggled(Checked: Boolean); cdecl;
end; end;
{ TQtPushButton } { TQtPushButton }
@ -571,12 +570,13 @@ type
TQtRadioButton = class(TQtAbstractButton) TQtRadioButton = class(TQtAbstractButton)
private private
FClickedHook: QAbstractButton_hookH; FToggledHook: QAbstractButton_hookH;
protected protected
function CreateWidget(const AParams: TCreateParams):QWidgetH; override; function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
public public
procedure AttachEvents; override; procedure AttachEvents; override;
procedure DetachEvents; override; procedure DetachEvents; override;
procedure SignalToggled(Checked: Boolean); cdecl;
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override; function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
end; end;
@ -4360,17 +4360,6 @@ begin
DeliverMessage(Msg); DeliverMessage(Msg);
end; end;
{------------------------------------------------------------------------------
Function: TQtAbstractButton.SignalToggled
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
procedure TQtAbstractButton.SignalToggled(Checked: Boolean); cdecl;
begin
{use this for TToggleButton }
end;
{ TQtPushButton } { TQtPushButton }
function TQtPushButton.CreateWidget(const AParams: TCreateParams): QWidgetH; function TQtPushButton.CreateWidget(const AParams: TCreateParams): QWidgetH;
@ -5059,11 +5048,14 @@ end;
procedure TQtCheckBox.signalStateChanged(p1: Integer); cdecl; procedure TQtCheckBox.signalStateChanged(p1: Integer); cdecl;
var var
Msg: TLMessage; Msg: TLMessage;
begin
if not InUpdate then
begin begin
FillChar(Msg, SizeOf(Msg), #0); FillChar(Msg, SizeOf(Msg), #0);
Msg.Msg := LM_CHANGED; Msg.Msg := LM_CHANGED;
DeliverMessage(Msg); DeliverMessage(Msg);
end; end;
end;
{ TQtRadioButton } { TQtRadioButton }
@ -5088,19 +5080,29 @@ end;
procedure TQtRadioButton.AttachEvents; procedure TQtRadioButton.AttachEvents;
begin begin
inherited AttachEvents; inherited AttachEvents;
FClickedHook := QAbstractButton_hook_create(Widget); FToggledHook := QAbstractButton_hook_create(Widget);
QAbstractButton_hook_hook_toggled(FToggledHook, @SignalToggled);
QAbstractButton_hook_hook_clicked(FClickedHook, @SignalClicked);
end; end;
procedure TQtRadioButton.DetachEvents; procedure TQtRadioButton.DetachEvents;
begin begin
QAbstractButton_hook_destroy(FClickedHook); QAbstractButton_hook_destroy(FToggledHook);
inherited DetachEvents; inherited DetachEvents;
end; end;
function TQtRadioButton.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; procedure TQtRadioButton.SignalToggled(Checked: Boolean); cdecl;
cdecl; var
Msg: TLMessage;
begin
if not InUpdate then
begin
FillChar(Msg, SizeOf(Msg), #0);
Msg.Msg := LM_CHANGED;
DeliverMessage(Msg);
end;
end;
function TQtRadioButton.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
begin begin
Result := inherited EventFilter(Sender, Event); Result := inherited EventFilter(Sender, Event);
if (LCLObject <> nil) and if (LCLObject <> nil) and
@ -5110,7 +5112,7 @@ begin
(QKeyEvent_key(QKeyEventH(Event)) = QtKey_Space) and (QKeyEvent_key(QKeyEventH(Event)) = QtKey_Space) and
isChecked)) isChecked))
then then
Result := not (LCLObject.Parent is TRadioGroup); Result := False;
end; end;
{ TQtGroupBox } { TQtGroupBox }

View File

@ -1060,13 +1060,19 @@ end;
Returns: Nothing Returns: Nothing
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
class procedure TQtWSCustomCheckBox.SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); class procedure TQtWSCustomCheckBox.SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState);
var
QtCheckBox: TQtCheckBox;
begin begin
//enclose the call between Begin/EndUpdate to avoid send LM_CHANGE message
QtCheckBox := TQtCheckBox(ACustomCheckBox.Handle);
QtCheckBox.BeginUpdate;
case NewState of case NewState of
cbGrayed: TQtCheckBox(ACustomCheckBox.Handle).setCheckState(QtPartiallyChecked); cbGrayed: QtCheckBox.setCheckState(QtPartiallyChecked);
cbChecked: TQtCheckBox(ACustomCheckBox.Handle).setCheckState(QtChecked); cbChecked: QtCheckBox.setCheckState(QtChecked);
else else
TQtCheckBox(ACustomCheckBox.Handle).setCheckState(QtUnchecked); QtCheckBox.setCheckState(QtUnchecked);
end; end;
QtCheckBox.EndUpdate;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -1120,8 +1126,14 @@ end;
Sets the state of the control Sets the state of the control
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
class procedure TQtWSRadioButton.SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); class procedure TQtWSRadioButton.SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState);
var
QtRadioButton: TQtRadioButton;
begin begin
TQtRadioButton(ACustomCheckBox.Handle).setChecked(NewState = cbChecked); //enclose the call between Begin/EndUpdate to avoid send LM_CHANGE message
QtRadioButton := TQtRadioButton(ACustomCheckBox.Handle);
QtRadioButton.BeginUpdate;
QtRadioButton.setChecked(NewState = cbChecked);
QtRadioButton.EndUpdate;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------