From 5456d6fc31a43676f3e05cc6ecebde31d562ccfc Mon Sep 17 00:00:00 2001 From: blikblum Date: Tue, 10 Aug 2010 16:52:59 +0000 Subject: [PATCH] wince: avoid sending LM_CHANGE message when clearing TRadioButton siblings and when setting TRadioButton checked property programatically. Send LM_CHANGE when TRadioButton is unchecked. Don't toggle TRadioButton state when it's already checked. Part of 0017139 and 0017104 git-svn-id: trunk@27051 - --- lcl/interfaces/wince/wincecallback.inc | 64 +++++++++++++++---------- lcl/interfaces/wince/wincewsstdctrls.pp | 3 +- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/lcl/interfaces/wince/wincecallback.inc b/lcl/interfaces/wince/wincecallback.inc index 348c6c6658..e6d2017ad5 100644 --- a/lcl/interfaces/wince/wincecallback.inc +++ b/lcl/interfaces/wince/wincecallback.inc @@ -544,15 +544,22 @@ Var var Parent: TWinControl; Sibling: TControl; + WinControl: TWinControlAccess absolute Sibling; + PreviousCheckState: LRESULT; i: Integer; begin Parent := RadioButton.Parent; - for i:= 0 to Parent.ControlCount - 1 do begin + for i:= 0 to Parent.ControlCount - 1 do + begin Sibling := Parent.Controls[i]; - if (Sibling is TRadioButton) and (Sibling<>RadioButton) and - (TRadioButton(Sibling).HandleAllocated) then - Windows.SendMessageW(TRadioButton(Sibling).Handle, BM_SETCHECK, - Windows.WParam(BST_UNCHECKED), 0); + if (Sibling is TRadioButton) and (Sibling <> RadioButton) then + begin + // Pass previous state through LParam so the event handling can decide + // when to propagate LM_CHANGE (New State <> Previous State) + PreviousCheckState := Windows.SendMessage(WinControl.WindowHandle, BM_GETCHECK, 0, 0); + Windows.SendMessage(WinControl.WindowHandle, BM_SETCHECK, + Windows.WParam(BST_UNCHECKED), Windows.LParam(PreviousCheckState)); + end; end; end; @@ -1053,10 +1060,6 @@ begin end; end; end; - BM_SETCHECK: - begin - LMessage.Msg := LM_CHANGED; - end; WM_CAPTURECHANGED: begin LMessage.Msg := LM_CAPTURECHANGED; @@ -1160,18 +1163,22 @@ begin // in checkboxes (needed by dbcheckbox for null fields) we need // to handle checkbox state ourselves, according to msdn state // sequence goes from checked->cleared->grayed etc. - Flags := SendMessageW(lWinControl.Handle, BM_GETCHECK, 0, 0); - if (Flags=BST_CHECKED) then - Flags := BST_UNCHECKED - else - if (Flags=BST_UNCHECKED) and - TCustomCheckbox(lWinControl).AllowGrayed then - Flags := BST_INDETERMINATE - else - Flags := BST_CHECKED; - Windows.SendMessageW(lWinControl.Handle, BM_SETCHECK, - Windows.WPARAM(flags), 0); - + Flags := SendMessage(lWinControl.Handle, BM_GETCHECK, 0, 0); + //dont update the check state if is TRadioButton and is already checked + if (Flags <> BST_CHECKED) or not (lWinControl is TRadioButton) then + begin + if (Flags=BST_CHECKED) then + Flags := BST_UNCHECKED + else + if (Flags=BST_UNCHECKED) and + TCustomCheckbox(lWinControl).AllowGrayed then + Flags := BST_INDETERMINATE + else + Flags := BST_CHECKED; + //pass a different values in WParam and WParam to force sending LM_CHANGE + Windows.SendMessage(lWinControl.Handle, BM_SETCHECK, + Windows.WPARAM(Flags), Windows.LPARAM(Flags + 1)); + end; LMessage.Msg := LM_CLICKED; end; BN_KILLFOCUS: @@ -1847,9 +1854,6 @@ begin LMessage.Msg := LM_SETFOCUS; if (lWinControl <> nil) and (lWinControl.FCompStyle = csEdit) then Windows.SendMessage(Window, EM_SETSEL, 0, -1); - // RadioButton functionality - if (lWinControl <> nil) and (lWinControl is TRadioButton) then - Windows.SendMessage(Window, BM_SETCHECK, BST_CHECKED, 0); end; WM_SHOWWINDOW: begin @@ -2083,8 +2087,16 @@ begin end; BM_SETCHECK: begin - if (WParam=BST_CHECKED) and (lWinControl is TRadioButton) then - ClearSiblingRadioButtons(TRadioButton(lWinControl)); + //LParam holds previous state + //Propagate LM_CHANGED when state is changed + if LParam <> WParam then + LMessage.Msg := LM_CHANGED; + if lWinControl is TRadioButton then + begin + //Uncheck siblings + if WParam = BST_CHECKED then + ClearSiblingRadioButtons(TRadioButton(lWinControl)); + end; end; //roozbeh : dont have these on ce! diff --git a/lcl/interfaces/wince/wincewsstdctrls.pp b/lcl/interfaces/wince/wincewsstdctrls.pp index eeadb56b27..ded7c5d2a1 100644 --- a/lcl/interfaces/wince/wincewsstdctrls.pp +++ b/lcl/interfaces/wince/wincewsstdctrls.pp @@ -1330,7 +1330,8 @@ begin else Flags := Windows.WParam(BST_INDETERMINATE); end; - Windows.SendMessage(ACustomCheckBox.Handle, BM_SETCHECK, Flags, 0); + //Pass the same state through lParam to avoid the OnChange event be fired + Windows.SendMessage(ACustomCheckBox.Handle, BM_SETCHECK, Flags, LPARAM(Flags)); end; { TWinCEWSToggleBox }