source: trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_calendar.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: 15.4 KB
Line 
1; IDL> testwid,julday(1,1,1980)+lindgen(100)*5
2;
3; PRO testwid_event, event
4;     ComboboxId = widget_info(event.top,find_by_uname = 'c''est lui')
5;    widget_control, event.id, get_uvalue=uval
6;    if n_elements(uval) EQ 0 then return
7;    case uval of
8;       'done':widget_control, event.top, /destroy
9;       'set':BEGIN
10;          widget_control, event.id, get_value = value
11;          widget_control, ComboboxId, set_value = value
12;       END
13;       'get':BEGIN
14;          widget_control, ComboboxId, get_value = value
15;          help,  value, /struct
16;       END
17;       ELSE:
18;    endcase
19;    return
20; end
21; PRO testwid, calendar, date0, _extra = ex
22;    base=widget_base(/COLUMN)
23; print, 'base=', base
24;    nothing = widget_label(base, value = 'beginning of the test')
25; ;
26;    nothing = cw_calendar(base,calendar, date0, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui' )
27; print, 'cw_calendar ID =', nothing
28; ;
29;    nothing = widget_label(base, value = 'end of the test')
30;     nothing = widget_text(base, value = string(calendar[0]), uvalue = 'set', /editable)
31;     nothing = widget_button(base, value = 'get', uvalue = 'get')
32;     nothing = widget_button(base, value = 'done', uvalue = 'done')
33;    widget_control, base, /REALIZE
34;    xmanager,'testwid', base
35;    return
36; END
37;
38;
39;+
40;
41; @file_comments
42;
43; @categories
44; Compound widget
45;
46; @param ID
47;
48; @param VALUE
49; It is the default tick mark value (a floating-point number).
50;
51; @returns
52;
53; @uses
54;
55; @restrictions
56;
57; @examples
58;
59; @history
60;
61; @version
62; $Id$
63;-
64;
65PRO cw_calendar_set_value, id, value
66;
67  compile_opt strictarr, strictarrsubs
68;
69@cm_4cal
70; get back the calendar and its related informations
71  winfo_id = widget_info(id, find_by_uname = 'infocal')
72  widget_control, winfo_id, get_uvalue = infowid
73  key_caltype = infowid.caltype
74
75; high freqeuncy calendar
76  IF keyword_set(infowid.fakecal) THEN BEGIN
77    value2 = date2jul(long(value)) - infowid.fakecal
78    IF value2 LT n_elements(infowid.calendar) AND value2 GE 0 THEN BEGIN
79      stepid = widget_info(id, find_by_uname = 'step')
80      widget_control, stepid, set_value = {combobox_select:value2}
81      infowid.date = jul2date(value2 + infowid.fakecal)
82      widget_control, winfo_id, set_uvalue = infowid
83    ENDIF
84  ENDIF ELSE BEGIN
85;
86    value = long(value[0])
87; make sure the value correspond
88    value = jul2date(date2jul(value))
89; define year month day
90    year = value/10000l
91    month = (value MOD 10000L)/100L
92    day = value MOD 100L
93; check that the date exists in the calendar
94  if (where(infowid.calendar EQ julday(month, day, year)))[0] EQ - 1 then return
95; update the value of infocal
96    infowid.date = value
97    widget_control, winfo_id, set_uvalue = infowid
98; update the combobox if needed...
99    possiblecase = ['day', 'month', 'year']
100    for name = 2, 0, -1 do BEGIN
101; call set_cal_combobox with out = 2 to specify that the call is coming
102; from cw_calendar_set_value
103      if widget_info(id, find_by_uname = possiblecase[name]) NE 0 then $
104         set_cal_combobox, {handler:id, out:2}, possiblecase[name], value
105    ENDFOR
106  ENDELSE
107;
108  return
109end
110;----------------------------------------------------------------------
111;+
112; @file_comments
113;
114;
115; @categories
116; Compound widget
117;
118; @param ID
119;
120;
121; @returns
122;
123; @uses
124;
125; @restrictions
126;
127; @examples
128;
129; @history
130;
131; @version
132; $Id$
133;-
134;
135FUNCTION cw_calendar_get_value, id
136;
137  compile_opt strictarr, strictarrsubs
138;
139  winfo_id = widget_info(id, find_by_uname = 'infocal')
140  widget_control, winfo_id, get_uvalue = infowid
141  return, infowid.date
142END
143;----------------------------------------------------------------------
144;+
145; @file_comments
146;
147;
148; @categories
149; Compound widget
150;
151; @param ID
152;
153;
154; @param WINFOID
155;
156;
157; @returns
158;
159; @uses
160;
161; @restrictions
162;
163; @examples
164;
165; @history
166;
167; @version
168; $Id$
169;-
170;
171FUNCTION get_cal_value, id, winfoid
172;
173  compile_opt strictarr, strictarrsubs
174;
175  winfo_id = widget_info(id, find_by_uname = 'infocal')
176  widget_control, winfo_id, get_uvalue = infowid
177  oldate = infowid.date
178;-------------day-----------------
179  wid_id = widget_info(id, find_by_uname = 'day')
180  if wid_id NE 0 then BEGIN
181    widget_control, wid_id, get_value = wid_value
182    date = long(wid_value.combobox_gettext)
183  ENDIF ELSE date = oldate MOD 100L
184;-------------month---------------
185  wid_id = widget_info(id, find_by_uname = 'month')
186  if wid_id NE 0 then BEGIN
187    widget_control, wid_id, get_value = wid_value
188    allmonths = string(format = '(C(CMoA))', 31*(indgen(12)))
189    month = (where(allmonths EQ wid_value.combobox_gettext))[0] + 1
190    date = date + 100L * long(month)
191  ENDIF ELSE date = date + (oldate MOD 10000L)/100L*100L
192;-------------year----------------
193  wid_id = widget_info(id, find_by_uname = 'year')
194  widget_control, wid_id, get_value = wid_value
195  date = date + 10000L * long(wid_value.combobox_gettext)
196;
197  IF arg_present(winfoid) NE 0 THEN BEGIN
198    winfoid = winfo_id
199    infowid.date = date
200    return, infowid
201  ENDIF ELSE return, date
202end
203;----------------------------------------------------------------------
204; redefine the value and index position of the combobox
205;+
206; @file_comments
207;
208;
209; @categories
210; Compound widget
211;
212; @param EVENT
213;
214;
215; @param CASENAME
216;
217;
218; @param DATE0
219;
220;
221; @returns
222;
223; @uses
224;
225; @restrictions
226;
227; @examples
228;
229; @history
230;
231; @version
232; $Id$
233;-
234PRO set_cal_combobox, event, casename, date0
235;
236  compile_opt strictarr, strictarrsubs
237;
238; casename: Which widget shall we move: 'day', 'month' or 'year' ?
239  wid_id = widget_info(event.handler, find_by_uname = casename)
240; we get back the calendar...
241  winfo_id = widget_info(event.handler, find_by_uname = 'infocal')
242  widget_control, winfo_id, get_uvalue = infowid
243  caldat, infowid.calendar, monthcal, daycal, yearcal
244; ... and the current date
245  IF n_elements(date0) EQ 0 then date0 = get_cal_value(event.handler)
246  year0 = date0/10000L
247  month0 = (date0 MOD 10000L)/100L
248  day0 = date0 MOD 100L
249; index of days/months/years according to date0
250  case casename of
251    'day':BEGIN
252; list of days corresponding to month0 and year0
253      index = where(monthcal EQ month0 AND yearcal EQ year0)
254      current = daycal[index]
255    END
256    'month':BEGIN
257; list of months corresponding to year0
258      index = where(yearcal EQ year0)
259      current = monthcal[index]
260; keep only the uniq values
261      indexbis = uniq(current)
262      index = index[indexbis]
263      current = current[indexbis]
264    END
265    'year':BEGIN
266; keep only the uniq years
267      index = uniq(yearcal)
268      current = yearcal[index]
269    END
270  ENDCASE
271; we update the uvalue of the widget
272  widget_control, wid_id, set_uvalue = {name:casename}
273; for event.out = 0, we store the previous position of the combobox to use
274; it as the default position.
275  IF event.out EQ 0 THEN widget_control, wid_id, get_value = oldselect
276; we redefine the new list
277  if casename EQ 'month' then begin
278    widget_control, wid_id, set_value = string(format = '(C(CMoA))', 31*(current-1))
279  ENDIF ELSE BEGIN
280    widget_control, wid_id, set_value = strtrim(current, 1)
281  ENDELSE
282; specify the index position within the new list of values.
283  widget_control, wid_id, get_value = combobox
284  CASE event.out OF
285; -1: we put to the biggest position
286    -1:selected = combobox.combobox_number - 1
287; 0: same as the previous position is the best choice...
288    0:selected = oldselect.combobox_index < (combobox.combobox_number - 1)
289; 1: we put to the smallest position
290    1:selected = 0
291; 2: a new date has been specified...
292    2:BEGIN
293      case casename of
294        'day':selected = (where(current EQ day0))[0]
295        'month':selected = (where(current EQ month0))[0]
296        'year':selected = (where(current EQ year0))[0]
297      ENDCASE
298    END
299  ENDCASE
300  widget_control, wid_id, set_value = {combobox_select:selected}
301; update the date...
302  infowid.date = get_cal_value(event.handler)
303  widget_control, winfo_id, set_uvalue = infowid
304  return
305end
306;----------------------------------------------------------------------
307; move cyclically the calendar to the
308; value 0 if event.out=1 or combobox_number-1 if event.out=-1
309;+
310; @file_comments
311;
312;
313; @categories
314; Compound widget
315;
316; @param EVENT
317;
318;
319; @param CASENAME
320;
321;
322; @returns
323;
324; @uses
325;
326; @restrictions
327;
328; @examples
329;
330; @history
331;
332; @version
333; $Id$
334;-
335PRO move, event, casename
336;
337  compile_opt strictarr, strictarrsubs
338;
339   possiblecase = ['day', 'month', 'year', 'impossiblecase']
340   id = widget_info(event.handler, find_by_uname = casename)
341   widget_control, id, get_value = wvalue
342; we try to move but we are already at the beginning/end of the combobox
343; wvalue.combobox_index EQ (wvalue.combobox_number-1) and event.out EQ 1
344; wvalue.combobox_index EQ 0 and event.out EQ -1 (move is not called when out eq 0)
345   whichcase = (where(possiblecase EQ casename))[0]
346   if wvalue.combobox_index EQ (wvalue.combobox_number-1)*(event.out EQ 1) THEN BEGIN
347      if widget_info(event.handler, find_by_uname = possiblecase[whichcase+1]) EQ 0 then begin
348; it is impossible to move the "next" combobox...
349         widget_control, id, get_value = widvalue
350; we set to "widvalue.combobox_number-1" when event.out EQ -1
351; and to 0 when event.out EQ 1
352         selected = (widvalue.combobox_number-1)*(event.out EQ -1)
353         widget_control, id, set_value = {combobox_select:selected}
354; we call move for the next combobox
355      ENDIF ELSE move, event, possiblecase[whichcase+1]
356; it is possible to move from +/- 1
357   ENDIF ELSE widget_control, id, set_value = {combobox_select:wvalue.combobox_index+event.out}
358   set_cal_combobox, event, possiblecase[whichcase-1]
359   return
360end
361;----------------------------------------------------------------------
362;+
363; @file_comments
364;
365;
366; @categories
367; Compound widget
368;
369; @param EVENT
370;
371;
372; @returns
373;
374; @uses
375;
376; @restrictions
377;
378; @examples
379;
380; @history
381;
382; @version
383; $Id$
384;-
385FUNCTION cw_calendar_event, event
386;
387@cm_4cal
388  compile_opt strictarr, strictarrsubs
389;
390  winfo_id = widget_info(event.handler, find_by_uname = 'infocal')
391  widget_control, winfo_id, get_uvalue = infowid
392  key_caltype = infowid.caltype
393;
394  widget_control, event.id, get_uvalue = uval
395; high frequency calendar
396  IF uval.name EQ 'step' THEN BEGIN
397    infowid.date = jul2date(event.index + infowid.fakecal)
398  ENDIF ELSE BEGIN
399;
400    possiblecase = ['day', 'month', 'year', 'impossiblecase']
401    whichcase = (where(possiblecase EQ uval.name))[0]
402    if event.out NE 0 then BEGIN ; we use the +/- button and we want to go out of the combobox:
403; to index = -1 (event.out=-1) or to index = combobox_number (event.out=1)
404; we try to move the combobox just right, with name: possiblecase[whichcase+1]
405      if widget_info(event.handler, find_by_uname = possiblecase[whichcase+1]) EQ 0 then BEGIN
406; this widget do not exist we set cyclically the current widget to the
407; value 0 if event.out=1 or combobox_number-1 if event.out=-1
408        widget_control, event.id, get_value = widvalue
409        selected = (widvalue.combobox_number-1)*(event.out EQ -1)
410        widget_control, event.id, set_value = {combobox_select:selected}
411      ENDIF ELSE move, event, possiblecase[whichcase+1]
412    ENDIF
413; if we changed month(year), we need to update the day (and month) list
414    if uval.name NE 'day' then begin
415      event.out = 0
416      for name = whichcase-1, 0, -1 do BEGIN
417        if widget_info(event.handler, find_by_uname = possiblecase[name]) NE 0 then $
418           set_cal_combobox, event, possiblecase[name]
419      endfor
420    ENDIF
421; we update the date
422    infowid = get_cal_value(event.handler, winfo_id)
423  ENDELSE
424;
425  widget_control, winfo_id, set_uvalue = infowid
426  return, {CW_CALENDAR, ID:event.handler, TOP:event.top, HANDLER:0L $
427           , VALUE:infowid.date, FAKECAL: infowid.fakecal}
428end
429;----------------------------------------------------------------------
430;----------------------------------------------------------------------
431;+
432; @file_comments
433;
434;
435; @categories
436; Compound widget
437;
438; @param PARENT {in}{required}
439; The widget ID of the parent widget.
440;
441; @param CALENDAR
442;
443;
444; @param JDATE0
445;
446; @keyword CALTYPE
447;
448; @keyword FAKECAL
449;
450;
451; @keyword UVALUE
452;
453; @keyword UNAME
454;
455;
456; @keyword _EXTRA
457; Used to pass keywords
458;
459; @returns
460;
461; @uses
462;
463; @restrictions
464;
465; @examples
466;
467; @history
468;
469; @version
470; $Id$
471;
472; @todo
473; seb
474;
475;-
476;
477FUNCTION cw_calendar, parent, calendar, jdate0, CALTYPE = CALTYPE, FAKECAL = fakecal, UVALUE = uvalue, UNAME = uname, _EXTRA = ex
478;
479@cm_4cal
480;
481  compile_opt strictarr, strictarrsubs
482;
483  if keyword_set(caltype) then key_caltype = caltype
484; months days years found in the calendar
485  caldat, calendar, monthcal, daycal, yearcal, hourcal, mincal, scdcal
486; starting date
487  if n_elements(jdate0) EQ 0 then jdate0 = calendar[0]
488  if (where(calendar EQ jdate0))[0] EQ -1 then jdate0 = calendar[0]
489;
490  caldat, jdate0, month0, day0, year0
491; test the type of calendar
492  if n_elements(calendar) GT 1 then BEGIN
493; each day have the same value
494    if n_elements(uniq(daycal, sort(daycal))) EQ 1 then monthly = 1
495; each month and each day have the same value
496    if keyword_set(monthly) AND n_elements(uniq(monthcal, sort(monthcal))) EQ 1 then yearly = 1
497  endif
498;---------------------------------------------------------------------------------------
499  if NOT keyword_set(uvalue) then uvalue = {dummy:''}
500  if NOT keyword_set(uname) then uname = ''
501  base0 = widget_base(parent, /ROW $
502                      , EVENT_FUNC = 'cw_calendar_event' $
503                      , FUNC_GET_VALUE = 'cw_calendar_get_value' $
504                      , PRO_SET_VALUE = 'cw_calendar_set_value' $
505                      , UVALUE = uvalue, UNAME = uname, space = 0, _extra = ex)
506;
507
508  if n_elements(fakecal) eq 0 then fakecal = 0
509  base = widget_base(base0, space = 0, uname = 'infocal' $
510                     , uvalue = {calendar:calendar, date:jul2date(jdate0), fakecal:fakecal, caltype: key_caltype})
511;
512  IF keyword_set(fakecal) THEN BEGIN
513    cmbbid = cw_combobox_pm(base, UVALUE = {name:'step'}, UNAME = 'step' $
514                            , value = strtrim(indgen(n_elements(calendar)), 1))
515    widget_control, cmbbid, set_value = {combobox_select:(where(calendar EQ jdate0))[0]}
516  ENDIF ELSE BEGIN
517;
518    vallen = widget_info(base, string_size = 'm')
519;-------------day-----------------
520    if NOT keyword_set(monthly)  then begin
521      dayindex = where(monthcal EQ month0 AND yearcal EQ year0)
522      currentday = daycal[dayindex]
523      currentday = strtrim(currentday, 1)
524      cmbbid = cw_combobox_pm(base, UVALUE = {name:'day'}, UNAME = 'day', value = currentday)
525      widget_control, cmbbid, set_value = {combobox_select:(where(long(currentday) EQ day0))[0]}
526    endif
527;-------------month---------------
528    if NOT keyword_set(yearly)  then BEGIN
529      monthindex = where(yearcal EQ year0)
530      currentmonth = long(monthcal[monthindex])
531; we suppress the repeted months
532      monthindexbis = uniq(currentmonth, sort(currentmonth))
533      monthindex = monthindex[monthindexbis]
534      currentmonth = currentmonth[monthindexbis]
535      xoff = (34 + 2*vallen[0])*(1-keyword_set(monthly))
536      cmbbid = cw_combobox_pm(base, UVALUE = {name:'month'}, UNAME = 'month', value = string(format = '(C(CMoA))', 31*(currentmonth-1)), xoffset = xoff)
537      widget_control, cmbbid, set_value = {combobox_select:(where(long(currentmonth) EQ month0))[0]}
538    endif
539;-------------year----------------
540    yearindex = uniq(yearcal, sort(yearcal))
541    currentyear = strtrim(yearcal[yearindex], 1)
542    xoff = (34 + 2*vallen[0])*(1-keyword_set(monthly)) + (33 + 3*vallen[0])*(1-keyword_set(yearly))
543    cmbbid = cw_combobox_pm(base, UVALUE = {name:'year'}, UNAME = 'year', value = currentyear, xoffset = xoff)
544    widget_control, cmbbid, set_value = {combobox_select:(where(long(currentyear) EQ year0))[0]}
545;-----------------------------
546  ENDELSE
547;
548  return, base
549end
Note: See TracBrowser for help on using the repository browser.