source: trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_calendar.pro @ 232

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

improvements/corrections of some *.pro headers

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