Call contextualmenu on touch devices

Hi all!
How can I call the contextualmenu (right click) on tablets and smartphones?

Many thanks!

[quote=63070:@Oliver Scott-Brown]I believe it is standard to tap and hold for contextualmenus on touch devices. If you run Windows 7 on your tablet and AFAIK on Windows 8 (I doubt you would run them on on a smart phone, in most cases). This question is a little vague as to what you are trying to achieve. I cannot deny I do this to. ;| So please specify. Am I suppose to presume you are trying to achieve this with iOS? If so, this might be helpful https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/EditMenu.html

HSP[/quote]
************IGNORE ABOVE
I believe it is standard to tap and hold for contextualmenus on touch devices. If you run Windows 7 on your tablet and AFAIK on Windows 8 (I doubt you would run them on on a smart phone, in most cases), I believe you tap and hold and tap somewhere or something, I have brought this up in another thread. This question is a little vague as to what you are trying to achieve. I cannot deny I do this to. ;| So please specify. Am I suppose to presume you are trying to achieve this with iOS? If so, this might be helpful https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/EditMenu.html

I have found the thread:
https://forum.xojo.com/5834-right-click-on-touchscreen

HSP

Thanks Oliver. My needs was to open a contextual menu on right-click on a weblistbox, and it works, but it doesn’t work on iPad and iPhone. For now I use a work-around: under the listbox i put a button that contains mylistbox.presentcontextualmenu.

If anyone has another solution, is welcome.

Sorry if I don’t explained well my problem.

Right now Xojo does not support contextual clicks in iPads and other devices. I have had a feedback request open for quite some time:

<https://xojo.com/issue/19175>

Please sign on to this. I have wanted it. Instead, I have had to create custom menus that on Tablets, have an additional sub-menu that basically does what the contextual menu did. It gets dicey too on iPhones, as there is no screen room to bring up the sub-menu so I have to load a separate page on the iPhone.

It’s a pain and I wish Xojo would add support for it.

If only it was possible to get the length of a click, it would be possible to trigger a simulated right click. One possible workaround is to measure the time a click took between mousedown/mouseup.

  • Set a public variable to Microseconds in mousedown
  • Compare the variable to current Microseconds in mouseup.

You get the amount of time a button was clicked, so after a set amount, it is possible to show the contextual menu. It shows the contextual menu as soon as user releases the button. It does not quite work the same way as “long click” would, but it alleviates the need for an extra control.

I worked on providing a contextual menu functionality upon Long Click (replacement for right click on touch screen).Could not find a way to raise the ContextualMenuAction event but worked on simulating a contextual menu with weblistbox.

I created a listbox called ListBox1 that contains three rows, 1 column, no alternate background color, no heading, and is not visible as default.

Here is in the page Open event code that populates the listbox :

Sub Open() ListBox1.AddRow("One") ListBox1.AddRow("Two") ListBox1.AddRow("Three") End Sub

I added a window property called elapsed as integer

Sub CellClick(Row As Integer, Column As Integer) select case Row case 0 msgbox("One") case 1 msgBox("Two") case 2 msgBox("Tree") end select me.Visible = False End Sub

Because of what appears to be a bug, adding mousedown/mouseup to the window breaks Listboxes selection. So I placed a webCanvas against the whole background (could be done with other controls, for instance buttons) with the following code :

Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent) elapsed = Ticks ListBox1.visible = False End Sub

[code]Sub MouseUp(X As Integer, Y As Integer, Details As REALbasic.MouseEvent)

if ticks-elapsed >20 then
ListBox1.Left = X
ListBox1.top = Y
ListBox1.visible = True
end if
End Sub
[/code]

When user holds tap for more than 0.33 seconds and releases, the listbox appears next to the cursor and acts as a menu. Tapping on a cell triggers the option in cellclick. Here I just called MsgBox with the value selected. When user taps out of the listbox, it disappears.

I know, the appearance of this replacement for ContextualMenu is not identical to the original thing. But it may be a welcome replacement for tablets which now account for more than 30% of total web sessions, according to Google. All this pending addition of “Long Click” by Xojo, if and when this happens…

I forgot to add code to prevent the cell from remaining selected after the first menu selection. This goes into Canvas1.MouseUp :

for i as integer = 0 to 2 ListBox1.Selected(i) = false next

It is possible to get the border blue and corners round like the original WebContextualMenu with webstyle : border color 0,0,255,255 and corner 5. Apart from the bottom blue triangle, the result is not that far from the original.

Here is the menu displayed above the finger :

Sub MouseUp(X As Integer, Y As Integer, Details As REALbasic.MouseEvent) if ticks-elapsed >20 then ListBox1.Left = X-(ListBox1.Width/2) ListBox1.top = Y-ListBox1.Height-20 ListBox1.visible = True for i as integer = 0 to 2 ListBox1.Selected(i) = false next end if End Sub

Here is the MouseMove event in ListBox1 that selects items upon hover:

Sub MouseMove(X As Integer, Y As Integer, Details As REALbasic.MouseEvent) if me.visible = True then select case Y case is <29 ListBox1.Selected(0) = True ListBox1.Selected(1) = False ListBox1.Selected(2) = False case 28 to 57 ListBox1.Selected(0) = False ListBox1.Selected(1) = True ListBox1.Selected(2) = False case is > 56 ListBox1.Selected(0) = False ListBox1.Selected(1) = False ListBox1.Selected(2) = True end select end if End Sub

This was a quick work to demonstrate long click. I just wanted to see if I could get something to work. It is still possible to polish the result, for instance by adding an imageWell under the listbox that contains the blue triangle picture. But basically, this workaround adds longclick contextual menu. I believe the same technique could be applied to desktop under Windows, as more and more PCs now come with touchscreen, and may not generate right click upon Long Click. Already, VB has the Tap and Right Tap events, which are clearly targeted towards touchscreen . Here is now long tap for Xojo.

Xojo iOS will probably address touchscreen fully, but in the meantime, I hope this work will enable web to better respond to touch screen devices :wink:

Michael, I’ll try what you suggest soon… And I’ll let you know if it’s nice for me (but seems very nice)…
Thanks for now.

[quote=68437:@Sergio Tamborini]Michael, I’ll try what you suggest soon… And I’ll let you know if it’s nice for me (but seems very nice)…
Thanks for now.[/quote]

Just a detail I left out : the listbox used for the menu must be high enough so no scroll bar will show. From what I gathered, allow one empty row more than the menu items.

You can download my sample project here : . I have even added the small triangle under the menu :slight_smile: