source: trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_droplist_pm.pro @ 157

Last change on this file since 157 was 157, checked in by navarro, 18 years ago

header improvements + xxx doc

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