What is the equivalent of isContextualClick in Xojo Web?

I would like to manage simple clicks with Pressed and right clicks with ContextualMenuSelected on the same WebCanvas: how can I do this?

You don’t use an event.
Usually you make a WebMenuItem object and attach it to the control.

See example snippets in the documentation:

Yes, and when I right-click, the Pressed event fires at the same time as the webmenu appears

I have to say, that the standard for web and web apps, is to not have/use a traditional right click like regular desktop apps. that is because webapps are expected to work on mobile devices and mobile does not have a right-click.

Yes, you can tap lightly or press and hold to access a menu.

Here is a simple example of how to do a contextual menu on a canvas. (see attached .zip file)

The gist of it is.

Add contextual menus in the canvas’ open event:

Dim menu As New WebMenuItem
menu.AddMenuItem(New WebMenuItem("I Prefer Blue"))
menu.AddMenuItem(New WebMenuItem("-"))
menu.AddMenuItem(New WebMenuItem("I like Green"))
menu.AddMenuItem(New WebMenuItem("-"))
menu.AddMenuItem(New WebMenuItem("Cancel"))

me.ContextualMenu = menu

Handle those menus in the ContextualMenuSelected event:

Select Case hitItem.Text
case "I Prefer Blue"
  self.paint_color = color.Blue
  self.Canvas1.Refresh
  
  //case insensitive apparently
  'case "I Like Green"
  'self.paint_color = color.Purple
  'self.Canvas1.Refresh
  
case "I like Green"
  self.paint_color = color.Green
  self.Canvas1.Refresh
  
Case "Cancel"
  MessageBox("Canceled!")
  
End Select

Return

contextual_click_example.xojo_binary_project.zip (8.3 KB)

HTH,
Anthony

Thanks, but I would like to handle both short taps (event Pressed) and long taps (to obtain a contextual menu).

So specifically on a mobile browser, like Mobile Safari?

Sorry, I didn’t see that mentioned in your original request.

Yes, just like with a desktop app, a simple click and a right-click are treated differently.

Today it looks like you’d have to implement this yourself with a WebSDK control or ask Xojo to implement it.

Pinging @Ricardo_Cruz to make sure this is correct, but I don’t see any way to support the long-press event without going the WebSDK route. (edit: In CURRENT versions of Xojo)

The reason there’s no IsConextualClick on web is that everything the user does on the browser Is asynchronous to the code that executes on the server. There’s no way for you to catch that click and do something special.

If a right-click is firing the pressed event when a menu is assigned, that’s a bug.

Could you please describe what you trying to do? Maybe a desktop example that helps us to think how to convert that to web?

Desktop example, in the CellClick event of a ListBox :

if IsContextualClick then

base = New MenuItem(“”) and display of the context menu

else click management

I would like to handle both short taps (event Pressed) and long taps (to obtain a contextual menu), in Xojo Web.

I think you can try to add a ContextualMenu to the WebListBox in the Opening event, and let Xojo handle the action, depending on the button pressed.

Here is a sample project:
weblistbox-contextualmenu.xojo_binary_project.zip (8.3 KB)

If you need to do something special with the main button press, you can just implement the Pressed event.

1 Like

I’ve implemented the Pressed event, please look at the result :

weblistbox-contextualmenu2.xojo_binary_project.zip (8.4 KB)

Is that what you need or are you missing something else?

On Desktop I would like to differentiate between mouse clicks and right clicks, or on a touchscreen differentiate between a simple tap and a long tap, and have different actions depending on the case, without one interfering with the other (as is the case when I right-click in the program I sent you: we get both actions at the same time, the one from Pressed and the one from ContextualMenu).

@Ricardo_Cruz - I think Marc is looking for something akin to the taphold event in JQuery Mobile.

Anthony

I’m just looking for the same thing on the xojoweb as on xojodesktop: an isContextualClick function.

Perhaps it’s not possible; I’ll check Taphold.

And I made a mistake above with “On Desktop I would like to differentiate between mouse clicks and right clicks,” I meant “On a computer screen, with a mouse, I would like to differentiate between simple clicks and right clicks”

Using the Web SDK you can achieve anything you like. Here is a code repository for a web clickable control that you can place somewhere. It’s Pressed event has a buttonIndex property you can use to check which button has been used.