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

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME: cw_droplist_pm
6;
7; PURPOSE: widget equivalent a WIDGET_DROPLIST 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_droplist_pm(parent)
13;
14; INPUTS:
15;         Parent: The widget ID of the parent widget.
16;
17; KEYWORD PARAMETERS:tous ceux de WIDGET_DROPLIST
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 Droplist Widgets
28;
29;   Pressing the mouse button while the mouse cursor is over an
30;   element of a droplist widget causes the widget to change the label
31;   on the droplist 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_DROPLIST_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_DROPLIST:
59;            DROPLIST_NUMBER: the number of elements currently
60;            contained in the specified droplist widget.
61;            DROPLIST_SELECT: the zero-based number of the
62;            currently-selected element (i.e., the currently-displayed
63;            element) in the specified droplist widget.
64;            DYNAMIC_RESIZE: a True value (1) if the widget specified
65;            by Widget_ID is a button, droplist, 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 droplist comme on peut le faire
71;   pour WIDGET_DROPLIST 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_DROPLIST_PM widget (see the documentation
77;            for the DYNAMIC_RESIZE keyword to WIDGET_DROPLIST
78;            procedure for more information about dynamic widget
79;            resizing).
80;            DROPLIST_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 droplist
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; PRO testwid_event, event
100; ;   help, event, /STRUCT
101;    DroplistId = widget_info(event.top,find_by_uname = 'c''est lui')
102;    widget_control, event.id, get_uvalue=uval
103;    if n_elements(uval) EQ 0 then return
104;    case uval of
105;       'done':widget_control, event.top, /destroy
106;       'dynamic_resize':BEGIN
107;          widget_control, event.id, get_value = value
108;          widget_control, DroplistId, set_value = {dynamic_resize:value}
109;       END
110;       'droplist_select':BEGIN
111;          widget_control, event.id, get_value = value
112;          widget_control, DroplistId, set_value = {droplist_select:value}
113;       END
114;       'value':BEGIN
115;          widget_control, event.id, get_value = value
116;          widget_control, DroplistId, set_value = value
117;       END
118;       'get':BEGIN
119;          widget_control, DroplistId, get_value = value
120;          help,  value, /struct
121;       END
122;       ELSE:
123;    endcase
124;    return
125; end
126; PRO testwid, _extra = ex
127;    base=widget_base(/COLUMN)
128; print, 'base=', base
129;    nothing = widget_label(base, value = 'beginning of the test')
130; ;
131;    nothing = cw_droplist_pm(base, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui')
132; print, 'cw_droplist_pm ID =', nothing
133; ;
134;    nothing = widget_label(base, value = 'end of the test')
135;    nothing = widget_text(base, value = '0', uvalue = 'dynamic_resize', /editable)
136;    nothing = widget_text(base, value = '10', uvalue = 'droplist_select', /editable)
137;    nothing = widget_text(base, value = '5', uvalue = 'value', /editable)
138;    nothing = widget_button(base, value = 'get', uvalue = 'get')
139;    nothing = widget_button(base, value = 'done', uvalue = 'done')
140;    widget_control, base, /REALIZE
141;    xmanager,'testwid', base
142;    return
143; end
144;----------------------------------------------------------------------
145PRO cw_droplist_pm_set_value, id, value
146;
147  compile_opt idl2, strictarrsubs
148;
149   DroplistId = widget_info(id,find_by_uname = 'Droplist')
150   if size(value, /type) eq 8 then BEGIN ; this is a structure
151      tagnames = tag_names(value)
152      for tag = 0, n_tags(value)-1 do begin
153         case strtrim(strlowcase(tagnames[tag]), 2) of
154            'dynamic_resize':widget_control, DroplistId, dynamic_resize = value.dynamic_resize
155            'droplist_select':widget_control, DroplistId, set_droplist_select = value.droplist_select
156            'value':widget_control, DroplistId, set_value = value.value
157            ELSE:ras = report('mauvais nom de l''argument de la structure ds cw_droplist_pm_set_value')
158         endcase
159      endfor
160   ENDIF ELSE widget_control, DroplistId, set_value = value
161   return
162end
163;----------------------------------------------------------------------
164FUNCTION cw_droplist_pm_get_value, id
165;
166  compile_opt idl2, strictarrsubs
167;
168   DroplistId = widget_info(id,find_by_uname = 'Droplist')
169   return, {droplist_number:widget_info(DroplistId, /droplist_number) $
170            , droplist_select:widget_info(DroplistId, /droplist_select) $
171            , dynamic_resize:widget_info(DroplistId, /dynamic_resize)}
172end
173;----------------------------------------------------------------------
174FUNCTION cw_droplist_pm_event, event
175;
176  compile_opt idl2, strictarrsubs
177;
178   widget_control, event.id, get_uvalue=uval
179;
180   if uval EQ 'Droplist' then $
181    return, {CW_DROPLIST_PM, ID:event.handler, TOP:event.top, HANDLER:0L $
182             , INDEX:event.index, OUT:0}
183;
184   DroplistId = widget_info(event.handler,find_by_uname = 'Droplist')
185   index = widget_info(DroplistId, /droplist_select)
186   case uval OF
187      'plus':BEGIN
188         indexmax = widget_info(DroplistId, /droplist_number)-1
189         if index NE indexmax then widget_control, DroplistId,set_droplist_select = index+1
190         return, {CW_DROPLIST_PM, ID:event.handler, TOP:event.top, HANDLER:0L $
191                  , INDEX:(index+1) < indexmax, OUT:long(index EQ indexmax)}
192      END
193      'minus':BEGIN
194         if index NE 0 then widget_control, DroplistId,set_droplist_select = index-1
195         return, {CW_DROPLIST_PM, ID:event.handler, TOP:event.top, HANDLER:0L $
196                  , INDEX:0 > (index-1), OUT:-long(index EQ 0)}
197      END
198   endcase
199end
200;----------------------------------------------------------------------
201FUNCTION cw_droplist_pm, parent,UVALUE = uvalue, UNAME = uname, ROW = row, COLUMN = column, _extra = ex
202;
203  compile_opt idl2, strictarrsubs
204;
205
206   IF (N_PARAMS() NE 1) THEN MESSAGE, 'Incorrect number of arguments'
207   ON_ERROR, 2                  ;return to caller
208; cheking for row and column keywords
209   row = keyword_set(row)*(1-keyword_set(column))
210   column = keyword_set(column)*(1-keyword_set(row))+(keyword_set(column) EQ row)
211   if NOT keyword_set(uvalue) then uvalue = ''
212   if NOT keyword_set(uname) then uname = ''
213;
214   base = widget_base(parent, space = 1, xpad = 1, ypad = 1, ROW = row, COLUMN = column  $
215                      , EVENT_FUNC = 'cw_droplist_pm_event' $
216                      , FUNC_GET_VALUE='cw_droplist_pm_get_value' $
217                      , PRO_SET_VALUE='cw_droplist_pm_set_value' $
218                      , UVALUE = uvalue, UNAME = uname, _extra = ex)   
219;
220   if keyword_set(row) THEN nothing = widget_button(base,value= '-', uvalue= 'minus')
221   nothing = widget_droplist(base, UVALUE = 'Droplist', UNAME = 'Droplist', _extra = ex)
222   if keyword_set(column) then begin
223      base1 = widget_base(base, /row, /align_center, space = 1, xpad = 1, ypad = 1)
224      nothing = widget_button(base1,value= '-', uvalue= 'minus', xsize = 20, ysize = 20)
225      nothing = widget_button(base1,value= '+', uvalue= 'plus', xsize = 20, ysize = 20)
226   ENDIF ELSE nothing = widget_button(base,value= '+', uvalue= 'plus')
227;
228;   widget_control,base,/realize
229;
230   return, base
231end
Note: See TracBrowser for help on using the repository browser.