Custom button taking left click event from other controls? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
USB3pt0
Earned a small fee
Earned a small fee
Posts: 18
Joined: Mon May 04, 2020 3:03 pm

Custom button taking left click event from other controls?

Post by USB3pt0 »

Hi,

A while ago I posted about creating custom buttons and was pointed to this. While it has worked perfectly so far and with the addition of the following code to its mouseReleased function:

Code: Select all

wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
evt.SetEventObject(this);
HandleWindowEvent(evt);
handles the command event for when it's clicked. But because it's on release, if a dialog is popped up in front of where the user clicked, any buttons at that position are also clicked instantly. For example, I have a wxTextCtrl that, when clicked on, brings up an on-screen keyboard. If a key is directly at the point where the mouse clicked the control, it will activate and enter a key erroneously.

I tried putting it in mouseDown, which changes it so the buttons are instantly clicked, but this causes a sizeable delay in pressing the same button multiple times if the mouse does not move at all. It also causes some other slightly undesired functionality as the user cannot hold the click and move their cursor off it to cancel.

Is there a way to make it so it the button won't be activated by clicking on another control? If not, as the intended device has a resistive touch screen, I can have the code in the mouseDown function.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Custom button taking left click event from other controls?

Post by doublemax »

Set a flag on mouse down. Clear the flag on mouse leave. If you get a mouse up, but the flag is not set, ignore it. Then clear the flag.
Use the source, Luke!
USB3pt0
Earned a small fee
Earned a small fee
Posts: 18
Joined: Mon May 04, 2020 3:03 pm

Re: Custom button taking left click event from other controls?

Post by USB3pt0 »

Perfect, that was exactly what I was looking for.

Silly me kept trying to sleep the program, change around the events, change the mouse position programmatically...use a Boolean to block the first key entered.

Never thought to use a flag in the events...

Thanks.
Post Reply