summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-10-25 14:53:44 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-10-25 14:53:44 +0200
commitbf8a6f279217408bd21b9bfbadd8416c2b850cb8 (patch)
tree86b1b842de8d6de71ffe1b9c0280233d96dedbfe
parentd1b0ae55c3a2a70737f298a61952bacb2d8a021e (diff)
downloadfpGUI-bf8a6f279217408bd21b9bfbadd8416c2b850cb8.tar.xz
Improved event firing of OnDoubleClick and OnClick
* Single click produces one OnClick event * On a Double Click in produces a OnClick, then a OnDoubleClick event. Old behaviour used to procuder yet another OnClick at the end. This is not needed. * OnMouseDown and OnMouseUp events behaviour has not changed. The reason we introduce the FOnClickPending instead of fully handling the events in TfpgWidget.MsgMouseUp is because a TfpgButton has slightly different behavior (eg: When clicking on a button, keep mouse down, and move mouse out of button rectangle, then an OnClick must not fire.) The extra FOnClickPending allows us to toggle this behaviour of HandleLButtonUp (which normally fires the OnClick event)
-rw-r--r--src/corelib/fpg_widget.pas7
-rw-r--r--src/gui/fpg_button.pas11
2 files changed, 12 insertions, 6 deletions
diff --git a/src/corelib/fpg_widget.pas b/src/corelib/fpg_widget.pas
index f0c7f514..2afb667a 100644
--- a/src/corelib/fpg_widget.pas
+++ b/src/corelib/fpg_widget.pas
@@ -99,6 +99,7 @@ type
FBackgroundColor: TfpgColor;
FTextColor: TfpgColor;
FIsContainer: Boolean;
+ FOnClickPending: Boolean;
procedure SetAcceptDrops(const AValue: boolean); virtual;
function GetOnShowHint: THintEvent; virtual;
procedure SetOnShowHint(const AValue: THintEvent); virtual;
@@ -470,6 +471,7 @@ begin
FTextColor := clText1;
FAcceptDrops := False;
FDragActive := False;
+ FOnClickPending := False;
inherited Create(AOwner);
@@ -670,6 +672,7 @@ begin
case msg.Params.mouse.Buttons of
MOUSE_LEFT:
begin
+ FOnClickPending := True;
mb := mbLeft;
if uLastClickWidget = self then
IsDblClick := ((fpgGetTickCount - uLastClickTime) <= DOUBLECLICK_MS)
@@ -683,7 +686,7 @@ begin
uLastClickTime := fpgGetTickCount;
if IsDblClick then
begin
-
+ FOnClickPending := False; { When Double Click occurs we don't want single click }
HandleDoubleClick(msg.Params.mouse.x, msg.Params.mouse.y, msg.Params.mouse.Buttons, msg.Params.mouse.shiftstate);
if Assigned(FOnDoubleClick) then
FOnDoubleClick(self, mb, msg.Params.mouse.shiftstate,
@@ -1032,7 +1035,7 @@ end;
procedure TfpgWidget.HandleLMouseUp(x, y: integer; shiftstate: TShiftState);
begin
- if Assigned(FOnClick) then
+ if FOnClickPending and Assigned(FOnClick) then
FOnClick(self);
end;
diff --git a/src/gui/fpg_button.pas b/src/gui/fpg_button.pas
index fbca006f..cc9866c3 100644
--- a/src/gui/fpg_button.pas
+++ b/src/gui/fpg_button.pas
@@ -664,7 +664,7 @@ begin
FDown := False;
RePaint;
fpgApplication.ProcessMessages;
- if PtInRect(r, Point(x, y)) then
+ if PtInRect(r, Point(x, y)) and FOnClickPending then
Click;
end;
end
@@ -675,7 +675,7 @@ begin
FDown := False;
RePaint;
fpgApplication.ProcessMessages;
- if PtInRect(r, Point(x, y)) then
+ if PtInRect(r, Point(x, y)) and FOnClickPending then
Click;
end;
end;
@@ -785,8 +785,11 @@ begin
if Assigned(FCommand) then // ICommand takes preference to OnClick
FCommand.Execute
- else if Assigned(OnClick) then
- OnClick(self);
+ else
+ begin
+ if Assigned(OnClick) then
+ OnClick(self);
+ end;
end;
function TfpgBaseButton.GetCommand: ICommand;