
Chapter 15: Creating a Custom iTool Widget Interface 367
iTool Developer’s Guide Example: a Custom iTool Interface
The WIDGET_KBRD_FOCUS event arrives when the user clicks “into” or “out of”
the widget interface. We are concerned only with events generated when the user
selects the widget interface, because in this case we need to inform the iTool system
object that our iTool has become the “current” tool. To do this, we check the value of
the
enter field of the widget event structure; if it contains a 1 (one), we know that
the user has clicked “into” the interface.
Next, we check to make sure that the user interface object stored in the
oUI field of
the widget interface state structure is still valid. If the object is valid, we retrieve a
reference to the iTool object using the user interface object’s GetTool method. We
use the iTool object reference to retrieve an object reference to the
SET_AS_CURRENT_TOOL service, and call the iTool object’s DoAction method
with the full identifier of the service.
draw_plot_event
The draw_plot_event routine is specified as the event handler for the “Insert New
Plot” button in the custom section of the interface. The routine checks the values of
the other widgets in the custom interface and uses the IPLOT routine to generate a
new plot line in our iTool window. The complete code for this event-handler routine
is shown below.
PRO draw_plot_event, event
; Retrieve a pointer to the state structure.
wChild = WIDGET_INFO(event.top, /CHILD)
WIDGET_CONTROL, wChild, GET_UVALUE = pState
; Get the iTool identifier and make sure our iTool
; is the current tool.
toolID = (*pState).oTool->GetFullIdentifier()
ITCURRENT, toolID
; Define some line colors.
colors = [[0,0,0],[255,0,0], [0,255,0], [0,0,255]]
; Get the value of the line color droplist and use it
; to select the line color.
linecolor = WIDGET_INFO((*pState).wLineColor, /DROPLIST_SELECT)
newcolor = colors[*,linecolor]
; Get the value of the "number of points" slider.
WIDGET_CONTROL, (*pState).wSlider, GET_VALUE=points
; Get the value of the line size droplist.
linesize = WIDGET_INFO((*pState).wLineSize, /DROPLIST_SELECT)+1