[Fxruby-users] Using TEXTFIELD_REAL and connect()
Status: Inactive
Brought to you by:
lyle
|
From: <tku...@so...> - 2004-02-20 00:34:30
|
Hi,
I have a window derived from FXDialogBox, and I would like to have it
respond to either mouse clicks in the "OK" box as well as hitting the
enter key. I tried an initial attempt at it by doing something like
this:
(tf is a FXTextfield)
...
@tf.connect(SEL_KEYPRESS) do |send,sel,ptr|
onNewKeypress(send,sel,ptr)
end
...
def onNewKeypress(send,sel,ptr)
asciival = ptr.text[0].to_i
if asciival == 13 # Enter key
onCmdAccept(send,sel,ptr)
else
@tf.text += ptr.text
@tf.setCursorPos(@tf.text.length)
end
end
(This isn't necessarily 100% runnable code, I just copied it out of my
head, but the idea should be there)
The problem is, that now that I have used connect() on the textfield,
I lose the TEXTFIELD_REAL option, because I'm handling all keypresses
myself in the above function. I started adding stuff into the above
function to catch various keys, but then I realized I was probably
re-implementing all of what's already in the default keypress handler.
The goal is to have "enter" treated differently than other keystrokes,
so that hitting enter while in the field causes automatic onCmdAccept
for the dialog box. After probably wasting time writing a dozen or
two lines of code, I think there's probably already an answer that
isn't nearly so hard.
Any suggestions would be greatly appreciated.
Thanks,
Tom
|