; --------------------------------------------------------------------
;          Selection (au moins 1)
;          Selection (0 1 ou n boutons ) quelconque
; modif mars 2002 : selection quelconque
; --------------------------------------------------------------------

PRO rh_selection_Event, Event

common rh_wselection, t_sel, sel_01n, exclusive

  WIDGET_CONTROL, Event.Id, GET_UVALUE = Ev
  CASE Ev OF 

    'self': BEGIN
;            print,'event',event
;stop
            if exclusive eq 0 then BEGIN
                t_sel(event.value)=event.select
  end else begin
      t_sel(*) = 0b
      tsel = event.value
      t_sel(tsel)=1b
  endelse
                
            END

    'fin':  BEGIN
            ind = WHERE(t_sel,nb)
            IF sel_01n eq 0 and nb EQ 0 THEN return
            WIDGET_CONTROL,EVENT.TOP,/DESTROY
            RETURN
            END
    ELSE:      
  ENDCASE

  RETURN
END
   

PRO rh_selection, titre, nom_f, tab_sel_2d, monofrequence = monofrequence, $
                  SEL_qcq = sel_qcq, $
                  GROUP = group
; pour la selection d'une seule frequence exclusive =1
;  la valeur t_sel renvoyee par cw_bgroup est un entier
;  sinon exclusive = 0 et t_sel est un tableau
common rh_wselection, tab_sel, sel_01n, exclusive
  tab_sel = tab_sel_2d
  if n_elements(monofrequence) eq 0 then exclusive = 0 else $
                                         exclusive = monofrequence

  IF N_ELEMENTS(Group) EQ 0 THEN GROUP=0
  t_sel = tab_sel
  if exclusive eq 1 then t_sel = 0
  sel_01n = 0
  IF N_ELEMENTS(sel_qcq) NE 0 THEN sel_01n=1  
;  selb = WIDGET_BASE(GROUP_LEADER = GROUP, COLUMN = 1, MAP = 1, $
;         TITLE = titre,/modal)
  selb = WIDGET_BASE(GROUP_LEADER = GROUP, COLUMN = 1, $
         TITLE = titre,/modal)

  b = WIDGET_BASE(selb, COLUMN=1, /FRAME,/BASE_ALIGN_CENTER,$
      /ALIGN_CENTER) 
  if exclusive eq 0 then begin
  ;  selection non exclusive 
       if N_ELEMENTS(t_sel) lt 10 then begin
          b_freq = CW_BGROUP( b, nom_f, COLUMN=1, /NONEXCLUSIVE, $
                   uvalue = 'self', SET_VALUE = t_sel)
      end else begin
          b_freq = CW_BGROUP( b, nom_f, /NONEXCLUSIVE, $
                   uvalue = 'self', SET_VALUE = t_sel, ROW = 6)
      endelse
  end else begin
  ;  selection exclusive 
              b_freq = CW_BGROUP( b, nom_f, COLUMN=1, /EXCLUSIVE, $
                   uvalue = 'self', SET_VALUE = t_sel)
  endelse  
;Arret 
  b = WIDGET_BASE(selb, /ROW, /ALIGN_CENTER)
  b1 = WIDGET_BUTTON( b, VALUE = ' OK ', UVALUE = 'fin', $
       xsize=70, ysize=35, /FRAME)

  WIDGET_CONTROL, selb, /REALIZE
  XMANAGER, 'rh_selection', selb, GROUP=group
  tab_sel_2d = tab_sel
  return
END

