Menu annoyance

Discussions related to mouse, keyboard, fonts and Graphical User Interface
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Menu annoyance

Post by KenDown »

With dear old RISC-OS, if you clicked on a menu item, it was a menu item and nothing but a menu item. With Windows it seems that if you click on a menu item, although the menu item is actioned, the click also gets transferred through to the main program and is interpreted as if it was a click on the program window.

For example, I have a screen which is divided up into squares and clicking on one of the squares produces a certain action. However there is a line of menu items along the top of the screen, click on one and a drop-down menu comes down over the screen. Click on a menu item and although that menu item is selected and does what it is supposed to do, the square underneath that menu item is *also* selected and does what it is supposed to do, even though I do not want that square to be selected or actioned.

Is there any way of confining clicks on menu items to the menu items and not to the underlying screen? Thanks.
Hated Moron

Re: Menu annoyance

Post by Hated Moron »

KenDown wrote: Thu 06 Oct 2022, 21:53 With Windows it seems that if you click on a menu item, although the menu item is actioned, the click also gets transferred through to the main program and is interpreted as if it was a click on the program window.
I don't believe that is true at all. In Windows, mouse clicks are sent only to the window which currently has the 'input focus', in just the same way as keyboard input is. They are never sent to two different windows. The true cause of the symptom you describe is almost certainly a bug in your own code.

One possibility is a classic programming error (and one which has been discussed here before): confusing a mouse event (signalled by ON MOUSE) with the mouse state (as indicated by the MOUSE statement). Events and states are fundamentally different things; notably whilst a mouse event (such as a click) is sent only to the window which has focus, the mouse state is global and can be sampled anywhere.

So check your code to make sure that if you are trying to receive mouse clicks you are doing so using ON MOUSE, not MOUSE (you may wish to use MOUSE to discover the coordinates, but only after ON MOUSE has told you that a click occurred).

I should add that Windows, along with all other modern Operating Systems, expects programs to be event driven. That is, they should ideally not 'poll' but wait for an event before taking any action. BASIC is not well suited to event-driven programming, and you may well find that you have to resort to polling sometimes, but it should be avoided when possible.
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: Menu annoyance

Post by KenDown »

Hah!

You are, of course, correct. I was using MOUSE and the problem vanished as soon as I used ON MOUSE. Mind you, that threw up another problem. ON MOUSE, so long as it was over the window, called PROCxyz but inside PROCxyz were routines to deal with further mouse actions - but as soon as I clicked again to initiate those actions, ON MOUSE sent me back to the start of PROCxyz! I had to use ON MOUSE LOCAL OFF at the start of PROCxyz so that further mouse actions could proceeed - if you'll excuse the pun - uninterruptedly.

It works, but I imagine it is such a klutzy way of doing things that you are tearing your hair out and rolling your eyes in frustration. Sorry.
Hated Moron

Re: Menu annoyance

Post by Hated Moron »

KenDown wrote: Fri 07 Oct 2022, 05:31 I had to use ON MOUSE LOCAL OFF at the start of PROCxyz so that further mouse actions could proceeed
You chose to use ON MOVE LOCAL OFF, you didn't have to. There would have been other, probably better, ways of dealing with the issue, which would have arisen in much the same way in any language that supports 'interrupts'. It's what's called programming and it isn't always easy!

If you prefer the RISC OS way of doing things, which is to use polling for absolutely everything (it's not even a pre-emptive multi-tasking system) then simply set a global variable in the ON MOUSE interrupt and poll it:

Code: Select all

      ON MOUSE MouseClicked = TRUE : RETURN
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: Menu annoyance

Post by KenDown »

A fair enough point about choosing - and I agree that programming is not always easy, but isn't it fun!

I shall no doubt continue to look for better ways, but I needed to get the program back up and running and this seems to work.