Passing and Retrieving User Data
All Wave Widgets can carry the user-specified value of a variable. This allows the developer to store the copy of the variable with the widget in one routine and retrieve it in another routine. Any value can be stored and retrieved.
This feature is useful for passing values between routines without using Common Block variables.
To store the value 111 with a widget, use the following command:
status = WwSetValue(widgetID, Userdata=111)
To retrieve the value of Userdata from the widget, use the command:
value = WwGetValue(widgetID, /Userdata)
Example
The following example shows a practical use for passing a value with the Userdata keyword to close an application when the user clicks on a specified button. The value of the top-level widget, top, is passed from the widget creation procedure myap to the callback procedure ButtonCB via the Userdata keyword. This value is then used in the WwSetValue function to close the application by destroying the top-level widget when the user clicks on Quit. You can run this example by typing the callback procedures into a file and compiling them with the .RUN command. Then enter the application procedure in a file and run it.
Callback Procedure
PRO ButtonCB, wid, data
CASE data OF
1: BEGIN
top=WwGetValue(wid, /Userdata)
; Get the value of the top-level widget.
PRINT, top
status=WwSetValue(top, /Close)
END
2: PRINT, 'Dialog Selected'
3: PRINT,'Message Selected'
ENDCASE
END
 
PRO RadioCB, wid, which
CASE which OF
1: PRINT,'First Toggle Selected'
2: PRINT,'Second Toggle Selected'
3: PRINT,'Third Toggle Selected'
ENDCASE
value = WwGetValue(wid)
print, value
END
Application Procedure
PRO myap
top=WwInit('ww_ex19', 'Examples', layout,$
/Vertical, Spacing=30, Border=10)
blabels = ['Quit','Dialog','Message']
bbox=WwButtonBox(layout, blabels, $
'ButtonCB', /Horizontal, Spacing=20)
status=WwSetValue(bbox, Userdata=top)
; Store value of top-level widget with the Userdata keyword.
rlabels=['System','Owner','Group']
rbox=WwRadioBox(layout,rlabels, 'RadioCB', /Vertical, $
Border=2, Spacing=20, Top=controls)
status=WwSetValue(top, /Display)
WwLoop
END