Author |
Topic: Single/double click (Read 2628 times) |
|
Alincon
Full Member
member is offline
Posts: 147
|
|
Single/double click
« Thread started on: Nov 8th, 2015, 02:32am » |
|
Richard said: "There's an undocumented feature of LB whereby you can enable both single- and double-click events from a listbox. I do not support that in LBB, although I could."
I have a program that DOES use both single and double click events because I need to do two different things, and I didn't want to use a menu with only two choices. I hope you will support this feature in the future.
r.m.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Single/double click
« Reply #1 on: Nov 8th, 2015, 10:30am » |
|
on Nov 8th, 2015, 02:32am, Alincon wrote:I hope you will support this feature in the future. |
|
Obviously undocumented features of LB have a low priority for being emulated in LBB (most of them are bugs anyway). How did you discover that you can enable both single and double clicks? Is it documented anywhere 'official'? Has Carl acknowledged that it's a supported feature?
Richard.
|
|
Logged
|
|
|
|
SarmedNafi
Junior Member
member is offline
Posts: 93
|
|
Re: Single/double click
« Reply #2 on: Nov 8th, 2015, 2:17pm » |
|
By code:
nomainwin
for i = 1 to 10 array$(i) = str$(i) next
listbox #m.lb, array$(, [DoubleClickAction], 10, 10, 200, 200 statictext #m.txt, "Select an item or double click it.", 10, 220, 200, 40
open "test listbox event handlers" for window as #m #m "trapclose [quit]" #m.lb "singleClickSelect [SingleClickAction]" wait
[SingleClickAction] calldll #user32, "GetDoubleClickTime", delay as ulong timer delay, [continue] wait
[continue] timer 0 #m.txt "Single Click Action"; chr$(13); "Double-Click-Delay: "; delay; "ms"
' reset selection #m.lb "selectindex 0" wait
[DoubleClickAction] timer 0 #m.txt "Double Click Action"
' reset selection #m.lb "selectindex 0" wait
[quit] close #m end
'Regards
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Single/double click
« Reply #3 on: Nov 8th, 2015, 3:23pm » |
|
on Nov 8th, 2015, 2:17pm, SarmedNafi wrote: I know. But the LB docs say this:
Code:print #handle.ext, "singleclickselect"
This tells Liberty BASIC to jump to the control's branch label on a single click,
instead of the default double click. It clearly states that the singleclickselect command causes a single click to have effect instead of a double click, not as well as! That is what is implemented in LBB, and I have no plans to change it.
Richard.
|
|
|
|
SarmedNafi
Junior Member
member is offline
Posts: 93
|
|
Re: Single/double click
« Reply #4 on: Nov 8th, 2015, 4:30pm » |
|
Sorry I back home right now,
I think he see the above which works on LB but not on LBB. So he thought that LB has the ability of both events. And ask you to let LBB has the same (by modifying the code to work on LBB).
Regards,
|
|
Logged
|
|
|
|
Rod
Full Member
member is offline
Gender:
Posts: 110
|
|
Re: Single/double click
« Reply #5 on: Nov 8th, 2015, 8:18pm » |
|
You can have either a standard double click or enforce a single click. The code uses a timing trick to mimic the reading of a double click event but it is essentially using two single click events to achieve this.
So no undocumented abilities just a clever trick to differentiate user input. Problem I foresee is that you need clever users capable of understanding the difference.
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline
Posts: 147
|
|
Re: Single/double click
« Reply #6 on: Nov 8th, 2015, 9:57pm » |
|
I think using both single and double clicks is useful code, not just a 'timing trick'
And it is documented in Liberty Basic Programmer's Encyclopedia.
r.m.
|
|
Logged
|
|
|
|
SarmedNafi
Junior Member
member is offline
Posts: 93
|
|
Re: Single/double click
« Reply #7 on: Nov 9th, 2015, 02:16am » |
|
This is slow a bit but it could solve the problem. The single click of LBB took 500 ms.
WindowWidth = 482 : WindowHeight = 446 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2) for i = 1 to 10 List1$(i)= str$(i);"i";"i" next listbox #main.list1, List1$(), [SingleClick], 30, 20, 225, 345 Open "Window Title" for Window as #main #main "trapclose [quit]" #main.list1 "selectindex 1" #main "font ms_sans_serif 10" #main.list1 "singleclickselect [SingleClick]" endtime = time$("ms") what = time$("ms") - start start = time$("ms")
[loop] Wait
[SingleClick] endtime = time$("ms") what = time$("ms") - start start = time$("ms") 'print what timer 950, [c] wait [c] timer 0 if what<=900 then Goto [double] else Goto [single] wait
[single] print "single" wait
[double] print "double" wait
[quit] close #main : END
Regards
|
« Last Edit: Nov 9th, 2015, 02:17am by SarmedNafi » |
Logged
|
|
|
|
SarmedNafi
Junior Member
member is offline
Posts: 93
|
|
Re: Single/double click
« Reply #8 on: Nov 9th, 2015, 03:23am » |
|
Replace with following part will work better.
------- ------- ------ [SingleClick] endtime = time$("ms") what = time$("ms") - start start = time$("ms") 'print what timer 1250, [c] wait [c] timer 0 if what<=900 then Goto [double] if what>1000 then Goto [single] wait ------ ------ ------
Regards Sarmed
|
« Last Edit: Nov 9th, 2015, 03:26am by SarmedNafi » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Single/double click
« Reply #9 on: Nov 9th, 2015, 04:17am » |
|
In fact it appears that LB doesn't even work as it is documented to work. The docs say that sending a singleclickselect command causes the listbox to respond to a single-click instead of a double-click, and that's what I implemented in LBB. But in fact if you try it you'll find that, following that command, LB 4 responds to both a single and double click (but of course they trigger the same handler).
Note that it's not responding to two single clicks in quick succession as you might think, that's not how Windows works.
So this complicates things even more. Not only is there an undocumented feature, which is not supported in LBB, but even the documented functionality doesn't work as described so LBB isn't fully compatible with it. It's a mess.
Richard.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: Single/double click
« Reply #10 on: Nov 9th, 2015, 10:36am » |
|
Here's what has resulted on the LB board since this was posted over there, too:
Quote:Rod Global Moderator Re: singleclickselect with a branch label « Reply #6 on: Today at 02:15am » My understanding is that this is rooted in Windows protocol. Windows will issue a single click event AND a double click event if it happens in doubleclick time.
https://msdn.microsoft.com/en-us/library/ms171543(v=vs.110).aspx
So the control gets three events, a single click, another single click and then the double click. This has been the problem, there was never any point in trying for both events because the single would arrive first and always pre-empt the double.
Again, my understanding is that LB will react to single click events if enabled. If not they are just ignored and a double is needed to trigger activity. This is the default.
That is why the single click trick works in LB because it reacts to the second single click event that windows issues just ahead of the double. The double is ignored in this case. |
|
|
« Last Edit: Nov 9th, 2015, 10:37am by joker » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Single/double click
« Reply #11 on: Nov 9th, 2015, 11:21am » |
|
on Nov 9th, 2015, 10:36am, pnlawrence wrote:Rod: "Windows will issue a single click event AND a double click event if it happens in doubleclick time". |
|
Yes, if both single-click and double-click events are enabled, with any control, a double-click event will always be accompanied by a preceding single-click event. Since the default double-click time is 500ms you would have to wait at least that long to find out which kind of event it really is, which is clunky and not user-friendly.
So in practice the only way you can sensibly use both events on the same control is when it doesn't matter that a 'spurious' single-click event accompanies every double-click. In other words the action that results from a single-click must be something fairly 'innocuous', or that can be later 'undone'.
It would be interesting to learn from Alincon what a single-click event does in his application, and why it doesn't matter that an extra event accompanies every double-click.
Quote:Rod: "This has been the problem, there was never any point in trying for both events". |
|
I wouldn't say "never" but certainly the issue discussed above, plus the fact that very few LB users know it is possible (and fewer still actually use the feature) makes me even more disinclined to support it in LBB.
Arguably, however, I ought sometime to modify LBB so that at least it works the same way as LB in the 'normal' singleclickselect mode, which is to activate the handler on both single and double clicks. That would be easy, involving actually removing code!
Richard.
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: Single/double click
« Reply #12 on: Nov 9th, 2015, 12:40pm » |
|
I knew you would get to the nitty-gritty.
Since getting into the GUI side of Windows only recently, I'm still amazed at how little can get done with so much code.
This double/single click thing is a good example of that.
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline
Posts: 147
|
|
Re: Single/double click
« Reply #13 on: Nov 9th, 2015, 2:24pm » |
|
I don't know nothin 'bout milliseconds and extra clicks or documented or undocumented.
All I know is that when I singleclick on my listbox entry one thing happens and when I doubleclick on the same entry something else happens.
Of course, that's in LB. In LBB I only get one action, which I do not like.
r.m.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Single/double click
« Reply #14 on: Nov 9th, 2015, 2:40pm » |
|
on Nov 9th, 2015, 2:24pm, Alincon wrote:All I know is that when I singleclick on my listbox entry one thing happens and when I doubleclick on the same entry something else happens. |
|
I don't think so. Unless I've completely misunderstood how Windows works, when you singleclick one thing happens and when you doubleclick both things happen! That's the point Rod was making: you unavoidably get a 'spurious' single click event with every double-click.
My question was, how do you deal with that in your program? Does it just happen to be the case that the 'unwanted' single-click event doesn't matter?
Quote:Of course, that's in LB. In LBB I only get one action, which I do not like. |
|
I know this isn't helpful, but you (presumably) knew when you wrote your program that you were relying on undocumented behaviour. So you shouldn't be too upset to find it doesn't work in LBB.
If you can explain how your application responds to the two different user actions we may be able to suggest an alternative mode of operation that requires only one.
Richard.
|
|
Logged
|
|
|
|
|