;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; NAME: cw_combobox_pm ; ; PURPOSE: widget equivalent a WIDGET_COMBOBOX sauf qu'en plus on ; dispose de 2 bouttons + et - pour deplacer le widget de +/- 1. ; ; CATEGORY: compound widget (aide a l''ecriture des widgets) ; ; CALLING SEQUENCE: id=cw_combobox_pm(parent) ; ; INPUTS: ; Parent: The widget ID of the parent widget. ; ; KEYWORD PARAMETERS:tous ceux de WIDGET_COMBOBOX ; ; OUTPUTS: ; The returned value of this function is the widget ID of the ; newly-created animation widget. ; ; COMMON BLOCKS: none ; ; SIDE EFFECTS: ; ; Widget Events Returned by Combobox Widgets ; ; Pressing the mouse button while the mouse cursor is over an ; element of a combobox widget causes the widget to change the label ; on the combobox button and to generate an event. The appearance of ; any previously selected element is restored to normal at the same ; time. The event structure returned by the WIDGET_EVENT function is ; defined by the following statement: ; ; { CW_COMBOBOX_PM, ID:0L, TOP:0L, HANDLER:0L, INDEX:0L, OUT:0 } ; ; The first three fields are the standard fields found in every ; widget event. ; INDEX returns the index of the selected item. This can be used to ; index the array of names originally used to set the widget''s ; value ; OUT:c''est un entier qui peut prendre 3 valeurs: ; 1 : si on appuie sur + alors que l''index est deja aux max. rq: ; ds ce cas l''index reste au max ; -1: si on appuie sur - alors que l''index est deja aux min. rq: ; ds ce cas l''index reste au min ; 0 : ds les autres cas! ; ; Keywords to WIDGET_CONTROL ; ; A number of keywords to the WIDGET_CONTROL procedure affect the ; behavior of cw_slider_pm widget: GET_VALUE and SET_VALUE. ; 1) GET_VALUE ; widget_control,wid_id,get_value=resultat ; retourne ds la variable resultat une structure de 3 elements dont ; les noms sont inspires des mots cles que l''on peut passer a ; widget_control qd on utilise WIDGET_COMBOBOX: ; COMBOBOX_NUMBER: the number of elements currently ; contained in the specified combobox widget. ; COMBOBOX_SELECT: the zero-based number of the ; currently-selected element (i.e., the currently-displayed ; element) in the specified combobox widget. ; DYNAMIC_RESIZE: a True value (1) if the widget specified ; by Widget_ID is a button, combobox, or label widget that ; has had its DYNAMIC_RESIZE attribute set. Otherwise, ; False (0) is returned. ; 2) SET_VALUE ; widget_control,wid_id,set_value=impose ; permet de modifier l''etat de la combobox comme on peut le faire ; pour WIDGET_COMBOBOX Impose peut etre: ; a) The contents of the list widget (string or string array) ; b) une structure qui peut avoir comme elements (de 1 a 3): ; DYNAMIC_RESIZE:Set this keyword to activate (if set to 1) ; or deactivate (if set to 0) dynamic resizing of the ; specified CW_COMBOBOX_PM widget (see the documentation ; for the DYNAMIC_RESIZE keyword to WIDGET_COMBOBOX ; procedure for more information about dynamic widget ; resizing). ; COMBOBOX_SELECT:Set this keyword to return the zero-based ; number of the currently-selected element (i.e., the ; currently-displayed element) in the specified combobox ; widget. ; VALUE: The contents of the list widget (string or string ; array) ; ; RESTRICTIONS: ; ; EXAMPLE: cf utiliser le programme founit i-dessous: testwid et la ; procedure associee, testwid_event. ; ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) ; 6/9/1999 ; ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ; testwid, value=strtrim(indgen(10),2) ; PRO testwid_event, event ; ; help, event, /STRUCT ; ComboboxId = widget_info(event.top,find_by_uname = 'c''est lui') ; widget_control, event.id, get_uvalue=uval ; if n_elements(uval) EQ 0 then return ; case uval of ; 'done':widget_control, event.top, /destroy ; 'dynamic_resize':BEGIN ; widget_control, event.id, get_value = value ; widget_control, ComboboxId, set_value = {dynamic_resize:value} ; END ; 'combobox_select':BEGIN ; widget_control, event.id, get_value = value ; widget_control, ComboboxId, set_value = {combobox_select:value} ; END ; 'value':BEGIN ; widget_control, event.id, get_value = value ; widget_control, ComboboxId, set_value = value ; END ; 'get':BEGIN ; widget_control, ComboboxId, get_value = value ; help, value, /struct ; END ; ELSE: ; endcase ; return ; end ; PRO testwid, _extra = ex ; base=widget_base(/COLUMN) ; print, 'base=', base ; nothing = widget_label(base, value = 'beginning of the test') ; ; ; nothing = cw_combobox_pm(base, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui') ; print, 'cw_combobox_pm ID =', nothing ; ; ; nothing = widget_label(base, value = 'end of the test') ; nothing = widget_text(base, value = '0', uvalue = 'dynamic_resize', /editable) ; nothing = widget_text(base, value = '10', uvalue = 'combobox_select', /editable) ; nothing = widget_text(base, value = '5', uvalue = 'value', /editable) ; nothing = widget_button(base, value = 'get', uvalue = 'get') ; nothing = widget_button(base, value = 'done', uvalue = 'done') ; widget_control, base, /REALIZE ; xmanager,'testwid', base ; return ; end ;---------------------------------------------------------------------- PRO cw_combobox_pm_set_value, id, value ; compile_opt idl2, strictarrsubs ; ComboboxId = widget_info(id,find_by_uname = 'Combobox') if size(value, /type) eq 8 then BEGIN ; this is a structure tagnames = tag_names(value) for tag = 0, n_tags(value)-1 do begin case strtrim(strlowcase(tagnames[tag]), 2) of 'dynamic_resize':widget_control, ComboboxId, dynamic_resize = value.dynamic_resize ; for compatibility 'droplist_select':widget_control, ComboboxId, set_combobox_select = value.droplist_select 'combobox_select':widget_control, ComboboxId, set_combobox_select = value.combobox_select 'value':widget_control, ComboboxId, set_value = value.value ELSE:ras = report('wrong tag name in argument "value" of cw_combobox_pm_set_value') endcase endfor ENDIF ELSE widget_control, ComboboxId, set_value = value return end ;---------------------------------------------------------------------- FUNCTION cw_combobox_pm_get_value, id ; compile_opt idl2, strictarrsubs ; ComboboxId = widget_info(id,find_by_uname = 'Combobox') widget_control, ComboboxId, get_value = cmbbval cmbbtxt = widget_info(ComboboxId, /combobox_gettext) cmbbnumb = widget_info(ComboboxId, /combobox_number) index = (where(cmbbval EQ cmbbtxt))[0] return, {combobox_number:cmbbnumb, combobox_gettext:cmbbtxt $ , combobox_index:index, combobox_value:cmbbval $ , dynamic_resize:widget_info(ComboboxId, /dynamic_resize)} end ;---------------------------------------------------------------------- FUNCTION cw_combobox_pm_event, event ; compile_opt idl2, strictarrsubs ; widget_control, event.id, get_uvalue=uval ; if uval EQ 'Combobox' then $ return, {CW_COMBOBOX_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ , INDEX:event.index, STR:event.str, OUT:0} ; ComboboxId = widget_info(event.handler,find_by_uname = 'Combobox') widget_control, ComboboxId, get_value = cmbbval cmbbtxt = widget_info(ComboboxId, /combobox_gettext) cmbbnumb = widget_info(ComboboxId, /combobox_number) index = (where(cmbbval EQ cmbbtxt))[0] out = 0 case uval OF 'plus':BEGIN if index LT (cmbbnumb - 1) then BEGIN index = index + 1 widget_control, ComboboxId, set_combobox_select = index ENDIF ELSE out = 1 END 'minus':BEGIN if index GT 0 then BEGIN index = index - 1 widget_control, ComboboxId, set_combobox_select = index ENDIF ELSE out = -1 END endcase return, {CW_COMBOBOX_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ , INDEX:index, STR:cmbbtxt, OUT:out} end ;---------------------------------------------------------------------- FUNCTION cw_combobox_pm, parent, VALUE = value, UVALUE = uvalue, UNAME = uname, ROW = row, COLUMN = column, _extra = ex ; compile_opt idl2, strictarrsubs ; IF (N_PARAMS() NE 1) THEN MESSAGE, 'Incorrect number of arguments' ON_ERROR, 2 ;return to caller ; cheking for row and column keywords row = keyword_set(row)*(1-keyword_set(column)) column = keyword_set(column)*(1-keyword_set(row))+(keyword_set(column) EQ row) if NOT keyword_set(uvalue) then uvalue = '' if NOT keyword_set(uname) then uname = '' ; base = widget_base(parent, space = 0 $ , EVENT_FUNC = 'cw_combobox_pm_event' $ , FUNC_GET_VALUE='cw_combobox_pm_get_value' $ , PRO_SET_VALUE='cw_combobox_pm_set_value' $ , UVALUE = uvalue, UNAME = uname, _extra = ex) ; vallen = widget_info(base, string_size = 'm') vallen = 35 + (vallen[0]-1)*max(strlen(value)) if keyword_set(row) THEN BEGIN nothing = widget_button(base, value = '-', uvalue = 'minus', xoffset = 0 $ , yoffset = 5, xsize = 15, ysize = 15) nothing = widget_combobox(base, VALUE = value, UVALUE = 'Combobox', UNAME = 'Combobox' $ , xoffset = 13, yoffset = 0, xsize = vallen) nothing = widget_button(base, value = '+', uvalue = 'plus' $ , xoffset = vallen+11, yoffset = 5 $ , xsize = 15, ysize = 15) ENDIF ELSE BEGIN nothing = widget_combobox(base, VALUE = value, UVALUE = 'Combobox', UNAME = 'Combobox' $ , xoffset = 0, yoffset = 0, xsize = vallen) nothing = widget_button(base, value = '-', uvalue = 'minus' $ , xoffset = vallen/2-15 $ , yoffset = 24, xsize = 15, ysize = 15) nothing = widget_button(base, value = '+', uvalue = 'plus' $ , xoffset = vallen/2 $ , yoffset = 24, xsize = 15, ysize = 15) ENDELSE ; ; widget_control,base,/realize ; return, base end