user manual
362 Chapter 15: Creating a Custom iTool Widget Interface
Example: a Custom iTool Interface iTool Developer’s Guide
you are not familiar with this concept, inspect the example2_wdtool routine before
reading the event handling and callback routines.
Note
We store our state variable in the user value of the first child widget, rather than the
user value of the top-level base, as a matter of programming style. You could also
choose to store the variable in the user value of the top-level base.
example2_wdtool_callback
Our example interface handles only one message from the iTool system:
FILENAME. The complete code for the callback routine is shown below.
PRO example2_wdtool_callback, wBase, strID, messageIn, userdata
; Make sure we have a valid widget.
IF (~WIDGET_INFO(wBase, /VALID)) THEN $
RETURN
; Retrieve a pointer to the state structure.
wChild = WIDGET_INFO(wBase, /CHILD)
WIDGET_CONTROL, wChild, GET_UVALUE = pState
; Handle the message that was passed in.
CASE STRUPCASE(messageIn) OF
; The FILENAME message is received if the user saves
; the iTool with a new name. This callback sets the
; title of the iTool to match the name of the file.
'FILENAME': BEGIN
; Use the new filename to construct the title.
; Remove the path.
filename = FILE_BASENAME(userdata)
; Append the filename onto the base title.
newTitle = (*pState).title + ' [' + filename + ']'
WIDGET_CONTROL, wBase, TLB_SET_TITLE = newTitle
END
; Other messages would be handled here.
ELSE: ; Do nothing
ENDCASE
END