	pro xselect_event,ev

common xselect_exc,a,group

widget_control,ev.id,get_uval=uv

	CASE uv OF

'DONE':	begin
widget_control,ev.top,/destroy
if group ne 0L then if widget_info(group,/valid) then $
	widget_control,group,/show
	end

ELSE:	begin

a=ev.index
	end

	ENDCASE

	end





	function xselect,x,info=info,title=title,group_leader=group_leader

;	Interactive selection of an element in array.
;	XSELECT is similar to XLIST but returns number of element
;	rather its value.

common xselect_exc,a,group

a=-1

if n_elements(info) le 0 then info=' '
if n_elements(title) le 0 then title='Xselect'
if n_elements(group_leader) le 0 then group_leader=0L

group=group_leader

Len=max(strlen(x))

if Len le 80 then base=widget_base(/colu, tit=title) else $
	base=widget_base(/colu,tit=title, /scroll) 

button=widget_button(base,val='DONE',uval='DONE')

info=widget_text(base,val=Info,uval='Info',ysize=n_elements(Info))

list=widget_list(base,val=	$
	strcompress(sindgen(n_elements(x)),/rem)+':  '+x,	$
	ysiz=n_elements(x) > 4 < 20, uval='List')

WIDGET_control,base,/realize,/hour

xmanager,'xselect',base,/modal

	return,a


	end