source: trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_slider_pm.pro @ 262

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

corrections of some headers and parameters and keywords case. change of pro2href to replace proidl

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.7 KB
Line 
1;+
2;
3; @file_comments
4;
5; @categories
6; Compound widget
7;
8; @param VALUE
9; It is the default tick mark value (a floating-point number).
10;
11; @returns
12;
13; @uses
14;
15; @restrictions
16;
17; @examples
18;
19; @history
20;
21; @version
22; $Id$
23;-
24;
25FUNCTION decvalue, value
26;
27  compile_opt idl2, strictarrsubs
28;
29  a = float(value[0])
30  return, strtrim(string(floor(a) + 0.1*indgen(10), format = '(f15.1)'), 2)
31end
32;
33;+
34;
35; @file_comments
36;
37; @categories
38; Compound widget
39;
40; @param VALUE
41; It is the default tick mark value (a floating-point number).
42;
43; @returns
44;
45; @uses
46;
47; @restrictions
48;
49; @examples
50;
51; @history
52;
53; @version
54; $Id$
55;-
56;
57FUNCTION decind, value
58;
59  compile_opt idl2, strictarrsubs
60;
61  a = float(value[0])
62  return, round(10*(a - floor(a))) ; !! computation accuracy
63end
64;
65;+
66;
67; @file_comments
68;
69; @categories
70; Compound widget
71;
72; @param ID
73;
74; @param VALUE
75; It is the default tick mark value (a floating-point number).
76;
77; @returns
78;
79; @uses
80;
81; @restrictions
82;
83; @examples
84;
85; @history
86;
87; @version
88; $Id$
89;-
90;
91PRO cw_slider_pm_set_value, id, value
92;
93  compile_opt idl2, strictarrsubs
94;
95  sbid = widget_info(id, find_by_uname = 'SliderBar')
96  dcid = widget_info(id, find_by_uname = 'decimal')
97  minmax = widget_info(sbid, /SLIDER_MIN_MAX)
98  if size(value, /type) eq 8 then BEGIN ; this is a structure
99    tagnames = tag_names(value)
100    for tag = 0, n_tags(value)-1 do begin
101      case strtrim(strlowcase(tagnames[tag]), 2) of
102        'slider_min':BEGIN
103;          IF float(value.slider_min[0]) LT minmax[1] THEN BEGIN
104            minmax[0] = value.slider_min[0]
105            widget_control, sbid, set_slider_min = floor(float(value.slider_min[0]))
106            valuedc = float(widget_info(dcid, /combobox_gettext))
107            IF valuedc LT value.slider_min THEN BEGIN
108              widget_control, sbid, set_value = floor(float(value.slider_min[0]))
109              widget_control, dcid, set_value = decvalue(value.slider_min)
110              widget_control, dcid, set_combobox_select = decind(value.slider_min)
111            ENDIF
112;          ENDIF
113        end
114        'slider_max':BEGIN
115;          IF float(value.slider_max[0]) GT minmax[0] THEN BEGIN
116            minmax[1] = value.slider_max[0]
117            widget_control, sbid, set_slider_max = ceil(float(value.slider_max[0]))
118            valuedc = float(widget_info(dcid, /combobox_gettext))
119            IF valuedc GT value.slider_max THEN BEGIN
120              widget_control, sbid, set_value = ceil(float(value.slider_max[0]))
121              widget_control, dcid, set_value = decvalue(value.slider_max)
122              widget_control, dcid, set_combobox_select = decind(value.slider_max)
123            ENDIF
124;          ENDIF
125        end
126        'value':IF float(value.value[0]) GE minmax[0] $
127          AND float(value.value[0]) LE minmax[1] THEN value2 = float(value.value[0])
128        ELSE:ras = report('wrong tag name in argument "value" of cw_slider_pm_set_value')
129      endcase
130    endfor
131  ENDIF ELSE BEGIN
132    IF float(value[0]) GE minmax[0] $
133      AND float(value[0]) LE minmax[1] THEN value2 = float(value[0])
134  ENDELSE
135  IF n_elements(value2) NE 0 THEN BEGIN
136    widget_control, sbid, set_value = fix(value2)
137    widget_control, dcid, set_value = decvalue(value2)
138    widget_control, dcid, set_combobox_select = decind(value2)
139  ENDIF
140  return
141end
142;
143;+
144;
145; @file_comments
146;
147;
148; @categories
149; Compound widget
150;
151; @param ID
152;
153; @returns
154;
155; @uses
156;
157; @restrictions
158;
159; @examples
160;
161; @history
162;
163; @version
164; $Id$
165;-
166;
167FUNCTION cw_slider_pm_get_value, id
168;
169  compile_opt idl2, strictarrsubs
170;
171  sbid = widget_info(id, find_by_uname = 'SliderBar')
172  dcid = widget_info(id, find_by_uname = 'decimal')
173  minmax = widget_info(sbid, /SLIDER_MIN_MAX)
174  value = float(widget_info(dcid, /combobox_gettext))
175   return, {value:value, slider_min_max:minmax}
176end
177;
178;+
179;
180; @file_comments
181;
182; @categories
183; Compound widget
184;
185; @param EVENT
186;
187; @returns
188;
189; @uses
190;
191; @restrictions
192;
193; @examples
194;
195; @history
196;
197; @version
198; $Id$
199;-
200;
201FUNCTION cw_slider_pm_event, event
202;
203  compile_opt idl2, strictarrsubs
204;
205  widget_control, event.id, get_uvalue = uval
206;
207  sbid = widget_info(event.handler, find_by_uname = 'SliderBar')
208  dcid = widget_info(event.handler, find_by_uname = 'decimal')
209  minmax = widget_info(sbid, /SLIDER_MIN_MAX)
210  IF uval EQ 'decimal' THEN value = float(event.str) $
211  ELSE value = float(widget_info(dcid, /combobox_gettext))
212  out = 0 ; defaut case
213  case uval OF
214    'plus': if (value + 1) LE minmax[1] then value2 = value + 1 ELSE out = 1
215    'minus':if (value - 1) GE minmax[0] then value2 = value - 1 ELSE out = -1
216    'SliderBar':if (event.value + value - floor(value)) LE minmax[1] THEN value2 = event.value + value - floor(value)
217    'decimal':BEGIN
218      CASE 1 OF
219        value GT minmax[1]: value2 = minmax[1]
220        value LT minmax[0]: value2 = minmax[0]
221        ELSE:
222      ENDCASE
223    END
224    ELSE:
225  ENDCASE
226  IF n_elements(value2) NE 0  THEN BEGIN
227    value = value2
228    widget_control, sbid, set_value = floor(value)
229    widget_control, dcid, set_value = decvalue(value)
230    widget_control, dcid, set_combobox_select = decind(value)
231  ENDIF
232  return, {CW_SLIDER_PM, ID:event.handler, TOP:event.top, HANDLER:0L $
233           , VALUE:value, OUT:OUT}
234end
235;
236;+
237;
238; @file_comments
239; Like WIDGET_SLIDER but here, their are 2 buttons + and - to move the widget from +/- 1
240;
241; @categories
242; Compound widget
243;
244; @param PARENT {in}{required}
245; The widget ID of the parent widget.
246;
247; @keyword UVALUE
248; The user value to be associated with the widget.
249;
250; @keyword UNAME
251; The user name to be associated with the widget.
252;
253; @keyword VALUE
254;
255; @keyword MAXIMUM
256;
257; @keyword MINIMUM
258;
259; @keyword STRMINLEN
260;
261; @keyword _EXTRA
262; Used to pass keywords
263;
264; @returns
265; The returned value of this function is the widget ID of the
266; newly-created animation widget.
267;
268; @restrictions
269;
270;  Widget Events Returned by the CW_SLIDER_PM Widget
271;
272;  Slider widgets generate events when the mouse is used to change
273;  their value. The event structure returned by the WIDGET_EVENT
274;  function is defined by the following statement:
275;
276;  {CW_SLIDER_PM, ID:0L, TOP:0L, HANDLER:0L, VALUE:0L, DRAG:0, OUT:0}
277;
278;  ID is the widget ID of the button generating the event. TOP is the
279;  widget ID of the top level widget containing ID.
280;  HANDLER contains the widget ID of the widget associated with the
281;  handler routine.
282;  VALUE returns the new value of the slider.
283;  DRAG returns integer 1 if the slider event was generated as part of
284;  a drag operation, or zero if the event was generated when the user
285;  had finished positioning the slider. Note that the slider widget
286;  only generates events during the drag operation if the DRAG keyword
287;  is set, and if the application is running under Motif. When the
288;  DRAG keyword is set, the DRAG field can be used to avoid
289;  computationally expensive operations until the user releases the
290;  slider.
291;  OUT:It is an integer which can take 3 values:
292;       1 : If we press + when the index is already at the max
293;       Comment: In this case, the index stay at the max
294;       -1: If we press - when the index is already at the min
295;       Comment: In this case, the index stay at the min
296;       0 : In other cases
297;
298;   Keywords to WIDGET_CONTROL
299;
300;   A number of keywords to the WIDGET_CONTROL procedure affect the
301;   behavior of cw_slider_pm widget: GET_VALUE and SET_VALUE.
302;       1) GET_VALUE
303;   widget_control,wid_id,get_value=resultat
304;   Send back in the result variable a structure of 2 elements whose name
305;   are inspired from keywords we can pass at
306;   widget_control when we use WIDGET_SLIDER:
307;            VALUE:the value setting of the widget
308;            SLIDER_MIN_MAX: a 2 elements array: The minimum and the
309;            maximum value of the range encompassed by the slider
310;       2) SET_VALUE
311;   widget_control,wid_id,set_value=impose
312;   Allows to modify the state of the combobox like we can do it for
313;   WIDGET_COMBOBOX. May impose:
314;       a) a integer: give the new position of the slider.
315;       b) A structure which can have for elements (from 1 to 3):
316;            VALUE: an integer which give the new position of the slider
317;            SLIDER_MIN:Set to a new minimum value for the specified
318;            slider widget.
319;            SLIDER_MAX:Set to a new minimum value for the specified
320;            slider widget.
321;
322;
323; @examples
324; See the program provided above (testwid and the associated procedure, testwid_event).
325;
326; @history
327; Sebastien Masson (smasson\@lodyc.jussieu.fr)
328;                      5/9/1999
329;
330; @version
331; $Id$
332;
333; @todo
334; seb: documenter
335;
336;-
337;
338FUNCTION cw_slider_pm, parent, MAXIMUM = maximum, MINIMUM = minimum $
339                       , STRMINLEN = strminlen, VALUE = value, UVALUE = uvalue $
340                       , UNAME = uname, TITLE = title, _EXTRA = ex
341;
342  compile_opt idl2, strictarrsubs
343;
344
345  IF (N_PARAMS() NE 1) THEN ras = report('Incorrect number of arguments')
346  ON_ERROR, 2                   ;return to caller
347;
348  if n_elements(minimum) NE 0 then minimum = floor(minimum) ELSE minimum = 0
349  if n_elements(maximum) NE 0 then maximum = ceil(maximum) ELSE maximum = 100
350  if NOT keyword_set(title) then title = '    '
351;
352; checking exclusive keywords
353  column = (keyword_set(column)*(1-keyword_set(row))+keyword_set(vertical)) < 1
354  row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column)
355  if NOT keyword_set(uvalue) then uvalue = ''
356  if NOT keyword_set(uname) then uname = ''
357  base = widget_base(parent $
358                     , EVENT_FUNC = 'cw_slider_pm_event' $
359                     , FUNC_GET_VALUE = 'cw_slider_pm_get_value' $
360                     , PRO_SET_VALUE = 'cw_slider_pm_set_value' $
361                     , space = 0, UVALUE = uvalue, UNAME = uname, _extra = ex)
362;
363  mlen = (widget_info(base, string_size = 'm'))[0]
364
365  xsize = mlen*strlen(title)
366  dummyid = widget_label(base, value = title, xsize = xsize)
367  dummyid = widget_button(base, value = '-', uvalue = 'minus' $
368                          , yoffset = 15, xsize = 15, ysize = 15)
369  dummyid = widget_button(base, value = '+', uvalue = 'plus' $
370                          , xoffset = 15, yoffset = 15, xsize = 15, ysize = 15)
371  xoff = 30 > xsize
372  lenstr = max(strlen(strtrim([minimum, maximum], 1)))
373  if keyword_set(strminlen) then lenstr = strminlen > lenstr
374;  xsize = 35 + mlen*(lenstr+1)+3*(lenstr lt 4)
375  xsize = 35 + mlen*(lenstr+2)
376  dummyid = widget_combobox(base, value = decvalue(minimum) $
377                            , UVALUE = 'decimal', UNAME = 'decimal' $
378                            , xoffset = xoff, yoffset = 2, xsize = xsize)
379
380  dummyid = widget_slider(base, MAXIMUM = maximum, MINIMUM = minimum, UVALUE = 'SliderBar' $
381                          , UNAME = 'SliderBar', /suppress_value, /drag $
382                          , yoffset = 30, xsize = xoff + xsize)
383;
384  if keyword_set(value) then cw_slider_pm_set_value, base, value
385;
386  return, base
387end
Note: See TracBrowser for help on using the repository browser.