In article <3thd4j$32l@lace.Colorado.EDU>, Jyothi Kirani <jvk> wrote :
> Can any one help ?
>
> I have written a small widget interface in which I have a bunch of text fields.
> I wanted to know whether I can move the cursor to the next text field as soon
> as a return key is hit in the previous text field, without using the mouse.
>
> If anyone has any ideas as to how to implement this, please let me know.
>
> Thanks,
> jyothi.
Here's a _very_ simple example of how you can change the input focus from one
text widget to another. Although I don't condone using common blocks as
state variables, I've done it here to keep things simple.
-------------------- C u t H e r e ---------------------------------------
; change_focus.pro Charles Cavanaugh July 1995
; simple demonstration of changing focus of text widgets
pro change_focus_event, event
common testdata, txt0, txt1, txt2, val0, val1, val2
; process the event
widget_control, event.id, get_uvalue = uval
case uval of
; if the return key was hit while txt0 had the input focus, change focus to txt1
'txt0' : widget_control, txt1, /input_focus
; if the return key was hit while txt1 had the input focus, change focus to txt2
'txt1' : widget_control, txt2, /input_focus
; if the return key was hit while txt1 had the input focus, change focus to txt0
'txt2' : widget_control, txt0, /input_focus
; read the text boxes and destroy the widget
'done' : begin
widget_control, txt0, get_value = tempval
val0 = tempval(0)
widget_control, txt1, get_value = tempval
val1 = tempval(0)
widget_control, txt2, get_value = tempval
val2 = tempval(0)
widget_control, event.top, /destroy
end
else :
endcase
end
pro change_focus
; save ids and values
common testdata, txt0, txt1, txt2, val0, val1, val2
; build the widget
base = widget_base (title = 'Changing Focus Demonstration', /column)
val0 = ''
txt0 = widget_text (base, xsize = 50, value = val0, uvalue = 'txt0', /editable)
val1 = ''
txt1 = widget_text (base, xsize = 50, value = val1, uvalue = 'txt1', /editable)
val2 = ''
txt2 = widget_text (base, xsize = 50, value = val2, uvalue = 'txt2', /editable)
done = widget_button (base, xsize = 50, value = 'Done', uvalue = 'done')
; realize the widget
widget_control, base, /realize
; set the initial input focus to whatever text box you want
widget_control, txt0, /input_focus
; register the widget
; and since common blocks are used to hold the state variables, this widget should be modal
xmanager, 'change_focus', base, group_leader = group, /modal
; print out the values returned from the text boxes
print, 'val0 is ', val0
print, 'val1 is ', val1
print, 'val2 is ', val2
end
--
Charles Cavanaugh | "Words are very unnecessary, they can only do harm"
cavanaug@ncar.ucar.edu | - Depeche Mode
NCAR Boulder, CO, USA | "Facts all come with points of view"
My opinions | - Talking Heads
|