Pass forward accelerator keys 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
Romas
I live to help wx-kind
I live to help wx-kind
Posts: 176
Joined: Mon Jun 16, 2008 11:07 am
Location: Kaunas

Pass forward accelerator keys

Post by Romas » Tue Jul 15, 2008 6:08 am

Hello everyone,

My case is somekind unusual. There are few ways to catch particular(accelerator) key (combination) in your program, e.g. you can use accelerator table and/or you can filter all incoming eventas via wxApp:FilterEvent. The second methods has it's bads, so I am staying with first one.

So my question is: is there any way to pass accelerator key to focus control. Let's say:

wxAcceleratorEntry entries [1] = { 0 };
entries [0].Set(wxACCEL_NORMAL, (int) 'N', ID_NEW_WINDOW);
wxAcceleratorTable accel(1, entries);
frame->SetAcceleratorTable(accel);

'frame' control has few wxTextCtrl. When those text controls has no focus on it, it's ok to handle the accelerator event, but when they have, I want to pass that event to them (so they can handle 'N' key properly). Is there any way?

In case you will sey just handle keydown event isn't ok, because in frame window there are more windows, that can gain focus, but they don't need 'N' key.

I will appreciate for you oppinion.

DavidHart
Site Admin
Site Admin
Posts: 3846
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Tue Jul 15, 2008 10:13 am

Hi,
My case is somekind unusual.
No, not unless I misunderstand you.

You want the focused textctrl to react to accelerator keys. That's easy: just subclass wxTextCtrl, and put your accelerator table in the derived class. (You can then subclass further if you need different functionality in some of the textctrls.)

Focusing then automatically makes that textctrl react to accelerator keys. The posts you (presumably) have been reading were probably asking how to make this happen in non-focused controls.

Regards,

David

Romas
I live to help wx-kind
I live to help wx-kind
Posts: 176
Joined: Mon Jun 16, 2008 11:07 am
Location: Kaunas

Post by Romas » Tue Jul 15, 2008 10:41 am

I will try to explain it with different words :)

Let's imagine main window (wxFrame), which has many child(wxPanel) windows inside and those childs have childs also.

Now, when I am saying accelerator keys, I mean usual accelerator table, which is global to (I guess) main window. Only main window receives accelerator events. That is meant to be.

What I want to do is, when particular window catch key down event, I want it to eat it, no more further processing. In my case, if I set accelerator key to 'L', the event is sent to my text control window and without processing sent to parent window (then accelerator event is in action).

Or in other words: when particular window has focus, global accelerator table is disabled (or partly disabled).

DavidHart
Site Admin
Site Admin
Posts: 3846
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Tue Jul 15, 2008 12:56 pm

Let's imagine main window (wxFrame), which has many child(wxPanel) windows inside and those childs have childs also..
Fine so far. Though it's actually a better idea to have a single wxPanel as the only child of the frame; then make everything else a child of that panel, and put them in the panel's sizer. This avoids various bugs to do with sizing, tab, colour...
Now, when I am saying accelerator keys, I mean usual accelerator table, which is global to (I guess) main window. Only main window receives accelerator events. That is meant to be.
That might be what you mean it to be, but it isn't how wxWidgets works.
An accelerator table isn't global: it belongs to the widget it's put into. If you give your frame an accelerator table, it should catch key-presses only when the frame has focus, which will be approximately never. (In practice, on some platforms key events do sometimes manage to propagate up to the frame, but they officially shouldn't.)
What I want to do is, when particular window catch key down event, I want it to eat it, no more further processing. In my case, if I set accelerator key to 'L', the event is sent to my text control window and without processing sent to parent window (then accelerator event is in action).
If this is actually happening, it's the "In practice, on some platforms..." thing I mentioned above.
Or in other words: when particular window has focus, global accelerator table is disabled (or partly disabled)
That's the bit I misunderstood before. If you want a key combination to be disabled, and its event is somehow reaching a parent control, you should be able to prevent that happening by giving the textctrl an accelerator table as before, with those key combinations in it; but in the handler for those accelerators (in the textctrl), do nothing. That should effectively eat the key-press.

Romas
I live to help wx-kind
I live to help wx-kind
Posts: 176
Joined: Mon Jun 16, 2008 11:07 am
Location: Kaunas

Post by Romas » Tue Jul 15, 2008 1:25 pm

Ah, I think I've got it. What I wanted to do, cannot be done with accelerator table, because it is platform specific and I am trying to write multiplatfrom thing :) Well, I have a choise of filtering events, I just hope I will not find platfrom specific jokes :)))

Thank you for your replies.

DavidHart
Site Admin
Site Admin
Posts: 3846
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Tue Jul 15, 2008 7:07 pm

Ah, I think I've got it.
I think you haven't :(

a) What you want will happen anyway most of the time.

b) What I suggested in my second post, an empty handler that catches events from an accelerator table, will work on the other platform(s).

c) ...and it won't do any harm, even when it's not needed.

JustAProblem
In need of some credit
In need of some credit
Posts: 1
Joined: Sun Nov 02, 2008 9:39 am

Post by JustAProblem » Sun Nov 02, 2008 10:04 am

I have understand your problem, because I have the same one ;)

You have an acceleratortable for your main frame and you have several wxTextCtrl on this frame.

When you have set for example the 'a' as accelerator and you type in text in one TextCtrl, the program will execute the accelerator when you type in an 'a'.


When I set the wxMULTILINE style it works for me (wxMSW),(I don't know why), but I need an single-line user input, and when you press enter it should pass the word to a function (which works all probaly)

Can somebody help me?

Regards F.N.

alankdkd
In need of some credit
In need of some credit
Posts: 4
Joined: Mon Feb 04, 2019 6:33 pm

Re: Pass forward accelerator keys

Post by alankdkd » Mon Feb 04, 2019 6:55 pm

FYI, I think this problem has been solved here: viewtopic.php?t=39477

See TomasRiker's comment (#3).

Post Reply