;+ ; NAME: ; YNCANCEL ; ; PURPOSE: ; This function prompts USER with a widget window with Yes, No and ; Cancel buttons. Use this function to let the USER decide upon some ; subsequent action that you are going to take (described by the Msgs ; parameter) once this widget is destroyed. ; ; CATEGORY: ; Widgets. ; ; CALLING SEQUENCE: ; ; Result = YNCANCEL( [Msgs] ) ; ; INPUTS: ; Msgs: A string or array of strings containing message(s) ; to be displayed. ; ; OPTIONAL KEYWORD INPUTS: ; ; TITLE: A string containing the title of the widget window, ; ('IDL'=Default) ; ; ALIGN: Set this keyword to left align each message string, ; by default, each message string is centered (0=Default). ; ; RIGHT: Display widget in the right corner of the display. ; ; LEFT: Display widget in the left corner of the display. ; ; BOTTOM: Display widget in the bottom corner of the display. ; ; TOP: Display widget in the top corner of the display. ; ; CENTER: Display widget in the center of the display (DEFAULT). ; ; GROUP: The widget ID of an existing widget that serves as ; "group leader" for this message widget. ; ; OUTPUTS: ; This function will return: ; 1 if the Yes button is selected. ; 0 if the No button is selected. ; -1 if the Cancel button is selected. ; ; COMMON BLOCK: ; YNCANCEL: For internal use only. ; ; MODIFICATION HISTORY: ; Written by: Han Wen, January 1994. ; 02-AUG-1995 Added scrollbar if number of messages exceeds 15. ; 27-SEP-1995 Improved algorithm to determine width of widget in pixels. ;- PRO YNC_Event, Event common YNCANCEL, YNCANCEL_val WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev CASE Ev OF 'LISTN': return 'YES': YNCANCEL_val = 1 'NO' : YNCANCEL_val = 0 'CANCEL' : YNCANCEL_val = -1 ENDCASE dummy = EXECUTE('WIDGET_CONTROL, Event.Top, /DESTROY') END function YNCANCEL, Msg1, TITLE=Title, ALIGN=Align, LEFT=Left, $ RIGHT=Right, BOTTOM=Bottom, TOP=Top, CENTER=Center, GROUP=Group common YNCANCEL, YNCANCEL_val nrow_max = 15 NP = N_PARAMS() if NP eq 0 then Msg1 = '' margin=' ' Msg = margin+Msg1+margin IF N_ELEMENTS(Group) EQ 0 THEN GROUP=0 IF N_ELEMENTS(Title) EQ 0 THEN TITLE='IDL' IF N_ELEMENTS(Center)EQ 0 THEn CENTER=1 IF (keyword_set( LEFT ) or $ keyword_set( RIGHT) or $ keyword_set( BOTTOM)or $ keyword_set( TOP )) then CENTER=0 ; Create the message widget base YNC = WIDGET_BASE(GROUP_LEADER=Group, $ COLUMN=1, $ MAP=0, $ TITLE=title, $ UVALUE='YNC') ; Create one label for each message string LABEL0 = WIDGET_LABEL( YNC, UVALUE='LABEL0', VALUE=' ') nmsg = N_ELEMENTS( Msg ) if keyword_set( ALIGN ) or (nmsg gt nrow_max) then begin nrow = nmsg < nrow_max Listn= WIDGET_LIST( YNC, $ YSIZE= nrow, $ VALUE=msg, $ UVALUE='LISTN' ) endif else begin for i=0,nmsg-1 do begin LABELn= WIDGET_LABEL( YNC, $ UVALUE='LABEL'+strtrim(string(15+i),2), $ VALUE=msg(i)) endfor endelse LABEL1 = WIDGET_LABEL( YNC, UVALUE='LABEL1', VALUE=' ') ; Determine the number of pixels needed to center the Yes button msg_list = [string(msg1),title+strpad(' ',5)] msg_byte = byte(msg_list) msg_wgt = 6*( (msg_byte ne 32) and (msg_byte ne 0) ) msg_wgt = msg_wgt + 4*( msg_byte eq 32 ) msg_wgt = REFORM(TOTAL(msg_wgt,1)) widget_len= MAX(msg_wgt) + 2*strlen(margin) ; Create the Yes & CANCEL buttons widget base BASE_BUTTONS = WIDGET_BASE(YNC, $ ROW=1, $ MAP=1, $ XPAD=widget_len/2, $ UVALUE='BASE_BUTTONS') Yes = WIDGET_BUTTON( BASE_BUTTONS, $ UVALUE='YES', $ VALUE='Yes') No = WIDGET_BUTTON( BASE_BUTTONS, $ UVALUE='NO', $ VALUE='No') CANCEL = WIDGET_BUTTON( BASE_BUTTONS, $ UVALUE='CANCEL', $ VALUE='Cancel') WIDGET_POSITION, YNC, LEFT=Left, RIGHT=Right, TOP=Top, $ BOTTOM=Bottom, CENTER=Center WIDGET_CONTROL, YNC, /INPUT_FOCUS XMANAGER, 'YNC', YNC, /MODAL, GROUP_LEADER=Group IF keyword_set(Group) then WIDGET_CONTROL, Group, /SHOW return, YNCANCEL_val END