Mnemonics and custom widgets

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
OibafA
In need of some credit
In need of some credit
Posts: 7
Joined: Wed Oct 07, 2020 9:35 am

Mnemonics and custom widgets

Post by OibafA » Fri May 21, 2021 10:13 am

I've got a label with a mnemonic that precedes a custom widget - just a compound widget that derives from wxPanel, nothing too fancy. See below picture.

Image

The problem is, I can't seem to get the mnemonic to work with that.

What I naively expect is for the custom widget to gain focus, but it doesn't seem to be the case.

What is the mechanism behind the mnemonics, then? How should a custom widget be made to work with them?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5150
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Mnemonics and custom widgets

Post by ONEEYEMAN » Fri May 21, 2021 4:19 pm

Hi,
As you were told on SO - can you produce the SSCE so that it can be tested?
Also - what version of wxWidgets you are using and what port?
What OS/version you are testing this on?
Which compiler did you use to build the application and how did you configure the library?

And last but not least - what do you expect to happen?
Which sub-control should get focused?

Thank you.

OibafA
In need of some credit
In need of some credit
Posts: 7
Joined: Wed Oct 07, 2020 9:35 am

Re: Mnemonics and custom widgets

Post by OibafA » Sat May 22, 2021 12:13 am

Hello,

Thanks for the reply. Didn't think it'd be necessary to post any code for my question, but here follows a minimal example of what I am talking about. It's a diff against the minimal.cpp sample program, found in the v3.0.5 branch of the repository.

Tested on Linux, with GTK3. Configure options:

Code: Select all

--enable-shared --disable-static --enable-unicode --enable-printfposparam --enable-debug --with-gtk=3
Diff against minimal.cpp:

Code: Select all

diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 135595c9fb..0507952522 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -172,6 +172,24 @@ MyFrame::MyFrame(const wxString& title)
     CreateStatusBar(2);
     SetStatusText("Welcome to wxWidgets!");
 #endif // wxUSE_STATUSBAR
+
+    wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+    
+    wxStaticText *label = new wxStaticText(this, wxID_ANY, wxS("T&est"));
+    wxPanel *panel = new wxPanel(this); {
+        wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+        wxTextCtrl *text = new wxTextCtrl(panel, wxID_ANY);
+        sizer->Add(text, wxSizerFlags(0).Expand());
+        panel->SetSizerAndFit(sizer);
+    }
+    
+    wxTextCtrl *text2 = new wxTextCtrl(this, wxID_ANY);
+    
+    sizer->Add(label, wxSizerFlags(0).Expand());
+    sizer->Add(panel, wxSizerFlags(0).Expand());
+    sizer->Add(text2, wxSizerFlags(0).Expand());
+    
+    SetSizerAndFit(sizer);
 }
What I expect is to be able to press ALT+e and have the first wxTextCtrl focused, but instead the second one gets the focus. If I remove the second one from the code, I get the following line on the console:

Code: Select all

(minimal:2409662): Gtk-WARNING **: 01:58:45.676: Couldn't find a target for a mnemonic activation.
Thanks.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5150
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Mnemonics and custom widgets

Post by ONEEYEMAN » Sat May 22, 2021 3:14 am

Hi,
OK, so you are working under Linux, right?
What is your version of GTK?
Did you build wxWidgets yourself or installed it from the repository?
If you build it - how? What is you exact configure line?

Thank you.

OibafA
In need of some credit
In need of some credit
Posts: 7
Joined: Wed Oct 07, 2020 9:35 am

Re: Mnemonics and custom widgets

Post by OibafA » Sat May 22, 2021 12:35 pm

Yes, as I wrote in the previous post, the code is being run under Linux, with the GTK3 target. The code is being linked against a locally built set of wx libraries, from the official v3.0.5 branch.

I've tested the same code on Windows as well, and I had a different set of issues. Namely, it seemed I couldn't switch focus between widgets with TAB at all, and the "OS bell" would ring any time I tried. Then I tried to use a wxPanel as root of all the other widgets, rather than putting them within the surrounding frame directly, and then the program started working as expected, but only on Windows. On Linux it still sports the same issue as before.

So the problem seems to be GTK-related? Gonna try building a GTK2 version of the libraries to see if that makes any difference.

Below, the updated code.

Code: Select all

diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 135595c9fb..89bc1dbea6 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -172,6 +172,26 @@ MyFrame::MyFrame(const wxString& title)
     CreateStatusBar(2);
     SetStatusText("Welcome to wxWidgets!");
 #endif // wxUSE_STATUSBAR
+
+    wxPanel *root = new wxPanel(this); {
+        wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+        wxStaticText *label = new wxStaticText(root, wxID_ANY, wxS("T&est"));
+        wxPanel *panel = new wxPanel(root); {
+            wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+            wxTextCtrl *text = new wxTextCtrl(panel, wxID_ANY);
+            sizer->Add(text, wxSizerFlags(0).Expand());
+            panel->SetSizerAndFit(sizer);
+        }
+
+        wxTextCtrl *text2 = new wxTextCtrl(root, wxID_ANY);
+
+        sizer->Add(label, wxSizerFlags(0).Expand());
+        sizer->Add(panel, wxSizerFlags(0).Expand());
+        sizer->Add(text2, wxSizerFlags(0).Expand());
+
+        root->SetSizerAndFit(sizer);
+    }
 }

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5150
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Mnemonics and custom widgets

Post by ONEEYEMAN » Sat May 22, 2021 1:50 pm

Hi,
What is an exact GTK version used?
And how did you configure the library? Please post exact configure line.

Thank you.

OibafA
In need of some credit
In need of some credit
Posts: 7
Joined: Wed Oct 07, 2020 9:35 am

Re: Mnemonics and custom widgets

Post by OibafA » Sat May 22, 2021 2:14 pm

I'm using the Ubuntu-provided binaries for the GTK libraries, I didn't compile them myself.

Code: Select all

$ LANG=C dpkg -l libgtk-3-0:amd64
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name             Version          Architecture Description
+++-================-================-============-====================================
ii  libgtk-3-0:amd64 3.24.20-0ubuntu1 amd64        GTK graphical user interface library

OibafA
In need of some credit
In need of some credit
Posts: 7
Joined: Wed Oct 07, 2020 9:35 am

Re: Mnemonics and custom widgets

Post by OibafA » Sun May 23, 2021 7:57 am

Just tested the same minimal.cpp mods with the GTK2 target, and the result is exactly the same as with the GTK3 target.

Post Reply