;+ ; ; @file_comments ; ; @categories ; Compound widget ; ; @param VALUE ; It is the default tick mark value (a floating-point number). ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- ; FUNCTION decvalue, value ; compile_opt idl2, strictarrsubs ; a = float(value[0]) return, strtrim(string(floor(a) + 0.1*indgen(10), format = '(f15.1)'), 2) end ; ;+ ; ; @file_comments ; ; @categories ; Compound widget ; ; @param VALUE ; It is the default tick mark value (a floating-point number). ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- ; FUNCTION decind, value ; compile_opt idl2, strictarrsubs ; a = float(value[0]) return, round(10*(a - floor(a))) ; !! computation accuracy end ; ;+ ; ; @file_comments ; ; @categories ; Compound widget ; ; @param ID ; ; @param VALUE ; It is the default tick mark value (a floating-point number). ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- ; PRO cw_slider_pm_set_value, id, value ; compile_opt idl2, strictarrsubs ; sbid = widget_info(id, find_by_uname = 'SliderBar') dcid = widget_info(id, find_by_uname = 'decimal') minmax = widget_info(sbid, /SLIDER_MIN_MAX) 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 'slider_min':BEGIN ; IF float(value.slider_min[0]) LT minmax[1] THEN BEGIN minmax[0] = value.slider_min[0] widget_control, sbid, set_slider_min = floor(float(value.slider_min[0])) valuedc = float(widget_info(dcid, /combobox_gettext)) IF valuedc LT value.slider_min THEN BEGIN widget_control, sbid, set_value = floor(float(value.slider_min[0])) widget_control, dcid, set_value = decvalue(value.slider_min) widget_control, dcid, set_combobox_select = decind(value.slider_min) ENDIF ; ENDIF end 'slider_max':BEGIN ; IF float(value.slider_max[0]) GT minmax[0] THEN BEGIN minmax[1] = value.slider_max[0] widget_control, sbid, set_slider_max = ceil(float(value.slider_max[0])) valuedc = float(widget_info(dcid, /combobox_gettext)) IF valuedc GT value.slider_max THEN BEGIN widget_control, sbid, set_value = ceil(float(value.slider_max[0])) widget_control, dcid, set_value = decvalue(value.slider_max) widget_control, dcid, set_combobox_select = decind(value.slider_max) ENDIF ; ENDIF end 'value':IF float(value.value[0]) GE minmax[0] $ AND float(value.value[0]) LE minmax[1] THEN value2 = float(value.value[0]) ELSE:ras = report('wrong tag name in argument "value" of cw_slider_pm_set_value') endcase endfor ENDIF ELSE BEGIN IF float(value[0]) GE minmax[0] $ AND float(value[0]) LE minmax[1] THEN value2 = float(value[0]) ENDELSE IF n_elements(value2) NE 0 THEN BEGIN widget_control, sbid, set_value = fix(value2) widget_control, dcid, set_value = decvalue(value2) widget_control, dcid, set_combobox_select = decind(value2) ENDIF return end ; ;+ ; ; @file_comments ; ; ; @categories ; Compound widget ; ; @param ID ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- ; FUNCTION cw_slider_pm_get_value, id ; compile_opt idl2, strictarrsubs ; sbid = widget_info(id, find_by_uname = 'SliderBar') dcid = widget_info(id, find_by_uname = 'decimal') minmax = widget_info(sbid, /SLIDER_MIN_MAX) value = float(widget_info(dcid, /combobox_gettext)) return, {value:value, slider_min_max:minmax} end ; ;+ ; ; @file_comments ; ; @categories ; Compound widget ; ; @param EVENT ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- ; FUNCTION cw_slider_pm_event, event ; compile_opt idl2, strictarrsubs ; widget_control, event.id, get_uvalue = uval ; sbid = widget_info(event.handler, find_by_uname = 'SliderBar') dcid = widget_info(event.handler, find_by_uname = 'decimal') minmax = widget_info(sbid, /SLIDER_MIN_MAX) IF uval EQ 'decimal' THEN value = float(event.str) $ ELSE value = float(widget_info(dcid, /combobox_gettext)) out = 0 ; defaut case case uval OF 'plus': if (value + 1) LE minmax[1] then value2 = value + 1 ELSE out = 1 'minus':if (value - 1) GE minmax[0] then value2 = value - 1 ELSE out = -1 'SliderBar':if (event.value + value - floor(value)) LE minmax[1] THEN value2 = event.value + value - floor(value) 'decimal':BEGIN CASE 1 OF value GT minmax[1]: value2 = minmax[1] value LT minmax[0]: value2 = minmax[0] ELSE: ENDCASE END ELSE: ENDCASE IF n_elements(value2) NE 0 THEN BEGIN value = value2 widget_control, sbid, set_value = floor(value) widget_control, dcid, set_value = decvalue(value) widget_control, dcid, set_combobox_select = decind(value) ENDIF return, {CW_SLIDER_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ , VALUE:value, OUT:OUT} end ; ;+ ; ; @file_comments ; Like WIDGET_SLIDER but here, their are 2 buttons + and - to move the widget from +/- 1 ; ; @categories ; Compound widget ; ; @param PARENT {in}{required} ; The widget ID of the parent widget. ; ; @keyword UVALUE ; The user value to be associated with the widget. ; ; @keyword UNAME ; The user name to be associated with the widget. ; ; @keyword VALUE ; ; @keyword MAXIMUM ; ; @keyword MINIMUM ; ; @keyword STRMINLEN ; ; @keyword _EXTRA ; Used to pass keywords ; ; @returns ; The returned value of this function is the widget ID of the ; newly-created animation widget. ; ; @restrictions ; ; Widget Events Returned by the CW_SLIDER_PM Widget ; ; Slider widgets generate events when the mouse is used to change ; their value. The event structure returned by the WIDGET_EVENT ; function is defined by the following statement: ; ; {CW_SLIDER_PM, ID:0L, TOP:0L, HANDLER:0L, VALUE:0L, DRAG:0, OUT:0} ; ; ID is the widget ID of the button generating the event. TOP is the ; widget ID of the top level widget containing ID. ; HANDLER contains the widget ID of the widget associated with the ; handler routine. ; VALUE returns the new value of the slider. ; DRAG returns integer 1 if the slider event was generated as part of ; a drag operation, or zero if the event was generated when the user ; had finished positioning the slider. Note that the slider widget ; only generates events during the drag operation if the DRAG keyword ; is set, and if the application is running under Motif. When the ; DRAG keyword is set, the DRAG field can be used to avoid ; computationally expensive operations until the user releases the ; slider. ; OUT:It is an integer which can take 3 values: ; 1 : If we press + when the index is already at the max ; Comment: In this case, the index stay at the max ; -1: If we press - when the index is already at the min ; Comment: In this case, the index stay at the min ; 0 : In other cases ; ; 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 ; Send back in the result variable a structure of 2 elements whose name ; are inspired from keywords we can pass at ; widget_control when we use WIDGET_SLIDER: ; VALUE:the value setting of the widget ; SLIDER_MIN_MAX: a 2 elements array: The minimum and the ; maximum value of the range encompassed by the slider ; 2) SET_VALUE ; widget_control,wid_id,set_value=impose ; Allows to modify the state of the combobox like we can do it for ; WIDGET_COMBOBOX. May impose: ; a) a integer: give the new position of the slider. ; b) A structure which can have for elements (from 1 to 3): ; VALUE: an integer which give the new position of the slider ; SLIDER_MIN:Set to a new minimum value for the specified ; slider widget. ; SLIDER_MAX:Set to a new minimum value for the specified ; slider widget. ; ; ; @examples ; See the program provided above (testwid and the associated procedure, testwid_event). ; ; @history ; Sebastien Masson (smasson\@lodyc.jussieu.fr) ; 5/9/1999 ; ; @version ; $Id$ ; ; @todo ; seb: documenter ; ;- ; FUNCTION cw_slider_pm, parent, MAXIMUM = maximum, MINIMUM = minimum $ , STRMINLEN = strminlen, VALUE = value, UVALUE = uvalue $ , UNAME = uname, title = title, _EXTRA = ex ; compile_opt idl2, strictarrsubs ; IF (N_PARAMS() NE 1) THEN ras = report('Incorrect number of arguments') ON_ERROR, 2 ;return to caller ; if n_elements(minimum) NE 0 then minimum = floor(minimum) ELSE minimum = 0 if n_elements(maximum) NE 0 then maximum = ceil(maximum) ELSE maximum = 100 if NOT keyword_set(title) then title = ' ' ; ; checking exclusive keywords column = (keyword_set(column)*(1-keyword_set(row))+keyword_set(vertical)) < 1 row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column) if NOT keyword_set(uvalue) then uvalue = '' if NOT keyword_set(uname) then uname = '' base = widget_base(parent $ , EVENT_FUNC = 'cw_slider_pm_event' $ , FUNC_GET_VALUE = 'cw_slider_pm_get_value' $ , PRO_SET_VALUE = 'cw_slider_pm_set_value' $ , space = 0, UVALUE = uvalue, UNAME = uname, _extra = ex) ; mlen = (widget_info(base, string_size = 'm'))[0] xsize = mlen*strlen(title) dummyid = widget_label(base, value = title, xsize = xsize) dummyid = widget_button(base, value = '-', uvalue = 'minus' $ , yoffset = 15, xsize = 15, ysize = 15) dummyid = widget_button(base, value = '+', uvalue = 'plus' $ , xoffset = 15, yoffset = 15, xsize = 15, ysize = 15) xoff = 30 > xsize lenstr = max(strlen(strtrim([minimum, maximum], 1))) if keyword_set(strminlen) then lenstr = strminlen > lenstr ; xsize = 35 + mlen*(lenstr+1)+3*(lenstr lt 4) xsize = 35 + mlen*(lenstr+2) dummyid = widget_combobox(base, value = decvalue(minimum) $ , UVALUE = 'decimal', UNAME = 'decimal' $ , xoffset = xoff, yoffset = 2, xsize = xsize) dummyid = widget_slider(base, MAXIMUM = maximum, MINIMUM = minimum, UVALUE = 'SliderBar' $ , UNAME = 'SliderBar', /suppress_value, /drag $ , yoffset = 30, xsize = xoff + xsize) ; if keyword_set(value) then cw_slider_pm_set_value, base, value ; return, base end