From: Lyle Johnson Date: 2003-01-28T09:19:03+09:00 Subject: Re: FXTexr and widget focus Gordon Hartley wrote: > Just got an annoying problem with changing focus off of a FXText > widget (note: not FXTextField). > > All the other widgets on my form seem to be fine for tabbing away > from, but the multiline FXText instead consumes the tabs and stores > them as a character instead. > > Anyway, what's the appropriate solution for this? At the moment, I've > got a hotkey which sets focus on the next control, but that's still > quite painful, especially since the form is meant to be used for data > entry... > > The docs on the Fox site don't actually have anything under the > 'keyboarding' section, so just wondering what other people have done? > (I presume I'm not the first with this problem?) > > Any ideas? The most straightforward solution is to intercept the SEL_KEYPRESS message that the FXText widget sends to its message target, and then handle the tab key yourself. Here's the code: myText.connect(SEL_KEYPRESS) { |sender, sel, event| if event.code == KEY_Tab if (event.state & SHIFTMASK) != 0 getApp().focusWindow.handle(self, MKUINT(0, SEL_FOCUS_PREV), event) else getApp().focusWindow.handle(self, MKUINT(0, SEL_FOCUS_NEXT), event) end else 0 # keypress was not handled here end } This handler first checks to see if this SEL_KEYPRESS message was generated because of a tab key press (event.code == KEY_Tab). If it wasn't, the handler just returns zero to indicate that it didn't handle the SEL_KEYPRESS message and thus the FXText widget should perform its normal handling for this keypress event. If it was in fact a KEY_Tab, we then want to check whether the Shift key is down or not (i.e. are we tabbing "backwards" or "forwards"). Depending on the shift key state (event.state & SHIFTMASK) we send one of two messages to the currently-focused window (focusWindow). SEL_FOCUS_PREV tells the current focus window to hand off the focus to the previous window in the focus chain; SEL_FOCUS_NEXT does the opposite. Hope this helps, Lyle