source: trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_bgroup.pro @ 325

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.9 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_bgroup_setv, id, value
28;
29  compile_opt hidden, idl2, strictarrsubs
30;
31  ON_ERROR, 2                       ;return to caller
32
33  stash = WIDGET_INFO(id, /CHILD)
34  WIDGET_CONTROL, stash, GET_UVALUE=state, /NO_COPY
35
36  case state.type of
37    0: message,'unable to set plain button group value'
38    1: begin
39      WIDGET_CONTROL, SET_BUTTON=0, state.ids[state.excl_pos]
40      state.excl_pos = value
41      WIDGET_CONTROL, /SET_BUTTON, state.ids[value]
42    end
43    2: begin
44      n = n_elements(value)-1
45      for i = 0, n do begin
46        state.nonexcl_curpos[i] = value[i]
47        WIDGET_CONTROL, state.ids[i], SET_BUTTON=value[i]
48      endfor
49    end
50  endcase
51
52  WIDGET_CONTROL, stash, SET_UVALUE=state, /NO_COPY
53end
54
55
56
57;+
58; @file_comments
59; Compound widget
60;
61; @categories
62;
63; @param ID
64;
65;
66; @param VALUE
67; It is the default tick mark value (a floating-point number).
68;
69; @returns
70;
71; @uses
72;
73; @restrictions
74;
75; @examples
76;
77; @history
78;
79; @version
80; $Id$
81;
82;-
83FUNCTION cw_bgroup_getv, id, value
84;
85  compile_opt hidden, idl2, strictarrsubs
86;
87  ON_ERROR, 2                       ;return to caller
88
89  stash = WIDGET_INFO(id, /CHILD)
90  WIDGET_CONTROL, stash, GET_UVALUE=state, /NO_COPY
91
92  case state.type of
93    0: message, 'unable to get plain button group value'
94;    1: ret = state.excl_pos
95    1: ret = state.ret_arr[state.excl_pos]
96;    2: ret = state.nonexcl_curpos
97    2: BEGIN
98      index = where(state.nonexcl_curpos NE 0)
99      if index[0] EQ -1 then begin
100        if size(state.ret_arr, /type) EQ 7 then ret = '' ELSE ret = -1
101      ENDIF ELSE ret = state.ret_arr[index]
102    END
103  endcase
104
105  WIDGET_CONTROL, stash, SET_UVALUE=state, /NO_COPY
106
107  return, ret
108
109end
110;
111;+
112;
113; @file_comments
114; Compound widget
115;
116; @categories
117;
118; @param EV
119;
120; @returns
121;
122; @uses
123;
124; @restrictions
125;
126; @examples
127;
128; @history
129;
130; @version
131; $Id$
132;
133;-
134FUNCTION cw_bgroup_event, ev
135;
136  compile_opt hidden, idl2, strictarrsubs
137;
138  WIDGET_CONTROL, ev.handler, GET_UVALUE=stash
139  WIDGET_CONTROL, stash, GET_UVALUE=state, /NO_COPY
140  WIDGET_CONTROL, ev.id, get_uvalue=uvalue
141
142  ret = 1           ;Assume we return a struct
143  case state.type of
144    0:
145    1: if (ev.select eq 1) then begin
146      state.excl_pos = uvalue
147    ENDIF else begin
148      if (state.no_release ne 0) then ret = 0
149    ENDELSE
150    2: begin
151      ; Keep track of the current state
152      state.nonexcl_curpos[uvalue] = ev.select
153          if (state.no_release ne 0) and (ev.select eq 0) then ret = 0
154    end
155  endcase
156
157  if ret then begin     ;Return a struct?
158      ret = { ID:state.base, TOP:ev.top, HANDLER:0L, SELECT:ev.select, $
159           VALUE:state.ret_arr[uvalue] }
160      efun = state.efun
161      WIDGET_CONTROL, stash, SET_UVALUE=state, /NO_COPY
162      if efun ne '' then return, CALL_FUNCTION(efun, ret) $
163      else return, ret
164  endif else begin      ;Trash the event
165      WIDGET_CONTROL, stash, SET_UVALUE=state, /NO_COPY
166      return, 0
167  endelse
168end
169
170
171
172
173;
174;+
175; @file_comments
176; CW_BGROUP is a compound widget that simplifies creating
177; a base of buttons. It handles the details of creating the
178; proper base (standard, exclusive, or non-exclusive) and filling
179; in the desired buttons. Events for the individual buttons are
180; handled transparently, and a CW_BGROUP event returned. This
181; event can return any one of the following:
182;      - The Index of the button within the base.
183;      - The widget ID of the button.
184;      - The name of the button.
185;      - An arbitrary value taken from an array of User values.
186;
187; @categories
188; Compound widget
189;
190; @param PARENT {in}{required}
191; The ID of the parent widget.
192;
193; @param NAMES {type=string array}
194; A string array, containing one string per button,
195; giving the name of each button.
196;
197; @keyword BUTTON_UVALUE {type=array}
198; An array of user values to be associated with
199; each button and returned in the event structure.
200;
201; @keyword COLUMN
202; Buttons will be arranged in the number of columns
203; specified by this keyword.
204;
205; @keyword EVENT_FUNCT
206; The name of an optional user-supplied event function
207; for buttons. This function is called with the return
208; value structure whenever a button is pressed, and
209; follows the conventions for user-written event functions.
210;
211; @keyword EXCLUSIVE
212; Buttons will be placed in an exclusive base, with
213; only one button allowed to be selected at a time.
214;
215; @keyword FONT
216; The name of the font to be used for the button
217; titles. If this keyword is not specified, the default
218; font is used.
219;
220; @keyword FRAME
221; Specifies the width of the frame to be drawn around the base.
222;
223; @keyword IDS
224; A named variable into which the button IDs will be
225; stored, as a longword vector.
226;
227; @keyword LABEL_LEFT
228; Creates a text label to the left of the buttons.
229;
230; @keyword LABEL_TOP
231; Creates a text label above the buttons.
232;
233; @keyword MAP
234; If set, the base will be mapped when the widget
235; is realized (the default).
236;
237; @keyword NONEXCLUSIVE
238; Buttons will be placed in an non-exclusive base.
239; The buttons will be independent.
240;
241; @keyword NO_RELEASE
242; If set, button release events will not be returned.
243;
244; @keyword RETURN_ID
245; If set, the VALUE field of returned events will be
246; the widget ID of the button.
247;
248; @keyword RETURN_INDEX
249; If set, the VALUE field of returned events will be
250; the zero-based index of the button within the base.
251; THIS IS THE DEFAULT.
252;
253; @keyword RETURN_NAME
254; If set, the VALUE field of returned events will be
255; the name of the button within the base.
256;
257; @keyword ROW
258; Buttons will be arranged in the number of rows
259; specified by this keyword.
260;
261; @keyword SCROLL
262; If set, the base will include scroll bars to allow
263; viewing a large base through a smaller viewport.
264;
265; @keyword SET_VALUE
266; The initial value of the buttons. This is equivalent
267; to the later statement:
268;
269; WIDGET_CONTROL, widget, set_value=value
270;
271; @keyword SPACE
272; The space, in pixels, to be left around the edges
273; of a row or column major base. This keyword is
274; ignored if EXCLUSIVE or NONEXCLUSIVE are specified.
275;
276; @keyword UVALUE
277; The user value to be associated with the widget.
278;
279; @keyword UNAME
280; The user name to be associated with the widget.
281;
282; @keyword XOFFSET
283; The X offset of the widget relative to its parent.
284;
285; @keyword XPAD
286; The horizontal space, in pixels, between children
287; of a row or column major base. Ignored if EXCLUSIVE
288; or NONEXCLUSIVE are specified.
289;
290; @keyword XSIZE
291; The width of the base.
292; @keyword X_SCROLL_SIZE
293; The width of the viewport if SCROLL is specified.
294;
295; @keyword YOFFSET
296; The Y offset of the widget relative to its parent.
297;
298; @keyword YPAD
299; The vertical space, in pixels, between children of
300; a row or column major base. Ignored if EXCLUSIVE
301; or NONEXCLUSIVE are specified.
302;
303; @keyword YSIZE
304; The height of the base.
305;
306; @keyword Y_SCROLL_SIZE
307; The height of the viewport if SCROLL is specified.
308;
309; @returns
310; The ID of the created widget is returned.
311;
312; @restrictions
313; This widget generates event structures with the following definition:
314;
315;       event = { ID:0L, TOP:0L, HANDLER:0L, SELECT:0, VALUE:0 }
316;
317; The SELECT field is passed through from the button event. VALUE is
318; either the INDEX, ID, NAME, or BUTTON_UVALUE of the button,
319; depending on how the widget was created.
320;
321; @restrictions
322; Only buttons with textual names are handled by this widget.
323; Bitmaps are not understood.
324;
325; @history
326; 15 June 1992, AB
327; 7 April 1993, AB, Removed state caching.
328; 6 Oct. 1994, KDB, Font keyword is not applied to the label.
329; 10 FEB 1995, DJC  fixed bad bug in event procedure, getting
330;                         id of stash widget.
331; 11 April 1995, AB Removed Motif special cases.
332;
333; Copyright (c) 1992-2005, Research Systems, Inc.  All rights reserved.
334;   Unauthorized reproduction prohibited.
335;
336; @version
337; $Id$
338;
339;-
340FUNCTION cw_bgroup, parent, names, $
341    BUTTON_UVALUE = button_uvalue, COLUMN=column, EVENT_FUNCT = efun, $
342    EXCLUSIVE=excl, FONT=font, FRAME=frame, IDS=ids, LABEL_TOP=label_top, $
343    LABEL_LEFT=label_left, MAP=map, $
344    NONEXCLUSIVE=nonexcl, NO_RELEASE=no_release, RETURN_ID=return_id, $
345    RETURN_INDEX=return_index, RETURN_NAME=return_name, $
346    ROW=row, SCROLL=scroll, SET_VALUE=sval, SPACE=space, $
347    TAB_MODE=tab_mode, UVALUE=uvalue, $
348    XOFFSET=xoffset, XPAD=xpad, XSIZE=xsize, X_SCROLL_SIZE=x_scroll_size,$
349    YOFFSET=yoffset, YPAD=ypad, YSIZE=ysize, Y_SCROLL_SIZE=y_scroll_size, $
350    UNAME=uname
351;
352  compile_opt hidden, idl2, strictarrsubs
353;
354  IF (N_PARAMS() ne 2) THEN ras = report('Incorrect number of arguments')
355
356  ON_ERROR, 2                       ;return to caller
357
358  ; Set default values for the keywords
359  version = WIDGET_INFO(/version)
360  if (version.toolkit eq 'OLIT') then def_space_pad = 4 else def_space_pad = 3
361  IF (N_ELEMENTS(column) eq 0)      then column = 0
362  IF (N_ELEMENTS(excl) eq 0)        then excl = 0
363  IF (N_ELEMENTS(frame) eq 0)       then frame = 0
364  IF (N_ELEMENTS(map) eq 0)     then map=1
365  IF (N_ELEMENTS(nonexcl) eq 0)     then nonexcl = 0
366  IF (N_ELEMENTS(no_release) eq 0)  then no_release = 0
367  IF (N_ELEMENTS(row) eq 0)     then row = 0
368  IF (N_ELEMENTS(scroll) eq 0)      then scroll = 0
369  IF (N_ELEMENTS(space) eq 0)       then space = def_space_pad
370  IF (N_ELEMENTS(uname) eq 0)      then uname = 'CW_BGROUP_UNAME'
371  IF (N_ELEMENTS(uvalue) eq 0)      then uvalue = 0
372  IF (N_ELEMENTS(xoffset) eq 0)     then xoffset=0
373  IF (N_ELEMENTS(xpad) eq 0)        then xpad = def_space_pad
374  IF (N_ELEMENTS(xsize) eq 0)       then xsize = 0
375  IF (N_ELEMENTS(x_scroll_size) eq 0)   then x_scroll_size = 0
376  IF (N_ELEMENTS(yoffset) eq 0)     then yoffset=0
377  IF (N_ELEMENTS(ypad) eq 0)        then ypad = def_space_pad
378  IF (N_ELEMENTS(ysize) eq 0)       then ysize = 0
379  IF (N_ELEMENTS(y_scroll_size) eq 0)   then y_scroll_size = 0
380
381
382
383
384  top_base = 0L
385  if (n_elements(label_top) ne 0) then begin
386    next_base = WIDGET_BASE(parent, XOFFSET=xoffset, YOFFSET=yoffset, /COLUMN)
387    if(keyword_set(font))then $
388       junk = WIDGET_LABEL(next_base, value=label_top,font=font) $
389    else    junk = WIDGET_LABEL(next_base, value=label_top)
390    top_base = next_base
391  endif else next_base = parent
392
393  if (n_elements(label_left) ne 0) then begin
394    next_base = WIDGET_BASE(next_base, XOFFSET=xoffset, YOFFSET=yoffset, /ROW)
395    if(keyword_set(font))then $
396       junk = WIDGET_LABEL(next_base, value=label_left, font=font) $
397    else junk = WIDGET_LABEL(next_base, value=label_left)
398    if (top_base eq 0L) then top_base = next_base
399  endif
400  ; We need some kind of outer base to hold the users UVALUE
401  if (top_base eq 0L) then begin
402    top_base = WIDGET_BASE(parent, XOFFSET=xoffset, YOFFSET=yoffset)
403    next_base = top_base
404  endif
405  If (top_base EQ next_base) THEN $
406     next_base = WIDGET_BASE(top_base, Xpad=1, Ypad=1, Space=1)
407
408  ; Set top level base attributes
409  WIDGET_CONTROL, top_base, MAP=map, $
410    FUNC_GET_VALUE='CW_BGROUP_GETV', PRO_SET_VALUE='CW_BGROUP_SETV', $
411    SET_UVALUE=uvalue, SET_UNAME=uname
412
413  ; Tabbing
414  if (n_elements(tab_mode) ne 0) then begin
415    WIDGET_CONTROL, top_base, TAB_MODE=tab_mode
416    WIDGET_CONTROL, next_base, TAB_MODE=tab_mode
417  end
418
419  ; The actual button holding base
420  base = WIDGET_BASE(next_base, COLUMN=column, EXCLUSIVE=excl, FRAME=frame, $
421    NONEXCLUSIVE=nonexcl, ROW=row, SCROLL=scroll, SPACE=space, $
422    XPAD=xpad, XSIZE=xsize, X_SCROLL_SIZE=x_scroll_size, $
423    YPAD=ypad, YSIZE=ysize, Y_SCROLL_SIZE=y_scroll_size, $
424    EVENT_FUNC='CW_BGROUP_EVENT', $
425    UVALUE=WIDGET_INFO(top_base, /child))
426
427
428  n = n_elements(names)
429  ids = lonarr(n)
430  for i = 0, n-1 do begin
431    if (n_elements(font) eq 0) then begin
432      ids[i] = WIDGET_BUTTON(base, value=names[i], UVALUE=i, $
433      UNAME=uname+'_BUTTON'+STRTRIM(i,2))
434    endif else begin
435      ids[i] = WIDGET_BUTTON(base, value=names[i], FONT=font, $
436      UVALUE=i, UNAME=uname+'_BUTTON'+STRTRIM(i,2))
437    endelse
438  endfor
439
440  ; Keep the state info in the real (inner) base UVALUE.
441  ; Pick an event value type:
442  ; 0 - Return ID
443  ; 1 - Return INDEX
444  ; 2 - Return NAME
445  ret_type = 1
446  if KEYWORD_SET(RETURN_ID) then ret_type = 0
447  if KEYWORD_SET(RETURN_NAME) then ret_type = 2
448  if KEYWORD_SET(BUTTON_UVALUE) then ret_type = 3
449    case ret_type of
450      0: ret_arr = ids
451      1: ret_arr = indgen(n)
452      2: ret_arr = names
453      3: ret_arr = button_uvalue
454    endcase
455  type = 0
456  if (excl ne 0) then type = 1
457
458  if (nonexcl ne 0) then type = 2
459  if n_elements(efun) le 0 then efun = ''
460  state = { type:type, $    ; 0-Standard, 1-Exclusive, 2-Non-exclusive
461        base: top_base, $   ; cw_bgroup base...
462        ret_arr:ret_arr, $  ; Vector of event values
463        efun : efun, $  ; Name of event fcn
464        nonexcl_curpos:intarr(n), $ ; If non-exclus, tracks state
465        excl_pos:0, $           ; If exclusive, current button
466        ids:ids, $          ; Ids of buttons
467        no_release:no_release }
468  WIDGET_CONTROL, WIDGET_INFO(top_base, /CHILD), SET_UVALUE=state, /NO_COPY
469
470  if (n_elements(sval) ne 0) then CW_BGROUP_SETV, top_base, sval
471
472  return, top_base
473END
Note: See TracBrowser for help on using the repository browser.