1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; NAME: cw_combobox_pm |
---|
6 | ; |
---|
7 | ; PURPOSE: widget equivalent a WIDGET_COMBOBOX 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_combobox_pm(parent) |
---|
13 | ; |
---|
14 | ; INPUTS: |
---|
15 | ; Parent: The widget ID of the parent widget. |
---|
16 | ; |
---|
17 | ; KEYWORD PARAMETERS:tous ceux de WIDGET_COMBOBOX |
---|
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 Combobox Widgets |
---|
28 | ; |
---|
29 | ; Pressing the mouse button while the mouse cursor is over an |
---|
30 | ; element of a combobox widget causes the widget to change the label |
---|
31 | ; on the combobox 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_COMBOBOX_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_COMBOBOX: |
---|
59 | ; COMBOBOX_NUMBER: the number of elements currently |
---|
60 | ; contained in the specified combobox widget. |
---|
61 | ; COMBOBOX_SELECT: the zero-based number of the |
---|
62 | ; currently-selected element (i.e., the currently-displayed |
---|
63 | ; element) in the specified combobox widget. |
---|
64 | ; DYNAMIC_RESIZE: a True value (1) if the widget specified |
---|
65 | ; by Widget_ID is a button, combobox, 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 combobox comme on peut le faire |
---|
71 | ; pour WIDGET_COMBOBOX 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_COMBOBOX_PM widget (see the documentation |
---|
77 | ; for the DYNAMIC_RESIZE keyword to WIDGET_COMBOBOX |
---|
78 | ; procedure for more information about dynamic widget |
---|
79 | ; resizing). |
---|
80 | ; COMBOBOX_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 combobox |
---|
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 | ; testwid, value=strtrim(indgen(10),2) |
---|
100 | ; PRO testwid_event, event |
---|
101 | ; ; help, event, /STRUCT |
---|
102 | ; ComboboxId = widget_info(event.top,find_by_uname = 'c''est lui') |
---|
103 | ; widget_control, event.id, get_uvalue=uval |
---|
104 | ; if n_elements(uval) EQ 0 then return |
---|
105 | ; case uval of |
---|
106 | ; 'done':widget_control, event.top, /destroy |
---|
107 | ; 'dynamic_resize':BEGIN |
---|
108 | ; widget_control, event.id, get_value = value |
---|
109 | ; widget_control, ComboboxId, set_value = {dynamic_resize:value} |
---|
110 | ; END |
---|
111 | ; 'combobox_select':BEGIN |
---|
112 | ; widget_control, event.id, get_value = value |
---|
113 | ; widget_control, ComboboxId, set_value = {combobox_select:value} |
---|
114 | ; END |
---|
115 | ; 'value':BEGIN |
---|
116 | ; widget_control, event.id, get_value = value |
---|
117 | ; widget_control, ComboboxId, set_value = value |
---|
118 | ; END |
---|
119 | ; 'get':BEGIN |
---|
120 | ; widget_control, ComboboxId, get_value = value |
---|
121 | ; help, value, /struct |
---|
122 | ; END |
---|
123 | ; ELSE: |
---|
124 | ; endcase |
---|
125 | ; return |
---|
126 | ; end |
---|
127 | ; PRO testwid, _extra = ex |
---|
128 | ; base=widget_base(/COLUMN) |
---|
129 | ; print, 'base=', base |
---|
130 | ; nothing = widget_label(base, value = 'beginning of the test') |
---|
131 | ; ; |
---|
132 | ; nothing = cw_combobox_pm(base, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui') |
---|
133 | ; print, 'cw_combobox_pm ID =', nothing |
---|
134 | ; ; |
---|
135 | ; nothing = widget_label(base, value = 'end of the test') |
---|
136 | ; nothing = widget_text(base, value = '0', uvalue = 'dynamic_resize', /editable) |
---|
137 | ; nothing = widget_text(base, value = '10', uvalue = 'combobox_select', /editable) |
---|
138 | ; nothing = widget_text(base, value = '5', uvalue = 'value', /editable) |
---|
139 | ; nothing = widget_button(base, value = 'get', uvalue = 'get') |
---|
140 | ; nothing = widget_button(base, value = 'done', uvalue = 'done') |
---|
141 | ; widget_control, base, /REALIZE |
---|
142 | ; xmanager,'testwid', base |
---|
143 | ; return |
---|
144 | ; end |
---|
145 | ;---------------------------------------------------------------------- |
---|
146 | PRO cw_combobox_pm_set_value, id, value |
---|
147 | ; |
---|
148 | compile_opt idl2, strictarrsubs |
---|
149 | ; |
---|
150 | ComboboxId = widget_info(id,find_by_uname = 'Combobox') |
---|
151 | if size(value, /type) eq 8 then BEGIN ; this is a structure |
---|
152 | tagnames = tag_names(value) |
---|
153 | for tag = 0, n_tags(value)-1 do begin |
---|
154 | case strtrim(strlowcase(tagnames[tag]), 2) of |
---|
155 | 'dynamic_resize':widget_control, ComboboxId, dynamic_resize = value.dynamic_resize |
---|
156 | ; for compatibility |
---|
157 | 'droplist_select':widget_control, ComboboxId, set_combobox_select = value.droplist_select |
---|
158 | 'combobox_select':widget_control, ComboboxId, set_combobox_select = value.combobox_select |
---|
159 | 'value':widget_control, ComboboxId, set_value = value.value |
---|
160 | ELSE:ras = report('wrong tag name in argument "value" of cw_combobox_pm_set_value') |
---|
161 | endcase |
---|
162 | endfor |
---|
163 | ENDIF ELSE widget_control, ComboboxId, set_value = value |
---|
164 | return |
---|
165 | end |
---|
166 | ;---------------------------------------------------------------------- |
---|
167 | FUNCTION cw_combobox_pm_get_value, id |
---|
168 | ; |
---|
169 | compile_opt idl2, strictarrsubs |
---|
170 | ; |
---|
171 | ComboboxId = widget_info(id,find_by_uname = 'Combobox') |
---|
172 | widget_control, ComboboxId, get_value = cmbbval |
---|
173 | cmbbtxt = widget_info(ComboboxId, /combobox_gettext) |
---|
174 | cmbbnumb = widget_info(ComboboxId, /combobox_number) |
---|
175 | index = (where(cmbbval EQ cmbbtxt))[0] |
---|
176 | return, {combobox_number:cmbbnumb, combobox_gettext:cmbbtxt $ |
---|
177 | , combobox_index:index, combobox_value:cmbbval $ |
---|
178 | , dynamic_resize:widget_info(ComboboxId, /dynamic_resize)} |
---|
179 | end |
---|
180 | ;---------------------------------------------------------------------- |
---|
181 | FUNCTION cw_combobox_pm_event, event |
---|
182 | ; |
---|
183 | compile_opt idl2, strictarrsubs |
---|
184 | ; |
---|
185 | widget_control, event.id, get_uvalue=uval |
---|
186 | ; |
---|
187 | if uval EQ 'Combobox' then $ |
---|
188 | return, {CW_COMBOBOX_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ |
---|
189 | , INDEX:event.index, STR:event.str, OUT:0} |
---|
190 | ; |
---|
191 | ComboboxId = widget_info(event.handler,find_by_uname = 'Combobox') |
---|
192 | widget_control, ComboboxId, get_value = cmbbval |
---|
193 | cmbbtxt = widget_info(ComboboxId, /combobox_gettext) |
---|
194 | cmbbnumb = widget_info(ComboboxId, /combobox_number) |
---|
195 | index = (where(cmbbval EQ cmbbtxt))[0] |
---|
196 | out = 0 |
---|
197 | case uval OF |
---|
198 | 'plus':BEGIN |
---|
199 | if index LT (cmbbnumb - 1) then BEGIN |
---|
200 | index = index + 1 |
---|
201 | widget_control, ComboboxId, set_combobox_select = index |
---|
202 | ENDIF ELSE out = 1 |
---|
203 | END |
---|
204 | 'minus':BEGIN |
---|
205 | if index GT 0 then BEGIN |
---|
206 | index = index - 1 |
---|
207 | widget_control, ComboboxId, set_combobox_select = index |
---|
208 | ENDIF ELSE out = -1 |
---|
209 | END |
---|
210 | endcase |
---|
211 | return, {CW_COMBOBOX_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ |
---|
212 | , INDEX:index, STR:cmbbtxt, OUT:out} |
---|
213 | end |
---|
214 | ;---------------------------------------------------------------------- |
---|
215 | FUNCTION cw_combobox_pm, parent, VALUE = value, UVALUE = uvalue, UNAME = uname, ROW = row, COLUMN = column, _extra = ex |
---|
216 | ; |
---|
217 | compile_opt idl2, strictarrsubs |
---|
218 | ; |
---|
219 | |
---|
220 | IF (N_PARAMS() NE 1) THEN MESSAGE, 'Incorrect number of arguments' |
---|
221 | ON_ERROR, 2 ;return to caller |
---|
222 | ; cheking for row and column keywords |
---|
223 | row = keyword_set(row)*(1-keyword_set(column)) |
---|
224 | column = keyword_set(column)*(1-keyword_set(row))+(keyword_set(column) EQ row) |
---|
225 | if NOT keyword_set(uvalue) then uvalue = '' |
---|
226 | if NOT keyword_set(uname) then uname = '' |
---|
227 | ; |
---|
228 | base = widget_base(parent, space = 0 $ |
---|
229 | , EVENT_FUNC = 'cw_combobox_pm_event' $ |
---|
230 | , FUNC_GET_VALUE='cw_combobox_pm_get_value' $ |
---|
231 | , PRO_SET_VALUE='cw_combobox_pm_set_value' $ |
---|
232 | , UVALUE = uvalue, UNAME = uname, _extra = ex) |
---|
233 | ; |
---|
234 | vallen = widget_info(base, string_size = 'm') |
---|
235 | vallen = 35 + (vallen[0]-1)*max(strlen(value)) |
---|
236 | if keyword_set(row) THEN BEGIN |
---|
237 | nothing = widget_button(base, value = '-', uvalue = 'minus', xoffset = 0 $ |
---|
238 | , yoffset = 5, xsize = 15, ysize = 15) |
---|
239 | nothing = widget_combobox(base, VALUE = value, UVALUE = 'Combobox', UNAME = 'Combobox' $ |
---|
240 | , xoffset = 13, yoffset = 0, xsize = vallen) |
---|
241 | nothing = widget_button(base, value = '+', uvalue = 'plus' $ |
---|
242 | , xoffset = vallen+11, yoffset = 5 $ |
---|
243 | , xsize = 15, ysize = 15) |
---|
244 | ENDIF ELSE BEGIN |
---|
245 | nothing = widget_combobox(base, VALUE = value, UVALUE = 'Combobox', UNAME = 'Combobox' $ |
---|
246 | , xoffset = 0, yoffset = 0, xsize = vallen) |
---|
247 | nothing = widget_button(base, value = '-', uvalue = 'minus' $ |
---|
248 | , xoffset = vallen/2-15 $ |
---|
249 | , yoffset = 24, xsize = 15, ysize = 15) |
---|
250 | nothing = widget_button(base, value = '+', uvalue = 'plus' $ |
---|
251 | , xoffset = vallen/2 $ |
---|
252 | , yoffset = 24, xsize = 15, ysize = 15) |
---|
253 | ENDELSE |
---|
254 | ; |
---|
255 | ; widget_control,base,/realize |
---|
256 | ; |
---|
257 | return, base |
---|
258 | end |
---|