ITT Rule IDL Version 7.0 Manuale Utente

Pagina di 430
356
Chapter 15: Creating a Custom iTool Widget Interface
Handling Shutdown Events
iTool Developer’s Guide
Handling Shutdown Events
Because your custom interface is associated with an iTool, destruction of the 
interface may entail shutting down and cleaning up the entire iTools system. This 
means that in addition to normal cleanup of pointers and objects used by the 
interface, you will need to instruct the iTools system to shut itself down when your 
interface is destroyed.
Generating Shutdown Events
You must set the TLB_KILL_REQUEST_EVENTS keyword when creating the top-
level widget base that holds your interface. With this keyword set, when the user 
destroys the top-level base, a WIDGET_KILL_REQUEST event is generated, 
allowing you to perform the actions necessary to shut down the iTools system.
Handling the Shutdown Event
When the user destroys the top-level base of your custom interface, you may want to 
prompt the user to save the current iTool state before shutting down. The standard 
iTool interface uses an iTool system service named “Shutdown” to both prompt the 
user for confirmation that a shutdown is requested and offer to let the user save the 
current state. The Shutdown service then handles other cleanup tasks before exiting 
the iTool.
The following code, from the event handling routine in the 
example2_wdtool.pro
 
interface definition (developed in 
calls the iTools Shutdown service.
; Destroy the widget.
'WIDGET_KILL_REQUEST': BEGIN
; Get the shutdown service and call DoAction.
; This code must be here, and not in the _cleanup routine,
; because the tool may not actually be killed. (For example
; the user may be asked if they want to save, and they may 
; hit "Cancel" instead.)
IF OBJ_VALID((*pState).oUI) THEN BEGIN
oTool = (*pState).oUI->GetTool()
oShutdown = oTool->GetService('SHUTDOWN')
void = (*pState).oUI->DoAction(oShutdown-
>getFullIdentifier())
ENDIF
END