pro mg_dialog_list_event, event
compile_opt strictarr
widget_control, event.top, get_uvalue=pstate
uname = widget_info(event.id, /uname)
case uname of
'choiceDroplist': (*pstate).choice = event.index
'cancel': widget_control, event.top, /destroy
'ok': begin
(*pstate).cancelled = 0B
widget_control, event.top, /destroy
end
endcase
end
function mg_dialog_list, choices, text, dialog_parent=parent, title=title
compile_opt strictarr
_parent = n_elements(parent) eq 0L ? widget_base(map=0) : parent
tlb = widget_base(title=title, /column, /base_align_center, $
group_leader=_parent, /modal)
choicesBase = widget_base(tlb, /row)
labelWidget = widget_label(choicesBase, value=text)
choiceDroplist = widget_droplist(choicesBase, value=choices, $
uname='choiceDroplist')
xsize = 75
buttonBase = widget_base(tlb, /row)
cancelButton = widget_button(buttonBase, value='Cancel', scr_xsize=xsize, $
uname='cancel')
okButton = widget_button(buttonBase, value='OK', scr_xsize=xsize, $
uname='ok')
widget_control, tlb, /realize
state = { choice: 0L, cancelled: 1B }
pstate = ptr_new(state, /no_copy)
widget_control, tlb, set_uvalue=pstate
xmanager, 'mg_dialog_list', tlb, event_handler='mg_dialog_list_event'
if (n_elements(parent) eq 0L) then widget_control, _parent, /destroy
choice = (*pstate).choice
cancelled = (*pstate).cancelled
ptr_free, pstate
return, cancelled ? -1L : choice
end
choice = mg_dialog_list(['A', 'B', 'C'], $
'Select the correct answer:', $
title='Multiple choice')
help, choice
end