lcl: TTrackBar.OnChange should be called after Position change in code, add Changed method for VCL compatibility, fix qt, gtk2 to skip message sending in case of position change through code to prevent double calling of the message (issue #0014545)

git-svn-id: trunk@25161 -
This commit is contained in:
paul 2010-05-04 04:29:27 +00:00
parent d4d220476d
commit c3564e26d8
6 changed files with 27 additions and 7 deletions

View File

@ -1840,6 +1840,7 @@ type
protected protected
class procedure WSRegisterClass; override; class procedure WSRegisterClass; override;
procedure ApplyChanges; procedure ApplyChanges;
procedure Changed; virtual;
procedure DoChange(var msg); message LM_CHANGED; procedure DoChange(var msg); message LM_CHANGED;
procedure FixParams(var APosition, AMin, AMax: Integer); procedure FixParams(var APosition, AMin, AMax: Integer);
class function GetControlClassDefaultSize: TPoint; override; class function GetControlClassDefaultSize: TPoint; override;

View File

@ -466,9 +466,8 @@ begin
// only fire event if reason is not some other window hide/showing etc. // only fire event if reason is not some other window hide/showing etc.
if Message.Status = 0 then if Message.Status = 0 then
begin begin
if Message.Show then begin if Message.Show then
DoShowWindow; DoShowWindow;
end;
end; end;
finally finally
Exclude(FFormState, fsShowing); Exclude(FFormState, fsShowing);

View File

@ -174,6 +174,7 @@ begin
FPosition := Value; FPosition := Value;
if HandleAllocated then if HandleAllocated then
TWSTrackBarClass(WidgetSetClass).SetPosition(Self, FPosition); TWSTrackBarClass(WidgetSetClass).SetPosition(Self, FPosition);
Changed;
end; end;
end; end;
@ -311,6 +312,12 @@ begin
TWSTrackBarClass(WidgetSetClass).ApplyChanges(Self); TWSTrackBarClass(WidgetSetClass).ApplyChanges(Self);
end; end;
procedure TCustomTrackBar.Changed;
begin
if Assigned (FOnChange) then
FOnChange(Self);
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCustomTrackBar.DoChange Method: TCustomTrackBar.DoChange
Params: Msg (longint = LM_CHANGE) Params: Msg (longint = LM_CHANGE)
@ -325,8 +332,7 @@ begin
if [csLoading,csDestroying,csDesigning]*ComponentState<>[] then if [csLoading,csDestroying,csDesigning]*ComponentState<>[] then
Exit; Exit;
EditingDone; EditingDone;
if Assigned (FOnChange) then Changed;
FOnChange(Self);
end; end;
procedure TCustomTrackBar.FixParams(var APosition, AMin, AMax: Integer); procedure TCustomTrackBar.FixParams(var APosition, AMin, AMax: Integer);

View File

@ -2283,7 +2283,6 @@ var
begin begin
Result := CallBackDefaultReturn; Result := CallBackDefaultReturn;
EventTrace('Value changed', data); EventTrace('Value changed', data);
if (Widget=nil) then ;
Mess.msg := LM_CHANGED; Mess.msg := LM_CHANGED;
DeliverMessage(Data, Mess); DeliverMessage(Data, Mess);
end; end;

View File

@ -247,13 +247,22 @@ end;
{$I gtk2wscustomlistview.inc} {$I gtk2wscustomlistview.inc}
procedure GtkWSTrackBar_Changed(AWidget: PGtkWidget; AInfo: PWidgetInfo); cdecl;
var
Msg: TLMessage;
begin
if AInfo^.ChangeLock > 0 then Exit;
Msg.Msg := LM_CHANGED;
DeliverMessage(AInfo^.LCLObject, Msg);
end;
{ TGtk2WSTrackBar } { TGtk2WSTrackBar }
class procedure TGtk2WSTrackBar.SetCallbacks(const AWidget: PGtkWidget; class procedure TGtk2WSTrackBar.SetCallbacks(const AWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo); const AWidgetInfo: PWidgetInfo);
begin begin
TGtk2WSWinControl.SetCallbacks(PGtkObject(AWidget), TComponent(AWidgetInfo^.LCLObject)); TGtk2WSWinControl.SetCallbacks(PGtkObject(AWidget), TComponent(AWidgetInfo^.LCLObject));
TGtk2Widgetset(WidgetSet).SetCallback(LM_CHANGED, PGtkObject(AWidget), AWidgetInfo^.LCLObject); SignalConnect(AWidget, 'value_changed', @GtkWSTrackBar_Changed, AWidgetInfo);
end; end;
class function TGtk2WSTrackBar.CreateHandle(const AWinControl: TWinControl; class function TGtk2WSTrackBar.CreateHandle(const AWinControl: TWinControl;
@ -348,11 +357,17 @@ class procedure TGtk2WSTrackBar.SetPosition(const ATrackBar: TCustomTrackBar;
const NewPosition: integer); const NewPosition: integer);
var var
Range: PGtkRange; Range: PGtkRange;
WidgetInfo: PWidgetInfo;
begin begin
if not WSCheckHandleAllocated(ATrackBar, 'SetPosition') then if not WSCheckHandleAllocated(ATrackBar, 'SetPosition') then
Exit; Exit;
Range := PGtkRange(ATrackBar.Handle); Range := PGtkRange(ATrackBar.Handle);
WidgetInfo := GetWidgetInfo(Range);
// lock Range, so that no OnChange event is not fired
Inc(WidgetInfo^.ChangeLock);
gtk_range_set_value(Range, NewPosition); gtk_range_set_value(Range, NewPosition);
// unlock Range
Dec(WidgetInfo^.ChangeLock);
end; end;
{ TGtk2WSProgressBar } { TGtk2WSProgressBar }

View File

@ -5760,7 +5760,7 @@ begin
writeln('TQtTrackBar.SlotValueChanged()'); writeln('TQtTrackBar.SlotValueChanged()');
{$endif} {$endif}
if not SliderPressed and not InUpdate then if not SliderPressed and (TTrackBar(LCLObject).Position <> p1) and not InUpdate then
begin begin
FillChar(Msg, SizeOf(Msg), #0); FillChar(Msg, SizeOf(Msg), #0);
Msg.Msg := LM_CHANGED; Msg.Msg := LM_CHANGED;