Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in switch when case has wxMessageBox() #24463

Open
fmc-coder opened this issue Apr 10, 2024 · 3 comments
Open

Bug in switch when case has wxMessageBox() #24463

fmc-coder opened this issue Apr 10, 2024 · 3 comments
Labels
GTK repro needed A way to reproduce the problem is required

Comments

@fmc-coder
Copy link

fmc-coder commented Apr 10, 2024

In my first attempt at trying to catch keys, I think I found a bug. The first time I ran it, I had success catching the Tab key, which only popped up a message box to show the code worked. So, I got greedy and tried to catch both the Alt and the Ctrl keys. Here's what that code looked like:
Bind(wxEVT_CHAR_HOOK, &MyFrame::OnChar, this);

void MyFrame::OnChar(wxKeyEvent &event){
switch ( event.GetKeyCode() ) { case WXK_TAB: wxMessageBox("Tab key");break; case WXK_ALT: wxMessageBox("Alt key");break; case WXK_CONTROL: wxMessageBox("Ctrl key");break; } }

Without being too long-winded, hitting either the Alt key or Ctrl key made the switch statement loop through their respective wxMessageBoxes() 4 times. Without fail.

Linux Mint 21.3
wxWidgets-3.2.4

@vadz
Copy link
Contributor

vadz commented Apr 10, 2024

Please provide a way of reproducing the problem in a sample. With this diff:

diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 5f32257c6b..751de45266 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -175,6 +175,11 @@ MyFrame::MyFrame(const wxString& title)
     CreateStatusBar(2);
     SetStatusText("Welcome to wxWidgets!");
 #endif // wxUSE_STATUSBAR
+
+    auto p = new wxPanel(this);
+    p->Bind(wxEVT_CHAR_HOOK, [](wxKeyEvent& event) {
+        wxLogMessage("Char hook: %d", event.GetKeyCode());
+    });
 }
 

I don't see anything wrong, i.e. pressing either Alt or Ctrl results in just one message, as expected.

Also note that you should call event.Skip() for this event in your event handler unless you really want to prevent the default handling from taking place.

@vadz vadz added GTK repro needed A way to reproduce the problem is required labels Apr 10, 2024
@fmc-coder
Copy link
Author

I do use event.skip().

The code i showed you used wxMessageBox(), not wxLogMessage. I'm just trying to help you guys.

@github-actions github-actions bot removed the repro needed A way to reproduce the problem is required label Apr 10, 2024
@vadz
Copy link
Contributor

vadz commented Apr 11, 2024

I do use event.skip().

Sorry, but I have no way of knowing it if your example code doesn't show it.

The code i showed you used wxMessageBox(), not wxLogMessage.

Needless to say, I don't see the bug with the same diff using wxMessageBox() neither. You could have tried it yourself.

I'm just trying to help you guys.

Thank you, but what really helps is following our bug reporting guidelines, and notably providing a complete self-contained example reproducing the problem. Could you please make one as explained there?

@vadz vadz added the repro needed A way to reproduce the problem is required label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GTK repro needed A way to reproduce the problem is required
Projects
None yet
Development

No branches or pull requests

2 participants