FXTexr and widget focus

Hi,

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?

If you know how to set focus to the next widget, then all you have to do is
capture the TAB keypress. You can do this by subclassing the FXText widget
and capture the keypresses.

class MyTextWidget < FXText
def initialize(*args)
FXMAPFUNC(SEL_KEYRELEASE, 0, “onKeyRelease”)

def onKeyRelease(sender, sel, event)
	if event.code == Fox::KEY_Tab then
		# switch focus
	end
end

end

···

-----Original Message-----
From: Gordon Hartley [mailto:gordonhartley@gordonhartley.com]
Sent: Monday, January 27, 2003 4:19 PM
To: ruby-talk ML
Subject: FXTexr and widget focus

Hi,

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?

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

Hi Lyle,

Thanks for the help above, it does seem to work by itself, but I can’t
seem to integrate it with frames (I have 4 vertical frames sitting in
a horizontal one). It always the _NEXT always ends up on focusing at
the first control in the frame, and previous takes it to the last
control in the last frame.

I’ve played around with it quite a bit, but haven’t been successful so
far… I’m sure it should be obvious, but obviously not to me. Any
more great words of FXWisdom?

Thanks,
Gordon

···

On Mon, 27 Jan 2003 18:13:15 -0600, Lyle Johnson lyle@users.sourceforge.net wrote:

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
}

Gordon Hartley wrote:

Thanks for the help above, it does seem to work by itself, but I can’t
seem to integrate it with frames (I have 4 vertical frames sitting in
a horizontal one). It always the _NEXT always ends up on focusing at
the first control in the frame, and previous takes it to the last
control in the last frame.

I’m not quite sure I understand what the problem is, other than you’re
not getting the tab order that you expected. Usually, the tab order
within a frame goes in the order in which the child widgets were added
to the frame, although I think Jeroen recently found a bug for this. Can
you maybe send me some code that demonstrates the problem?