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

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

typo

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