Hi Ryan,

Thanks for your kind and thought-out reply.  Well, I think you're right 
about disabling alt-tab and similar events.  I should do that.  Not
just for the reasons you list, but also because I am creating a totally
controlled environment, so we just don't want all that op sys stuff 
visible.  So that would mean I can just log it as an issue and forget 
about it for the time being.

Regarding FindFocus(): it could work, if I didn't find that for some
reason the event-handler was being called TWICE, one for the first control
and once for the second control (ie the tabbed-to control).  It may just 
be a coding fault, of course.

The other route I'm looking at is GetID() and FindWindow(), which should 
also allow me to ascertain where I am.  I'm manually setting some ids 
rather than using wxANY in order to know which button I'm being called 
from.

I'll play around with them in the background and let this forum know
how I get on.

Thanks again.

Regards

Steve




-----Original Message-----
From: Ryan Jendoubi [mailto:ryan.jendo...@googlemail.com] 
Sent: 14 August 2009 12:10
To: wxPerl users
Subject: Re: wxGlade Generated Code

[ Sorry again all for my double postings ]

Hi Steve,

Steve Cookson wrote:
> So that's how it works!  So if I want to detect tabbing out of a field 
> to trigger validation, I use the lose focus event (EVT_KILL_FOCUS) on
> the control. But alt-tab (and I guess alt-esc etc) to another app 
> also trigger it.  How can I filter out alt-tab etc?

I know you've been tackling that for a few days, I'm still not sure I 
can help.

I don't think filtering keys is the way to go. I'd imagine it's not the 
actual keypress that generates a KILL_FOCUS, it's the /result/ of the 
keypress, if you get me. I think the best you could do with filtering 
key presses would be to disable alt-tab / program switching altogether 
when in that text field. That'd be in an event handler of a TextCtrl you 
subclassed yourself. You'd have to read up the wxWidgets docs [0], 
particularly wxKeyEvent and wxKeyCode to see what combination of 
EVT_KEY_DOWN, EVT_KEY_UP and/or EVT_CHAR you'd need to do what you need.

Looking around in the docs, I think a better way to do what you need 
would be using Wx::Window::FindFocus() [1] (in wxWidgets there's also a 
HasFocus() event that could be even more elegant but grep'ing for that 
doesn't show it anywhere in the Wx-0.91 source; maybe someone could 
correct me on that).

Could you just have something at the start of your EVT_KILL_FOCUS 
handler like this?

if ( Wx::Window::FindFocus ne $self->{nextCtrlByTab} ) { return; }

Or conceivably just if ( FindFocus == NULL ) if it returns null when 
focus has moved out of the program.

What do you think, workable?

-- Ryan



[0] http://docs.wxwidgets.org/trunk/

[1] 
http://docs.wxwidgets.org/trunk/classwx_window.html#777258379a3eef1b0530f12d
b6b77cab

Reply via email to