pro w_test dlg = w_edit(title='MAIN WIDGET',text=['Line 1','Line 2']) widget_control,dlg,/realize print,'widget_ID(DLG) = ',dlg dlg2 = w_edit(title='DEPENDENT WIDGET', $ group_leader=dlg, $ text=['2nd window:','Line 1','Line 2']) widget_control,dlg2,/realize print,'widget_ID(DLG2) = ',dlg2 event = widget_event(dlg) widget_control,event.top,/destroy end ;------------------------------------------------------------- ;+ ; NAME: ; W_EDIT ; ; PURPOSE: ; creates a simple text editor with an OK and Cancel button ; and handles the events of this widget. ; ; CATEGORY: ; general purpose widgets - modal widgets ; ; CALLING SEQUENCE: ; dlg = W_EDIT(parent, [keywords]) ; ; INPUTS: ; PARENT --> widget ID of the parent widget ; ; KEYWORD PARAMETERS: ; TITLE --> window title for the editor window (default blank) ; ; TEXT --> initial text in the editor window (string array) ; ; GROUP_LEADER --> if this widget shall be used as a simple display ; window, you can specify a GROUP_LEADER (= widget-ID of a ; dialog box). The window will then disappear as soon as the ; dialog box is closed. NOTE: the OK and Cancel buttons will ; not be shown in this case. ; ; OUTPUTS: ; w_edit returns a widget ID of the editor. For implementation ; see example below. ; ; SUBROUTINES: ; EDIT_EVENT --> handles editor events. Reacts only to OK or Cancel. ;- FUNCTION edit_event, event parent=event.handler ; Retrieve the structure from the child that contains the sub ids. stash = WIDGET_INFO(parent, /CHILD) WIDGET_CONTROL, stash, GET_UVALUE=state, /NO_COPY passevent = 0 ; ---------------------------------- ; button pressed ("OK" or "Cancel") ; ---------------------------------- if(event.id eq state.bID) then begin widget_control,state.textID,get_value=text info = text value = 1-event.value ; OK=1, Cancel=0 passevent = 1 ; this terminates the dialog 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_edit, TITLE=title, TEXT=text, UVALUE=uval, $ GROUP_LEADER=group_leader ON_ERROR,2 ; return to caller ; Defaults for keywords IF NOT (KEYWORD_SET(uval)) THEN uval = 0 if (not keyword_set(title)) then title = ' ' if (not keyword_set(text)) then text = '' if (not keyword_set(group_leader)) then group_leader = 0 print,'GROUP_LEADER=',group_leader base = WIDGET_BASE(TITLE=title, UVALUE = uval, $ frame = 3, /column, $ EVENT_FUNC = "edit_event" ) ysize = 8 > n_elements(text) < 40 textf = widget_text(base,/editable,xsize=80,ysize=ysize,frame=3, $ /scroll,value=text,group_leader=group_leader) if (group_leader eq 0) then $ buttons = cw_bgroup(base,/row,['OK','Cancel']) $ else $ buttons = -1 state = { bID:buttons, textID:textf } ; 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