Page 1 of 1
How to prevent #PB_EventType_LeftClick msg at dblclick?
Posted: Tue Aug 11, 2009 3:52 pm
by dige
If you click on the image gadget once, you'll get an
#PB_EventType_LeftClick .. thats good.
But if you doubleclick on theimage gadget, you'll get
#PB_EventType_LeftClick and #PB_EventType_LeftDoubleClick.
How to prevent that #PB_EventType_LeftClick first?
Code: Select all
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Image_0
#ListView_1
EndEnumeration
;}
;{ Images
Enumeration
#Image_Image_0
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 450, 200, 400, 181, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
If CreateGadgetList(WindowID(#Window_0))
ImageGadget(#Image_0, 13, 14, 180, 158, 0, #PB_Image_Border)
ListViewGadget(#ListView_1, 211, 15, 151, 158)
EndIf
EndIf
EndProcedure
CreateImage(0, 180, 158)
OpenWindow_Window_0()
;{- Event loop
Repeat
Event = WaitWindowEvent()
Select Event
; ///////////////////
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #Image_0
If EventType = #PB_EventType_LeftClick
AddGadgetItem(#ListView_1, -1, "Left Click :-(")
ElseIf EventType = #PB_EventType_LeftDoubleClick
AddGadgetItem(#ListView_1, -1, "Left Double Click :-)")
EndIf
ElseIf EventGadget = #ListView_1
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
Break
EndIf
EndSelect
ForEver
;
;}
Posted: Tue Aug 11, 2009 4:56 pm
by rsts
I think this has been discussed before.
There are ways to ignore the singleclick, but I'm not sure we want to do away with it.
http://www.purebasic.fr/english/viewtop ... 81&start=3 - also has a link to an alternate
I actually have code that depends on it
cheers
Posted: Tue Aug 11, 2009 5:02 pm
by AND51
LOL...
You write
Code: Select all
If EventType = #PB_EventType_LeftClick
AddGadgetItem(#ListView_1, -1, "Left Click :-(")
ElseIf EventType = #PB_EventType_LeftDoubleClick
AddGadgetItem(#ListView_1, -1, "Left Double Click :-)")
EndIf
But you could change the order for logical reasons. Try this
Code: Select all
If EventType = #PB_EventType_LeftDoubleClick
AddGadgetItem(#ListView_1, -1, "Left Doueble Click :-)")
ElseIf EventType = #PB_EventType_LeftClick
AddGadgetItem(#ListView_1, -1, "Left Click Only :-)")
EndIf
This is just an idea.
Posted: Tue Aug 11, 2009 6:22 pm
by cas
AND51 wrote:This is just an idea.
You commented your own idea even before you said it, here it is :
AND51 wrote:LOL...
This is epic LOL
If you doubleclick on gadget then WaitWindowEvent() will return two times, first time left click and second time double click because in reality you actually click two times (two left clicks), and OS calculates time passed from last click to generate doubleclick event if you clicked fast enough second time, so no matter how you arrange your cases, they both will be processed.
There is probably no other way than coding custom timer calculation to check for doubleclick...
Here is my quick attempt, it is not perfect, feel free to enhance it
Code: Select all
EnableExplicit
Global SysDoubleClickDelayMs = 500 ; According to Microsoft's MSDN website, the default timing in Windows is 500ms; change this value with some api which returns current sys doubleclick interval in milliseconds because users can edit this value in Control Panel
Global LastTimeOfLeftClick=-1
Global LeftClickOnlyProcessed=#True
Global lastMousePos_x=0
Global lastMousePos_y=0
Global currMousePos_x=0
Global currMousePos_y=0
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Image_0
#ListView_1
EndEnumeration
;}
;{ Images
Enumeration
#Image_Image_0
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure CheckClick(void)
Repeat
If LastTimeOfLeftClick<>-1
If (ElapsedMilliseconds()-LastTimeOfLeftClick)>SysDoubleClickDelayMs
LeftClickOnlyProcessed=#False
Repeat : Delay(1) : Until LeftClickOnlyProcessed=#True
EndIf
EndIf
Delay(1)
ForEver
EndProcedure
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 450, 200, 400, 181, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
;If CreateGadgetList(WindowID(#Window_0))
ImageGadget(#Image_0, 13, 14, 180, 158, 0, #PB_Image_Border)
CreateThread(@CheckClick(),0)
ListViewGadget(#ListView_1, 211, 15, 151, 158)
;EndIf
EndIf
EndProcedure
CreateImage(0, 180, 158)
OpenWindow_Window_0()
;{- Event loop
Repeat
Event = WaitWindowEvent(1)
If Event=0
If LeftClickOnlyProcessed=#False
Event=#PB_Event_Gadget
EventGadget = #Image_0
EventType = #PB_EventType_LeftClick
Else
Continue
EndIf
EndIf
Select Event
; ///////////////////
Case #PB_Event_Gadget
If LeftClickOnlyProcessed=#True
EventGadget = EventGadget()
EventType = EventType()
EndIf
If EventGadget = #Image_0
If EventType = #PB_EventType_LeftClick
currMousePos_x=WindowMouseX(#Window_0)
currMousePos_y= WindowMouseY(#Window_0)
If (currMousePos_x<>lastMousePos_x) Or (currMousePos_y<>lastMousePos_y)
If LastTimeOfLeftClick<>-1
LeftClickOnlyProcessed=#False
EndIf
EndIf
lastMousePos_x=currMousePos_x
lastMousePos_y=currMousePos_y
LastTimeOfLeftClick=ElapsedMilliseconds()
If LeftClickOnlyProcessed=#False
AddGadgetItem(#ListView_1, -1, "Left Click :-(")
LeftClickOnlyProcessed=#True
LastTimeOfLeftClick=-1
EndIf
ElseIf EventType = #PB_EventType_LeftDoubleClick
LastTimeOfLeftClick=-1
AddGadgetItem(#ListView_1, -1, "Left Double Click :-)")
LeftClickOnlyProcessed=#True
EndIf
ElseIf EventGadget = #ListView_1
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
Break
EndIf
EndSelect
ForEver
;
;}
Posted: Tue Aug 11, 2009 8:06 pm
by Arctic Fox
cas wrote:According to Microsoft's MSDN website, the default timing in Windows is 500ms; change this value with some api which returns current sys doubleclick interval in milliseconds because users can edit this value in Control Panel
For those on Windows you can use
GetDoubleClickTime_()
Posted: Tue Aug 11, 2009 9:11 pm
by cas
@Arctic Fox:
Thanks, that's exactly what we need here.
Posted: Wed Aug 12, 2009 8:18 am
by dige
Thank you all! Here is my solution, mixed and optimized all
suggestions (cas, netmeastro)
Code: Select all
Enumeration
#Window_0
EndEnumeration
Enumeration
#Image_0
#ListView_1
EndEnumeration
Enumeration
#Image_Image_0
EndEnumeration
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
Procedure.i CheckDoubleClick ( EventGadgetID.i, EventType.i )
Protected TimeOut.i
If EventType = #PB_EventType_LeftClick
TimeOut = ElapsedMilliseconds() + (GetDoubleClickTime_()*2/3)
Repeat
If WaitWindowEvent(10) = #PB_Event_Gadget And EventGadget() = EventGadget
If EventType() = #PB_EventType_LeftDoubleClick
EventType = #PB_EventType_LeftDoubleClick
Break
EndIf
EndIf
Until ElapsedMilliseconds() > TimeOut
EndIf
ProcedureReturn EventType
EndProcedure
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 450, 200, 400, 181, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
ImageGadget(#Image_0, 13, 14, 180, 158, 0, #PB_Image_Border)
ListViewGadget(#ListView_1, 211, 15, 151, 158)
EndIf
EndProcedure
CreateImage(0, 180, 158)
OpenWindow_Window_0()
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = #Image_0
EventType = EventType()
Select EventType
Case #PB_EventType_LeftDoubleClick, #PB_EventType_LeftClick
EventType = CheckDoubleClick( #Image_0, EventType )
Select EventType
Case #PB_EventType_LeftDoubleClick
AddGadgetItem(#ListView_1, -1, "Left Double Click")
Case #PB_EventType_LeftClick
AddGadgetItem(#ListView_1, -1, "Left Click")
EndSelect
EndSelect
ElseIf Event = #PB_Event_CloseWindow
Break
EndIf
ForEver
Re: How to prevent #PB_EventType_LeftClick msg at dblclick?
Posted: Tue Jan 12, 2010 4:30 pm
by yrreti
Thanks dije

I was beginning to pull my hair out on this problem, until I found
your example, which works really nice. I really like how you isolated the
Left Clicks and setup the CheckDoubleClick decode procedure.
Good job!
Thanks again
Re: How to prevent #PB_EventType_LeftClick msg at dblclick?
Posted: Wed Jan 13, 2010 9:06 am
by ozzie
Yes, that could be useful.
