; $Id: w_options.pro,v 1.0 1997/05/23 mgs $ ;+ ; NAME: ; w_options ; PURPOSE: ; creates a options dialog that allows to choose options options ; ; CATEGORY: ; Modal widgets. ; ; CALLING SEQUENCE: ; widget = w_options(parent) ; ; INPUTS: ; PARENT - The ID of the parent widget. ; ; KEYWORD PARAMETERS: ; UVALUE - Supplies the user value for the widget. ; ; OUTPUTS: ; The ID of the created widget is returned. ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; ; PROCEDURE: ; ; MODIFICATION HISTORY: ;- ;----------------------------------------------------------------------------- FUNCTION options_event, event parent=event.handler ; the event usually must be passed further up ! ; and the next higher event handler must destroy the window ; (cannot be destroyed here, because we need the info !) passevent = 0 ; Retrieve the structure from the child that contains the sub ids. stash = WIDGET_INFO(parent, /CHILD) WIDGET_CONTROL, stash, GET_UVALUE=state, /NO_COPY if(event.id eq state.bID) then begin ; button pressed (OK) widget_control,state.oID,get_value=bstate ; contains all buttons info = bstate(0) bmult = 2 if(n_elements(bstate) gt 1) then $ for i=1,n_elements(bstate)-1 do begin info = info + bmult*bstate(i) bmult = bmult*2 endfor value = 1-event.value ; OK=1, (Cancel=0) passevent = 1 endif ; Restore the state structure WIDGET_CONTROL, stash, SET_UVALUE=state, /NO_COPY if(passevent) then $ return, { ID:parent, TOP:event.top, HANDLER:0L, VALUE:value , $ INFO:info } $ else return,0 END ;----------------------------------------------------------------------------- FUNCTION w_options, TITLE=title, UVALUE=uval, OPTIONS=options, VALUE=value ; value contains initial selections ; options contains string array with the options to be displayed ON_ERROR, 2 ;return to caller ; Defaults for keywords IF NOT (KEYWORD_SET(uval)) THEN uval = 0 if (not keyword_set(value)) then value = 0 if (not keyword_set(options)) then options = ['option'] if (not keyword_set(title)) then title = ' OPTIONS ' ; construct array from value if necessary if(n_elements(value) eq 1 AND value gt 1) then begin tmpval = value value = intarr(n_elements(options)) for i =n_elements(options)-1,0,-1 do begin if((tmpval AND 2^i) gt 0) then value(i) = 1 endfor endif base = WIDGET_BASE(TITLE=title, UVALUE = uval, $ frame = 3, /column, $ EVENT_FUNC = "options_event" ) subbase = widget_base(base, /column) obut = cw_bgroup(base,/column,/nonexclusive,options,/frame) widget_control,obut,set_value=value buttons = cw_bgroup(base,/row,[' OK ']) state = { bID:buttons, oid:obut } ; Save out the initial state structure into the first childs UVALUE. WIDGET_CONTROL, WIDGET_INFO(base, /CHILD), SET_UVALUE=state, /NO_COPY RETURN, base END