source: trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_combobox_pm.pro @ 232

Last change on this file since 232 was 232, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:keywords set to Id
File size: 10.8 KB
Line 
1; testwid, value=strtrim(indgen(10),2)
2; PRO testwid_event, event
3; ;   help, event, /STRUCT
4;    ComboboxId = widget_info(event.top,find_by_uname = 'c''est lui')
5;    widget_control, event.id, get_uvalue=uval
6;    if n_elements(uval) EQ 0 then return
7;    case uval of
8;       'done':widget_control, event.top, /destroy
9;       'dynamic_resize':BEGIN
10;          widget_control, event.id, get_value = value
11;          widget_control, ComboboxId, set_value = {dynamic_resize:value}
12;       END
13;       'combobox_select':BEGIN
14;          widget_control, event.id, get_value = value
15;          widget_control, ComboboxId, set_value = {combobox_select:value}
16;       END
17;       'value':BEGIN
18;          widget_control, event.id, get_value = value
19;          widget_control, ComboboxId, set_value = value
20;       END
21;       'get':BEGIN
22;          widget_control, ComboboxId, get_value = value
23;          help,  value, /struct
24;       END
25;       ELSE:
26;    endcase
27;    return
28; end
29; PRO testwid, _extra = ex
30;    base=widget_base(/COLUMN)
31; print, 'base=', base
32;    nothing = widget_label(base, value = 'beginning of the test')
33; ;
34;    nothing = cw_combobox_pm(base, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui')
35; print, 'cw_combobox_pm ID =', nothing
36; ;
37;    nothing = widget_label(base, value = 'end of the test')
38;    nothing = widget_text(base, value = '0', uvalue = 'dynamic_resize', /editable)
39;    nothing = widget_text(base, value = '10', uvalue = 'combobox_select', /editable)
40;    nothing = widget_text(base, value = '5', uvalue = 'value', /editable)
41;    nothing = widget_button(base, value = 'get', uvalue = 'get')
42;    nothing = widget_button(base, value = 'done', uvalue = 'done')
43;    widget_control, base, /REALIZE
44;    xmanager,'testwid', base
45;    return
46; end
47;+
48;
49; @file_comments
50;
51;
52; @categories
53; Compound widget
54;
55; @param ID
56;
57; @param VALUE
58; It is the default tick mark value (a floating-point number).
59;
60; @returns
61;
62; @uses
63;
64; @restrictions
65;
66; @examples
67;
68; @history
69;
70; @version
71; $Id$
72;-
73;
74PRO cw_combobox_pm_set_value, id, value
75;
76  compile_opt idl2, strictarrsubs
77;
78   ComboboxId = widget_info(id,find_by_uname = 'Combobox')
79   if size(value, /type) eq 8 then BEGIN ; this is a structure
80      tagnames = tag_names(value)
81      for tag = 0, n_tags(value)-1 do begin
82         case strtrim(strlowcase(tagnames[tag]), 2) of
83            'dynamic_resize':widget_control, ComboboxId, dynamic_resize = value.dynamic_resize
84; for compatibility
85            'droplist_select':widget_control, ComboboxId, set_combobox_select = value.droplist_select
86            'combobox_select':widget_control, ComboboxId, set_combobox_select = value.combobox_select
87            'value':widget_control, ComboboxId, set_value = value.value
88            ELSE:ras = report('wrong tag name in argument "value" of cw_combobox_pm_set_value')
89         endcase
90      endfor
91   ENDIF ELSE widget_control, ComboboxId, set_value = value
92   return
93end
94;
95;+
96;
97; @file_comments
98;
99; @categories
100; Compound widget
101;
102; @param ID
103;
104; @returns
105;
106; @uses
107;
108; @restrictions
109;
110; @examples
111;
112; @history
113;
114; @version
115; $Id$
116;-
117;
118FUNCTION cw_combobox_pm_get_value, id
119;
120  compile_opt idl2, strictarrsubs
121;
122   ComboboxId = widget_info(id,find_by_uname = 'Combobox')
123   widget_control, ComboboxId, get_value = cmbbval
124   cmbbtxt = widget_info(ComboboxId, /combobox_gettext)
125   cmbbnumb = widget_info(ComboboxId, /combobox_number)
126   index = (where(cmbbval EQ cmbbtxt))[0]
127   return, {combobox_number:cmbbnumb, combobox_gettext:cmbbtxt $
128            , combobox_index:index, combobox_value:cmbbval $
129            , dynamic_resize:widget_info(ComboboxId, /dynamic_resize)}
130end
131;
132;+
133;
134; @file_comments
135;
136; @categories
137; Compound widget
138;
139; @param EVENT
140;
141; @returns
142;
143; @uses
144;
145; @restrictions
146;
147; @examples
148;
149; @history
150;
151; @version
152; $Id$
153;-
154;
155FUNCTION cw_combobox_pm_event, event
156;
157  compile_opt idl2, strictarrsubs
158;
159   widget_control, event.id, get_uvalue=uval
160;
161   if uval EQ 'Combobox' then $
162    return, {CW_COMBOBOX_PM, ID:event.handler, TOP:event.top, HANDLER:0L $
163             , INDEX:event.index, STR:event.str, OUT:0}
164;
165   ComboboxId = widget_info(event.handler,find_by_uname = 'Combobox')
166   widget_control, ComboboxId, get_value = cmbbval
167   cmbbtxt = widget_info(ComboboxId, /combobox_gettext)
168   cmbbnumb = widget_info(ComboboxId, /combobox_number)
169   index = (where(cmbbval EQ cmbbtxt))[0]
170   out = 0
171   case uval OF
172      'plus':BEGIN
173         if index LT (cmbbnumb - 1) then BEGIN
174           index = index + 1
175           widget_control, ComboboxId, set_combobox_select = index
176         ENDIF ELSE out = 1
177      END
178      'minus':BEGIN
179         if index GT 0 then BEGIN
180           index = index - 1
181           widget_control, ComboboxId, set_combobox_select = index
182         ENDIF ELSE out = -1
183      END
184   endcase
185   return, {CW_COMBOBOX_PM, ID:event.handler, TOP:event.top, HANDLER:0L $
186                  , INDEX:index, STR:cmbbtxt, OUT:out}
187end
188;
189;+
190;
191; @file_comments
192; Like WIDGET_COMBOBOX but here, their are 2 buttons + and - to move the widget from +/- 1
193;
194; @categories
195; Compound widget
196;
197; @param PARENT {in}{required}
198; The widget ID of the parent widget.
199;
200; @keyword COLUMN
201; Buttons will be arranged in the number of columns
202; specified by this keyword.
203;
204; @keyword ROW
205; Buttons will be arranged in the number of rows
206; specified by this keyword.
207;
208; @keyword UVALUE
209; The user value to be associated with the widget.
210;
211; @keyword UNAME
212; The user name to be associated with the widget.
213;
214; @keyword VALUE
215;
216; @keyword _EXTRA
217; Used to pass keywords
218;
219; @returns
220; The returned value of this function is the widget ID of the
221; newly-created animation widget.
222;
223; @restrictions
224;
225;     Widget Events Returned by Combobox Widgets
226;
227;   Pressing the mouse button while the mouse cursor is over an
228;   element of a combobox widget causes the widget to change the label
229;   on the combobox button and to generate an event. The appearance of
230;   any previously selected element is restored to normal at the same
231;   time. The event structure returned by the WIDGET_EVENT function is
232;   defined by the following statement:
233;
234;   { CW_COMBOBOX_PM, ID:0L, TOP:0L, HANDLER:0L, INDEX:0L, OUT:0 }
235;
236;   The first three fields are the standard fields found in every
237;   widget event.
238;   INDEX returns the index of the selected item. This can be used to
239;   index the array of names originally used to set the widget''s
240;   value
241;   OUT:It is an integer which can take 3 values:
242;       1 : If we press + when the index is already at the max
243;       Comment: In this case, the index stay at the max
244;       -1: If we press - when the index is already at the min
245;       Comment: In this case, the index stay at the min
246;       0 : In other cases
247;
248;   Keywords to WIDGET_CONTROL
249;
250;   A number of keywords to the WIDGET_CONTROL procedure affect the
251;   behavior of cw_slider_pm widget: GET_VALUE and SET_VALUE.
252;       1) GET_VALUE
253;   widget_control,wid_id,get_value=resultat
254;   Send back, in the result variable, a structure of 3 elements whose
255;   names are inspired by keywords we can pass at widget_control when
256;   we use WIDGET_COMBOBOX:
257;            COMBOBOX_NUMBER: the number of elements currently
258;            contained in the specified combobox widget.
259;            COMBOBOX_SELECT: the zero-based number of the
260;            currently-selected element (i.e., the currently-displayed
261;            element) in the specified combobox widget.
262;            DYNAMIC_RESIZE: a True value (1) if the widget specified
263;            by Widget_ID is a button, combobox, or label widget that
264;            has had its DYNAMIC_RESIZE attribute set. Otherwise,
265;            False (0) is returned.
266;       2) SET_VALUE
267;   widget_control,wid_id,set_value=impose
268;   Allows to modify the state of the combobox like we can do it for
269;   WIDGET_COMBOBOX. May impose:
270;       a) The contents of the list widget (string or string array)
271;       b) A structure which can have for elements (from 1 to 3):
272;            DYNAMIC_RESIZE:Set this keyword to activate (if set to 1)
273;            or deactivate (if set to 0) dynamic resizing of the
274;            specified CW_COMBOBOX_PM widget (see the documentation
275;            for the DYNAMIC_RESIZE keyword to WIDGET_COMBOBOX
276;            procedure for more information about dynamic widget
277;            resizing).
278;            COMBOBOX_SELECT:Set this keyword to return the zero-based
279;            number of the currently-selected element (i.e., the
280;            currently-displayed element) in the specified combobox
281;            widget.
282;            VALUE: The contents of the list widget (string or string
283;            array)
284;
285; @examples
286; See the program provided above (testwid and the associated procedure, testwid_event).
287;
288; @history
289; Sebastien Masson (smasson\@lodyc.jussieu.fr)
290;                      6/9/1999
291;
292; @version
293; $Id$
294;
295;-
296;
297FUNCTION cw_combobox_pm, parent, VALUE = value, UVALUE = uvalue, UNAME = uname, ROW = row, COLUMN = column, _EXTRA = ex
298;
299  compile_opt idl2, strictarrsubs
300;
301
302   IF (N_PARAMS() NE 1) THEN MESSAGE, 'Incorrect number of arguments'
303   ON_ERROR, 2                  ;return to caller
304; checking for row and column keywords
305   row = keyword_set(row)*(1-keyword_set(column))
306   column = keyword_set(column)*(1-keyword_set(row))+(keyword_set(column) EQ row)
307   if NOT keyword_set(uvalue) then uvalue = ''
308   if NOT keyword_set(uname) then uname = ''
309;
310   base = widget_base(parent, space = 0 $
311                      , EVENT_FUNC = 'cw_combobox_pm_event' $
312                      , FUNC_GET_VALUE='cw_combobox_pm_get_value' $
313                      , PRO_SET_VALUE='cw_combobox_pm_set_value' $
314                      , UVALUE = uvalue, UNAME = uname, _extra = ex)
315;
316   vallen = widget_info(base, string_size = 'm')
317   vallen = 35 + (vallen[0]-1)*max(strlen(value))
318   if keyword_set(row) THEN BEGIN
319     nothing = widget_button(base, value = '-', uvalue = 'minus', xoffset = 0 $
320                             , yoffset = 5, xsize = 15, ysize = 15)
321     nothing = widget_combobox(base, VALUE = value, UVALUE = 'Combobox', UNAME = 'Combobox' $
322                               , xoffset = 13, yoffset = 0, xsize = vallen)
323     nothing = widget_button(base, value = '+', uvalue = 'plus' $
324                             , xoffset = vallen+11, yoffset = 5 $
325                             , xsize = 15, ysize = 15)
326   ENDIF ELSE BEGIN
327     nothing = widget_combobox(base, VALUE = value, UVALUE = 'Combobox', UNAME = 'Combobox' $
328                               , xoffset = 0, yoffset = 0, xsize = vallen)
329     nothing = widget_button(base, value = '-', uvalue = 'minus' $
330                             , xoffset = vallen/2-15 $
331                             , yoffset = 24, xsize = 15, ysize = 15)
332     nothing = widget_button(base, value = '+', uvalue = 'plus' $
333                             , xoffset = vallen/2 $
334                             , yoffset = 24, xsize = 15, ysize = 15)
335   ENDELSE
336;
337;   widget_control,base,/realize
338;
339   return, base
340end
Note: See TracBrowser for help on using the repository browser.