[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; NAME: cw_droplist_pm |
---|
| 6 | ; |
---|
| 7 | ; PURPOSE: widget equivalent a WIDGET_DROPLIST 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_droplist_pm(parent) |
---|
| 13 | ; |
---|
| 14 | ; INPUTS: |
---|
| 15 | ; Parent: The widget ID of the parent widget. |
---|
| 16 | ; |
---|
| 17 | ; KEYWORD PARAMETERS:tous ceux de WIDGET_DROPLIST |
---|
| 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 Droplist Widgets |
---|
| 28 | ; |
---|
| 29 | ; Pressing the mouse button while the mouse cursor is over an |
---|
| 30 | ; element of a droplist widget causes the widget to change the label |
---|
| 31 | ; on the droplist button and to generate an event. The appearance of |
---|
| 32 | ; any previously selected element is restored to normal at the same |
---|
| 33 | ; time. The event structure returned by the WIDGET_EVENT function is |
---|
| 34 | ; defined by the following statement: |
---|
| 35 | ; |
---|
| 36 | ; { CW_DROPLIST_PM, ID:0L, TOP:0L, HANDLER:0L, INDEX:0L, OUT:0 } |
---|
| 37 | ; |
---|
| 38 | ; The first three fields are the standard fields found in every |
---|
| 39 | ; widget event. |
---|
| 40 | ; INDEX returns the index of the selected item. This can be used to |
---|
| 41 | ; index the array of names originally used to set the widget''s |
---|
| 42 | ; value |
---|
| 43 | ; OUT:c''est un entier qui peut prendre 3 valeurs: |
---|
| 44 | ; 1 : si on appuie sur + alors que l''index est deja aux max. rq: |
---|
| 45 | ; ds ce cas l''index reste au max |
---|
| 46 | ; -1: si on appuie sur - alors que l''index est deja aux min. rq: |
---|
| 47 | ; ds ce cas l''index reste au min |
---|
| 48 | ; 0 : ds les autres cas! |
---|
| 49 | ; |
---|
| 50 | ; Keywords to WIDGET_CONTROL |
---|
| 51 | ; |
---|
| 52 | ; A number of keywords to the WIDGET_CONTROL procedure affect the |
---|
| 53 | ; behavior of cw_slider_pm widget: GET_VALUE and SET_VALUE. |
---|
| 54 | ; 1) GET_VALUE |
---|
| 55 | ; widget_control,wid_id,get_value=resultat |
---|
| 56 | ; retourne ds la variable resultat une structure de 3 elements dont |
---|
| 57 | ; les noms sont inspires des mots cles que l''on peut passer a |
---|
| 58 | ; widget_control qd on utilise WIDGET_DROPLIST: |
---|
| 59 | ; DROPLIST_NUMBER: the number of elements currently |
---|
| 60 | ; contained in the specified droplist widget. |
---|
| 61 | ; DROPLIST_SELECT: the zero-based number of the |
---|
| 62 | ; currently-selected element (i.e., the currently-displayed |
---|
| 63 | ; element) in the specified droplist widget. |
---|
| 64 | ; DYNAMIC_RESIZE: a True value (1) if the widget specified |
---|
| 65 | ; by Widget_ID is a button, droplist, or label widget that |
---|
| 66 | ; has had its DYNAMIC_RESIZE attribute set. Otherwise, |
---|
| 67 | ; False (0) is returned. |
---|
| 68 | ; 2) SET_VALUE |
---|
| 69 | ; widget_control,wid_id,set_value=impose |
---|
| 70 | ; permet de modifier l''etat de la droplist comme on peut le faire |
---|
| 71 | ; pour WIDGET_DROPLIST Impose peut etre: |
---|
| 72 | ; a) The contents of the list widget (string or string array) |
---|
| 73 | ; b) une structure qui peut avoir comme elements (de 1 a 3): |
---|
| 74 | ; DYNAMIC_RESIZE:Set this keyword to activate (if set to 1) |
---|
| 75 | ; or deactivate (if set to 0) dynamic resizing of the |
---|
| 76 | ; specified CW_DROPLIST_PM widget (see the documentation |
---|
| 77 | ; for the DYNAMIC_RESIZE keyword to WIDGET_DROPLIST |
---|
| 78 | ; procedure for more information about dynamic widget |
---|
| 79 | ; resizing). |
---|
| 80 | ; DROPLIST_SELECT:Set this keyword to return the zero-based |
---|
| 81 | ; number of the currently-selected element (i.e., the |
---|
| 82 | ; currently-displayed element) in the specified droplist |
---|
| 83 | ; widget. |
---|
| 84 | ; VALUE: The contents of the list widget (string or string |
---|
| 85 | ; array) |
---|
| 86 | ; |
---|
| 87 | ; RESTRICTIONS: |
---|
| 88 | ; |
---|
| 89 | ; EXAMPLE: cf utiliser le programme founit i-dessous: testwid et la |
---|
| 90 | ; procedure associee, testwid_event. |
---|
| 91 | ; |
---|
| 92 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
| 93 | ; 6/9/1999 |
---|
| 94 | ; |
---|
| 95 | ;- |
---|
| 96 | ;------------------------------------------------------------ |
---|
| 97 | ;------------------------------------------------------------ |
---|
| 98 | ;------------------------------------------------------------ |
---|
| 99 | ; PRO testwid_event, event |
---|
| 100 | ; ; help, event, /STRUCT |
---|
| 101 | ; DroplistId = widget_info(event.top,find_by_uname = 'c''est lui') |
---|
| 102 | ; widget_control, event.id, get_uvalue=uval |
---|
| 103 | ; if n_elements(uval) EQ 0 then return |
---|
| 104 | ; case uval of |
---|
| 105 | ; 'done':widget_control, event.top, /destroy |
---|
| 106 | ; 'dynamic_resize':BEGIN |
---|
| 107 | ; widget_control, event.id, get_value = value |
---|
| 108 | ; widget_control, DroplistId, set_value = {dynamic_resize:value} |
---|
| 109 | ; END |
---|
| 110 | ; 'droplist_select':BEGIN |
---|
| 111 | ; widget_control, event.id, get_value = value |
---|
| 112 | ; widget_control, DroplistId, set_value = {droplist_select:value} |
---|
| 113 | ; END |
---|
| 114 | ; 'value':BEGIN |
---|
| 115 | ; widget_control, event.id, get_value = value |
---|
| 116 | ; widget_control, DroplistId, set_value = value |
---|
| 117 | ; END |
---|
| 118 | ; 'get':BEGIN |
---|
| 119 | ; widget_control, DroplistId, get_value = value |
---|
| 120 | ; help, value, /struct |
---|
| 121 | ; END |
---|
| 122 | ; ELSE: |
---|
| 123 | ; endcase |
---|
| 124 | ; return |
---|
| 125 | ; end |
---|
| 126 | ; PRO testwid, _extra = ex |
---|
| 127 | ; base=widget_base(/COLUMN) |
---|
| 128 | ; print, 'base=', base |
---|
| 129 | ; nothing = widget_label(base, value = 'beginning of the test') |
---|
| 130 | ; ; |
---|
| 131 | ; nothing = cw_droplist_pm(base, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui') |
---|
| 132 | ; print, 'cw_droplist_pm ID =', nothing |
---|
| 133 | ; ; |
---|
| 134 | ; nothing = widget_label(base, value = 'end of the test') |
---|
| 135 | ; nothing = widget_text(base, value = '0', uvalue = 'dynamic_resize', /editable) |
---|
| 136 | ; nothing = widget_text(base, value = '10', uvalue = 'droplist_select', /editable) |
---|
| 137 | ; nothing = widget_text(base, value = '5', uvalue = 'value', /editable) |
---|
| 138 | ; nothing = widget_button(base, value = 'get', uvalue = 'get') |
---|
| 139 | ; nothing = widget_button(base, value = 'done', uvalue = 'done') |
---|
| 140 | ; widget_control, base, /REALIZE |
---|
| 141 | ; xmanager,'testwid', base |
---|
| 142 | ; return |
---|
| 143 | ; end |
---|
| 144 | ;---------------------------------------------------------------------- |
---|
| 145 | PRO cw_droplist_pm_set_value, id, value |
---|
| 146 | DroplistId = widget_info(id,find_by_uname = 'Droplist') |
---|
| 147 | if size(value, /type) eq 8 then BEGIN ; this is a structure |
---|
| 148 | tagnames = tag_names(value) |
---|
| 149 | for tag = 0, n_tags(value)-1 do begin |
---|
| 150 | case strtrim(strlowcase(tagnames[tag]), 2) of |
---|
| 151 | 'dynamic_resize':widget_control, DroplistId, dynamic_resize = value.dynamic_resize |
---|
| 152 | 'droplist_select':widget_control, DroplistId, set_droplist_select = value.droplist_select |
---|
| 153 | 'value':widget_control, DroplistId, set_value = value.value |
---|
| 154 | ELSE:ras = report('mauvais nom de l''argument de la structure ds cw_droplist_pm_set_value') |
---|
| 155 | endcase |
---|
| 156 | endfor |
---|
| 157 | ENDIF ELSE widget_control, DroplistId, set_value = value |
---|
| 158 | return |
---|
| 159 | end |
---|
| 160 | ;---------------------------------------------------------------------- |
---|
| 161 | FUNCTION cw_droplist_pm_get_value, id |
---|
| 162 | DroplistId = widget_info(id,find_by_uname = 'Droplist') |
---|
| 163 | return, {droplist_number:widget_info(DroplistId, /droplist_number) $ |
---|
| 164 | , droplist_select:widget_info(DroplistId, /droplist_select) $ |
---|
| 165 | , dynamic_resize:widget_info(DroplistId, /dynamic_resize)} |
---|
| 166 | end |
---|
| 167 | ;---------------------------------------------------------------------- |
---|
| 168 | FUNCTION cw_droplist_pm_event, event |
---|
| 169 | widget_control, event.id, get_uvalue=uval |
---|
| 170 | ; |
---|
| 171 | if uval EQ 'Droplist' then $ |
---|
| 172 | return, {CW_DROPLIST_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ |
---|
| 173 | , INDEX:event.index, OUT:0} |
---|
| 174 | ; |
---|
| 175 | DroplistId = widget_info(event.handler,find_by_uname = 'Droplist') |
---|
| 176 | index = widget_info(DroplistId, /droplist_select) |
---|
| 177 | case uval OF |
---|
| 178 | 'plus':BEGIN |
---|
| 179 | indexmax = widget_info(DroplistId, /droplist_number)-1 |
---|
| 180 | if index NE indexmax then widget_control, DroplistId,set_droplist_select = index+1 |
---|
| 181 | return, {CW_DROPLIST_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ |
---|
| 182 | , INDEX:(index+1) < indexmax, OUT:long(index EQ indexmax)} |
---|
| 183 | END |
---|
| 184 | 'minus':BEGIN |
---|
| 185 | if index NE 0 then widget_control, DroplistId,set_droplist_select = index-1 |
---|
| 186 | return, {CW_DROPLIST_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ |
---|
| 187 | , INDEX:0 > (index-1), OUT:-long(index EQ 0)} |
---|
| 188 | END |
---|
| 189 | endcase |
---|
| 190 | end |
---|
| 191 | ;---------------------------------------------------------------------- |
---|
| 192 | FUNCTION cw_droplist_pm, parent,UVALUE = uvalue, UNAME = uname, ROW = row, COLUMN = column, _extra = ex |
---|
| 193 | |
---|
| 194 | IF (N_PARAMS() NE 1) THEN MESSAGE, 'Incorrect number of arguments' |
---|
| 195 | ON_ERROR, 2 ;return to caller |
---|
| 196 | ; cheking for row and column keywords |
---|
| 197 | row = keyword_set(row)*(1-keyword_set(column)) |
---|
| 198 | column = keyword_set(column)*(1-keyword_set(row))+(keyword_set(column) EQ row) |
---|
| 199 | if NOT keyword_set(uvalue) then uvalue = '' |
---|
| 200 | if NOT keyword_set(uname) then uname = '' |
---|
| 201 | ; |
---|
| 202 | base = widget_base(parent, space = 1, xpad = 1, ypad = 1, ROW = row, COLUMN = column $ |
---|
| 203 | , EVENT_FUNC = 'cw_droplist_pm_event' $ |
---|
| 204 | , FUNC_GET_VALUE='cw_droplist_pm_get_value' $ |
---|
| 205 | , PRO_SET_VALUE='cw_droplist_pm_set_value' $ |
---|
| 206 | , UVALUE = uvalue, UNAME = uname, _extra = ex) |
---|
| 207 | ; |
---|
| 208 | if keyword_set(row) THEN nothing = widget_button(base,value= '-', uvalue= 'minus') |
---|
| 209 | nothing = widget_droplist(base, UVALUE = 'Droplist', UNAME = 'Droplist', _extra = ex) |
---|
| 210 | if keyword_set(column) then begin |
---|
| 211 | base1 = widget_base(base, /row, /align_center, space = 1, xpad = 1, ypad = 1) |
---|
| 212 | nothing = widget_button(base1,value= '-', uvalue= 'minus', xsize = 20, ysize = 20) |
---|
| 213 | nothing = widget_button(base1,value= '+', uvalue= 'plus', xsize = 20, ysize = 20) |
---|
| 214 | ENDIF ELSE nothing = widget_button(base,value= '+', uvalue= 'plus') |
---|
| 215 | ; |
---|
| 216 | ; widget_control,base,/realize |
---|
| 217 | ; |
---|
| 218 | return, base |
---|
| 219 | end |
---|