Frame Callbacks
- Last UpdatedOct 30, 2024
- 2 minute read
The FRAME gadget can have an assigned callback, which is executed when the radio group selection is changed, whenever you select an unselected radio-toggle. As there is only a SELECT action supported, it can be either a simple callback or an open callback.
The form definition below is a simple TV and radio station selector, shown above.
layout form !!FRGTest dialog noAlign
title |Select a program|
Frame .rg1 |TV and Radio|
path down
text .choice tagwid 6 |Selection:| width 12 is STRING
rToggle .rad1 tagwid 7 |BBC 1| States '' 'BBC 1'
path right
valign centre
rToggle .rad2 tagwid 7 |BBC 2| States '' 'BBC 2'
rToggle .rad3 tagwid 7 |Anglia| States '' 'Anglia'
rToggle .rad4 tagwid 7 |Chan 4| at xmin.rad1 ymax.rad1 States '' 'Chan 4'
rToggle .rad5 tagwid 7 |Radio:| States '' 'radio'
option .Radio width 10
exit
button .cancel |Cancel| at xmin form ymax form + 0.2 CANCEL
button .ok | OK | at xmax form - size OK
- set focus to button to ensure to ensure Windows does not set it to first Rtoggle
!this.keyboardFocus = !this.ok
exit
Note:
The form’s keyboard focus is initially placed on the OK button to prevent it being assigned (by Windows) to the first RTOGGLE rad1 (effectively
the first interactive gadget on the form as the text field Selection is read-only).
The form constructor method assigns a simple callback, the form method RGroupSelectionChanged(), to the frame rg1 (radio group). It then initializes the gadget values and selects the second RTOGGLE as the default selection.
define method .FRGTest()
-- Constructor
-- Frame radiogroup with simple callback
!this.rg1.callback = '!this.RGroupSelectionChanged( )'
-- set result field read-only
!this.choice.setEditable(false)
-- Radio choices
!this.rad5.setTooltip(|select your Radio option|)
!radio[1] = 'Q103'
!radio[2] = 'Hereward'
!radio[3] = 'Cambridge'
!radio[4] = 'ClassicFM'
!radio[5] = 'Caroline'
!this.Radio.dtext = !radio
!this.Radio.setTooltip(|change your Radio option|)
!this.Radio.callback = '!this.selectProgram(!this.rad5)'
-- set initial value
!this.rg1.val = 2
!this.RGroupSelectionChanged( )
Endmethod
The group callback uses the FRAME’s VAL member to get the current selected index and hence the current RTOGGLE and its OnValue member value. If the selected RTOGGLE’S value is 'radio', then the selected program is read from the RADIO option gadget. Finally the selected program string is displayed in the Selection (read-only) text gadget.
define method .RGroupSelectionChanged( )
-- Service radiogroup select event
!Frame = !this.rg1
!index = !Frame.val
!rTog = !Frame.RToggle(!index)
!value = !rTog.onValue
-- Do some application actions
if( !value eq 'radio' ) then
!value = !this.Radio.selection('dtext')
endif
!this.choice.val = !value
endmethod
The callback on the RADIO option gadget detects if the 'radio:' RTOGGLE rad5 is current and if so, it deselects it, leaving no current selection, and clears the Selection text field.
define method .selectProgram( !rtog is GADGET )
-- Select new program from option list
if( !this.rg1.val eq !rtog.index ) then
-- rtog is current, so deselect it within group
!this.rg1.val = 0
!this.choice.clear()
endif
endmethod