[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; NAME: cw_slider_pm |
---|
| 6 | ; |
---|
| 7 | ; PURPOSE: widget equivalent a WIDGET_SLIDER sauf qu'en plus on |
---|
| 8 | ; dispose de 2 bouttons + et - pour deplacer le widget de +/- 1. |
---|
| 9 | ; |
---|
| 10 | ; CATEGORY: compound widget (aide a l''ecriture des widgets) |
---|
| 11 | ; |
---|
| 12 | ; CALLING SEQUENCE: id=cw_slider_pm(parent) |
---|
| 13 | ; |
---|
| 14 | ; INPUTS: |
---|
| 15 | ; Parent: The widget ID of the parent widget. |
---|
| 16 | ; |
---|
| 17 | ; KEYWORD PARAMETERS:tous ceux de WIDGET_SLIDER |
---|
| 18 | ; |
---|
| 19 | ; OUTPUTS: |
---|
| 20 | ; The returned value of this function is the widget ID of the |
---|
| 21 | ; newly-created animation widget. |
---|
| 22 | ; |
---|
| 23 | ; COMMON BLOCKS: none |
---|
| 24 | ; |
---|
| 25 | ; SIDE EFFECTS: |
---|
| 26 | ; |
---|
| 27 | ; Widget Events Returned by the CW_SLIDER_PM Widget |
---|
| 28 | ; |
---|
| 29 | ; Slider widgets generate events when the mouse is used to change |
---|
| 30 | ; their value. The event structure returned by the WIDGET_EVENT |
---|
| 31 | ; function is defined by the following statement: |
---|
| 32 | ; |
---|
| 33 | ; {CW_SLIDER_PM, ID:0L, TOP:0L, HANDLER:0L, VALUE:0L, DRAG:0, OUT:0} |
---|
| 34 | ; |
---|
| 35 | ; ID is the widget ID of the button generating the event. TOP is the |
---|
| 36 | ; widget ID of the top level widget containing ID. |
---|
| 37 | ; HANDLER contains the widget ID of the widget associated with the |
---|
| 38 | ; handler routine. |
---|
| 39 | ; VALUE returns the new value of the slider. |
---|
| 40 | ; DRAG returns integer 1 if the slider event was generated as part of |
---|
| 41 | ; a drag operation, or zero if the event was generated when the user |
---|
| 42 | ; had finished positioning the slider. Note that the slider widget |
---|
| 43 | ; only generates events during the drag operation if the DRAG keyword |
---|
| 44 | ; is set, and if the application is running under Motif. When the |
---|
| 45 | ; DRAG keyword is set, the DRAG field can be used to avoid |
---|
| 46 | ; computationally expensive operations until the user releases the |
---|
| 47 | ; slider. |
---|
| 48 | ; OUT:c''est un entier qui peut prendre 3 valeurs: |
---|
| 49 | ; 1 : si on appuie sur + alors que le slider est deja aux max. rq: |
---|
| 50 | ; ds ce cas le slider reste au max |
---|
| 51 | ; -1: si on appuie sur - alors que le slider est deja aux min. rq: |
---|
| 52 | ; ds ce cas le slider reste au min |
---|
| 53 | ; 0 : ds les autres cas! |
---|
| 54 | ; |
---|
| 55 | ; Keywords to WIDGET_CONTROL |
---|
| 56 | ; |
---|
| 57 | ; A number of keywords to the WIDGET_CONTROL procedure affect the |
---|
| 58 | ; behavior of cw_slider_pm widget: GET_VALUE and SET_VALUE. |
---|
| 59 | ; 1) GET_VALUE |
---|
| 60 | ; widget_control,wid_id,get_value=resultat |
---|
| 61 | ; retourne ds la variable resultat une structure de 2 elements dont |
---|
| 62 | ; les noms sont inspires des mots cles que l''on peut passer a |
---|
| 63 | ; widget_control qd on utilise WIDGET_SLIDER: |
---|
| 64 | ; VALUE:the value setting of the widget |
---|
| 65 | ; SLIDER_MIN_MAX: a 2 elements array: The minimum and the |
---|
| 66 | ; maximum value of the range encompassed by the slider |
---|
| 67 | ; 2) SET_VALUE |
---|
| 68 | ; widget_control,wid_id,set_value=impose |
---|
| 69 | ; permet de modifier l''etat de la slider bar comme on peut le faire |
---|
| 70 | ; pour WIDGET_SLIDER. Impose peut etre: |
---|
| 71 | ; a) un entier: donne la nouvelle position of the slider. |
---|
| 72 | ; b) une structure qui peut avoir comme elements (de 1 a 3): |
---|
| 73 | ; VALUE:un entier qui donne la nouvelle position of the slider. |
---|
| 74 | ; SLIDER_MIN:Set to a new minimum value for the specified |
---|
| 75 | ; slider widget. |
---|
| 76 | ; SLIDER_MAX:Set to a new minimum value for the specified |
---|
| 77 | ; slider widget. |
---|
| 78 | ; |
---|
| 79 | ; RESTRICTIONS: |
---|
| 80 | ; |
---|
| 81 | ; EXAMPLE: cf utiliser le programme founit i-dessous: testwid et la |
---|
| 82 | ; procedure associee, testwid_event. |
---|
| 83 | ; |
---|
| 84 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
| 85 | ; 5/9/1999 |
---|
| 86 | ;- |
---|
| 87 | ;------------------------------------------------------------ |
---|
| 88 | ;------------------------------------------------------------ |
---|
| 89 | ;------------------------------------------------------------ |
---|
| 90 | ; PRO testwid_event, event |
---|
| 91 | ; ; help, event, /STRUCT |
---|
| 92 | ; SliderBarId = widget_info(event.top,find_by_uname = 'c''est lui') |
---|
| 93 | ; widget_control, event.id, get_uvalue=uval |
---|
| 94 | ; if n_elements(uval) EQ 0 then return |
---|
| 95 | ; case uval of |
---|
| 96 | ; 'done':widget_control, event.top, /destroy |
---|
| 97 | ; 'slider_min':BEGIN |
---|
| 98 | ; widget_control, event.id, get_value = value |
---|
| 99 | ; widget_control, SliderBarId, set_value = {slider_min:value} |
---|
| 100 | ; END |
---|
| 101 | ; 'slider_max':BEGIN |
---|
| 102 | ; widget_control, event.id, get_value = value |
---|
| 103 | ; widget_control, SliderBarId, set_value = {slider_max:value} |
---|
| 104 | ; END |
---|
| 105 | ; 'slider_value':BEGIN |
---|
| 106 | ; widget_control, event.id, get_value = value |
---|
| 107 | ; widget_control, SliderBarId, set_value = value |
---|
| 108 | ; END |
---|
| 109 | ; 'get':BEGIN |
---|
| 110 | ; widget_control, SliderBarId, get_value = value |
---|
| 111 | ; help, value, /struct |
---|
| 112 | ; print, value.slider_min_max |
---|
| 113 | ; END |
---|
| 114 | ; ELSE: |
---|
| 115 | ; endcase |
---|
| 116 | ; return |
---|
| 117 | ; end |
---|
| 118 | ; PRO testwid, _extra = ex |
---|
| 119 | ; base=widget_base(/COLUMN) |
---|
| 120 | ; print, 'base=', base |
---|
| 121 | ; nothing = widget_label(base, value = 'beginning of the test') |
---|
| 122 | ; ; |
---|
| 123 | ; nothing = cw_slider_pm(base, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui') |
---|
| 124 | ; print, 'cw_slider_pm ID =', nothing |
---|
| 125 | ; ; |
---|
| 126 | ; nothing = widget_label(base, value = 'end of the test') |
---|
| 127 | ; nothing = widget_text(base, value = '0', uvalue = 'slider_min', /editable) |
---|
| 128 | ; nothing = widget_text(base, value = '10', uvalue = 'slider_max', /editable) |
---|
| 129 | ; nothing = widget_text(base, value = '5', uvalue = 'slider_value', /editable) |
---|
| 130 | ; nothing = widget_button(base, value = 'get', uvalue = 'get') |
---|
| 131 | ; nothing = widget_button(base, value = 'done', uvalue = 'done') |
---|
| 132 | ; widget_control, base, /REALIZE |
---|
| 133 | ; xmanager,'testwid', base |
---|
| 134 | ; return |
---|
| 135 | ; end |
---|
| 136 | ;---------------------------------------------------------------------- |
---|
| 137 | PRO cw_slider_pm_set_value, id, value |
---|
| 138 | SliderBarId = widget_info(id,find_by_uname = 'SliderBar') |
---|
| 139 | if size(value, /type) eq 8 then BEGIN ; this is a structure |
---|
| 140 | tagnames = tag_names(value) |
---|
| 141 | for tag = 0, n_tags(value)-1 do begin |
---|
| 142 | case strtrim(strlowcase(tagnames[tag]), 2) of |
---|
| 143 | 'slider_min':widget_control, SliderBarId, set_slider_min = value.slider_min |
---|
| 144 | 'slider_max':widget_control, SliderBarId, set_slider_max = value.slider_max |
---|
| 145 | 'value':widget_control, SliderBarId, set_value = value.value |
---|
| 146 | ELSE:ras = report('mauvais nom de l''argument de la structure ds cw_slider_pm_set_value') |
---|
| 147 | endcase |
---|
| 148 | endfor |
---|
| 149 | ENDIF ELSE widget_control, SliderBarId, set_value = value[0] |
---|
| 150 | return |
---|
| 151 | end |
---|
| 152 | ;---------------------------------------------------------------------- |
---|
| 153 | FUNCTION cw_slider_pm_get_value, id |
---|
| 154 | SliderBarId = widget_info(id,find_by_uname = 'SliderBar') |
---|
| 155 | widget_control, SliderBarId, get_value = value |
---|
| 156 | return, {value:value, slider_min_max:widget_info(SliderBarId, /slider_min_max)} |
---|
| 157 | end |
---|
| 158 | ;---------------------------------------------------------------------- |
---|
| 159 | FUNCTION cw_slider_pm_event, event |
---|
| 160 | widget_control, event.id, get_uvalue=uval |
---|
| 161 | ; |
---|
| 162 | if uval EQ 'SliderBar' then $ |
---|
| 163 | return, {CW_SLIDER_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ |
---|
| 164 | , VALUE:event.value, OUT:0} |
---|
| 165 | ; |
---|
| 166 | SliderBarId = widget_info(event.handler,find_by_uname = 'SliderBar') |
---|
| 167 | minmax = widget_info(SliderBarId, /SLIDER_MIN_MAX) |
---|
| 168 | widget_control, SliderBarId, get_value = value |
---|
| 169 | case uval OF |
---|
| 170 | 'plus':BEGIN |
---|
| 171 | if value NE minmax[1] then widget_control, SliderBarId,set_value = value+1 |
---|
| 172 | return, {CW_SLIDER_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ |
---|
| 173 | , VALUE:(value+1) < minmax[1], OUT:long(value eq minmax[1])} |
---|
| 174 | END |
---|
| 175 | 'minus':BEGIN |
---|
| 176 | if value NE minmax[0] then widget_control, SliderBarId,set_value = value-1 |
---|
| 177 | return, {CW_SLIDER_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ |
---|
| 178 | , VALUE:0 > (value-1), OUT:-long(value EQ minmax[0])} |
---|
| 179 | END |
---|
| 180 | endcase |
---|
| 181 | end |
---|
| 182 | ;---------------------------------------------------------------------- |
---|
| 183 | FUNCTION cw_slider_pm, parent, ROW = row, COLUMN = column, VERTICAL = vertical, UVALUE = uvalue, UNAME = uname, _extra = ex |
---|
| 184 | |
---|
| 185 | IF (N_PARAMS() NE 1) THEN MESSAGE, 'Incorrect number of arguments' |
---|
| 186 | ON_ERROR, 2 ;return to caller |
---|
| 187 | ; |
---|
| 188 | ; cheking exclusive keywords |
---|
| 189 | column = (keyword_set(column)*(1-keyword_set(row))+keyword_set(vertical)) < 1 |
---|
| 190 | row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column) |
---|
| 191 | if NOT keyword_set(uvalue) then uvalue = '' |
---|
| 192 | if NOT keyword_set(uname) then uname = '' |
---|
| 193 | base = widget_base(parent, space = 1, xpad = 1, ypad = 1 $ |
---|
| 194 | , EVENT_FUNC = 'cw_slider_pm_event' $ |
---|
| 195 | , FUNC_GET_VALUE='cw_slider_pm_get_value' $ |
---|
| 196 | , PRO_SET_VALUE='cw_slider_pm_set_value' $ |
---|
| 197 | , ROW = row, COLUMN = column, UVALUE = uvalue, UNAME = uname, _extra = ex) |
---|
| 198 | ; |
---|
| 199 | if keyword_set(vertical) then BEGIN |
---|
| 200 | if keyword_set(row) then begin |
---|
| 201 | nothing = widget_slider(base, /VERTICAL, UVALUE = 'SliderBar', UNAME = 'SliderBar', _extra = ex) |
---|
| 202 | base1 = widget_base(base, space = 1, xpad = 1, ypad = 1 $ |
---|
| 203 | , /column, /align_center) |
---|
| 204 | nothing = widget_button(base1,value= '+', uvalue='plus', xsize = 15, ysize = 15) |
---|
| 205 | nothing = widget_button(base1,value= '-', uvalue='minus', xsize = 15, ysize = 15) |
---|
| 206 | ENDIF ELSE BEGIN |
---|
| 207 | nothing = widget_button(base,value= '+', uvalue='plus', xsize = 15, ysize = 15) |
---|
| 208 | nothing = widget_slider(base, /VERTICAL, UVALUE = 'SliderBar', UNAME = 'SliderBar', _extra = ex) |
---|
| 209 | nothing = widget_button(base,value= '-', uvalue='minus', xsize = 15, ysize = 15) |
---|
| 210 | ENDELSE |
---|
| 211 | ENDIF ELSE BEGIN |
---|
| 212 | if keyword_set(row) then begin |
---|
| 213 | nothing = widget_button(base,value= '-', uvalue='minus', xsize = 15, ysize = 15) |
---|
| 214 | nothing = widget_slider(base, UVALUE = 'SliderBar', UNAME = 'SliderBar', _extra = ex) |
---|
| 215 | nothing = widget_button(base,value= '+', uvalue='plus', xsize = 15, ysize = 15) |
---|
| 216 | ENDIF ELSE BEGIN |
---|
| 217 | nothing = widget_slider(base, UVALUE = 'SliderBar', UNAME = 'SliderBar', _extra = ex) |
---|
| 218 | base1 = widget_base(base, space = 1, xpad = 1, ypad = 1 $ |
---|
| 219 | , /row, /align_center) |
---|
| 220 | nothing = widget_button(base1,value= '-', uvalue='minus', xsize = 15, ysize = 15) |
---|
| 221 | nothing = widget_button(base1,value= '+', uvalue='plus', xsize = 15, ysize = 15) |
---|
| 222 | ENDELSE |
---|
| 223 | ENDELSE |
---|
| 224 | ; |
---|
| 225 | ; |
---|
| 226 | return, base |
---|
| 227 | end |
---|