; IDL> testwid,julday(1,1,1980)+lindgen(100)*5 ; ; PRO testwid_event, event ; ComboboxId = widget_info(event.top,find_by_uname = 'c''est lui') ; widget_control, event.id, get_uvalue=uval ; if n_elements(uval) EQ 0 then return ; case uval of ; 'done':widget_control, event.top, /destroy ; 'set':BEGIN ; widget_control, event.id, get_value = value ; widget_control, ComboboxId, set_value = value ; END ; 'get':BEGIN ; widget_control, ComboboxId, get_value = value ; help, value, /struct ; END ; ELSE: ; endcase ; return ; end ; PRO testwid, calendar, date0, _extra = ex ; base=widget_base(/COLUMN) ; print, 'base=', base ; nothing = widget_label(base, value = 'beginning of the test') ; ; ; nothing = cw_calendar(base,calendar, date0, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui' ) ; print, 'cw_calendar ID =', nothing ; ; ; nothing = widget_label(base, value = 'end of the test') ; nothing = widget_text(base, value = string(calendar[0]), uvalue = 'set', /editable) ; nothing = widget_button(base, value = 'get', uvalue = 'get') ; nothing = widget_button(base, value = 'done', uvalue = 'done') ; widget_control, base, /REALIZE ; xmanager,'testwid', base ; return ; END ; ; ;+ ; ; @file_comments ; ; @categories ; Compound widget ; ; @param ID ; ; @param VALUE ; It is the default tick mark value (a floating-point number). ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- ; PRO cw_calendar_set_value, id, value ; compile_opt strictarr, strictarrsubs ; @cm_4cal ; get back the calendar and its related informations winfo_id = widget_info(id, find_by_uname = 'infocal') widget_control, winfo_id, get_uvalue = infowid key_caltype = infowid.caltype ; high freqeuncy calendar IF keyword_set(infowid.fakecal) THEN BEGIN value2 = date2jul(long(value)) - infowid.fakecal IF value2 LT n_elements(infowid.calendar) AND value2 GE 0 THEN BEGIN stepid = widget_info(id, find_by_uname = 'step') widget_control, stepid, set_value = {combobox_select:value2} infowid.date = jul2date(value2 + infowid.fakecal) widget_control, winfo_id, set_uvalue = infowid ENDIF ENDIF ELSE BEGIN ; value = long(value[0]) ; make sure the value correspond value = jul2date(date2jul(value)) ; define year month day year = value/10000l month = (value MOD 10000L)/100L day = value MOD 100L ; check that the date exists in the calendar if (where(infowid.calendar EQ julday(month, day, year)))[0] EQ - 1 then return ; update the value of infocal infowid.date = value widget_control, winfo_id, set_uvalue = infowid ; update the combobox if needed... possiblecase = ['day', 'month', 'year'] for name = 2, 0, -1 do BEGIN ; call set_cal_combobox with out = 2 to specify that the call is coming ; from cw_calendar_set_value if widget_info(id, find_by_uname = possiblecase[name]) NE 0 then $ set_cal_combobox, {handler:id, out:2}, possiblecase[name], value ENDFOR ENDELSE ; return end ;---------------------------------------------------------------------- ;+ ; @file_comments ; ; ; @categories ; Compound widget ; ; @param ID ; ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- ; FUNCTION cw_calendar_get_value, id ; compile_opt strictarr, strictarrsubs ; winfo_id = widget_info(id, find_by_uname = 'infocal') widget_control, winfo_id, get_uvalue = infowid return, infowid.date END ;---------------------------------------------------------------------- ;+ ; @file_comments ; ; ; @categories ; Compound widget ; ; @param ID ; ; ; @param WINFOID ; ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- ; FUNCTION get_cal_value, id, winfoid ; compile_opt strictarr, strictarrsubs ; winfo_id = widget_info(id, find_by_uname = 'infocal') widget_control, winfo_id, get_uvalue = infowid oldate = infowid.date ;-------------day----------------- wid_id = widget_info(id, find_by_uname = 'day') if wid_id NE 0 then BEGIN widget_control, wid_id, get_value = wid_value date = long(wid_value.combobox_gettext) ENDIF ELSE date = oldate MOD 100L ;-------------month--------------- wid_id = widget_info(id, find_by_uname = 'month') if wid_id NE 0 then BEGIN widget_control, wid_id, get_value = wid_value allmonths = string(format = '(C(CMoA))', 31*(indgen(12))) month = (where(allmonths EQ wid_value.combobox_gettext))[0] + 1 date = date + 100L * long(month) ENDIF ELSE date = date + (oldate MOD 10000L)/100L*100L ;-------------year---------------- wid_id = widget_info(id, find_by_uname = 'year') widget_control, wid_id, get_value = wid_value date = date + 10000L * long(wid_value.combobox_gettext) ; IF arg_present(winfoid) NE 0 THEN BEGIN winfoid = winfo_id infowid.date = date return, infowid ENDIF ELSE return, date end ;---------------------------------------------------------------------- ; redefine the value and index position of the combobox ;+ ; @file_comments ; ; ; @categories ; Compound widget ; ; @param EVENT ; ; ; @param CASENAME ; ; ; @param DATE0 ; ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- PRO set_cal_combobox, event, casename, date0 ; compile_opt strictarr, strictarrsubs ; ; casename: Which widget shall we move: 'day', 'month' or 'year' ? wid_id = widget_info(event.handler, find_by_uname = casename) ; we get back the calendar... winfo_id = widget_info(event.handler, find_by_uname = 'infocal') widget_control, winfo_id, get_uvalue = infowid caldat, infowid.calendar, monthcal, daycal, yearcal ; ... and the current date IF n_elements(date0) EQ 0 then date0 = get_cal_value(event.handler) year0 = date0/10000L month0 = (date0 MOD 10000L)/100L day0 = date0 MOD 100L ; index of days/months/years according to date0 case casename of 'day':BEGIN ; list of days corresponding to month0 and year0 index = where(monthcal EQ month0 AND yearcal EQ year0) current = daycal[index] END 'month':BEGIN ; list of months corresponding to year0 index = where(yearcal EQ year0) current = monthcal[index] ; keep only the uniq values indexbis = uniq(current) index = index[indexbis] current = current[indexbis] END 'year':BEGIN ; keep only the uniq years index = uniq(yearcal) current = yearcal[index] END ENDCASE ; we update the uvalue of the widget widget_control, wid_id, set_uvalue = {name:casename} ; for event.out = 0, we store the previous position of the combobox to use ; it as the default position. IF event.out EQ 0 THEN widget_control, wid_id, get_value = oldselect ; we redefine the new list if casename EQ 'month' then begin widget_control, wid_id, set_value = string(format = '(C(CMoA))', 31*(current-1)) ENDIF ELSE BEGIN widget_control, wid_id, set_value = strtrim(current, 1) ENDELSE ; specify the index position within the new list of values. widget_control, wid_id, get_value = combobox CASE event.out OF ; -1: we put to the biggest position -1:selected = combobox.combobox_number - 1 ; 0: same as the previous position is the best choice... 0:selected = oldselect.combobox_index < (combobox.combobox_number - 1) ; 1: we put to the smallest position 1:selected = 0 ; 2: a new date has been specified... 2:BEGIN case casename of 'day':selected = (where(current EQ day0))[0] 'month':selected = (where(current EQ month0))[0] 'year':selected = (where(current EQ year0))[0] ENDCASE END ENDCASE widget_control, wid_id, set_value = {combobox_select:selected} ; update the date... infowid.date = get_cal_value(event.handler) widget_control, winfo_id, set_uvalue = infowid return end ;---------------------------------------------------------------------- ; move cyclically the calendar to the ; value 0 if event.out=1 or combobox_number-1 if event.out=-1 ;+ ; @file_comments ; ; ; @categories ; Compound widget ; ; @param EVENT ; ; ; @param CASENAME ; ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- PRO move, event, casename ; compile_opt strictarr, strictarrsubs ; possiblecase = ['day', 'month', 'year', 'impossiblecase'] id = widget_info(event.handler, find_by_uname = casename) widget_control, id, get_value = wvalue ; we try to move but we are already at the beginning/end of the combobox ; wvalue.combobox_index EQ (wvalue.combobox_number-1) and event.out EQ 1 ; wvalue.combobox_index EQ 0 and event.out EQ -1 (move is not called when out eq 0) whichcase = (where(possiblecase EQ casename))[0] if wvalue.combobox_index EQ (wvalue.combobox_number-1)*(event.out EQ 1) THEN BEGIN if widget_info(event.handler, find_by_uname = possiblecase[whichcase+1]) EQ 0 then begin ; it is impossible to move the "next" combobox... widget_control, id, get_value = widvalue ; we set to "widvalue.combobox_number-1" when event.out EQ -1 ; and to 0 when event.out EQ 1 selected = (widvalue.combobox_number-1)*(event.out EQ -1) widget_control, id, set_value = {combobox_select:selected} ; we call move for the next combobox ENDIF ELSE move, event, possiblecase[whichcase+1] ; it is possible to move from +/- 1 ENDIF ELSE widget_control, id, set_value = {combobox_select:wvalue.combobox_index+event.out} set_cal_combobox, event, possiblecase[whichcase-1] return end ;---------------------------------------------------------------------- ;+ ; @file_comments ; ; ; @categories ; Compound widget ; ; @param EVENT ; ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ;- FUNCTION cw_calendar_event, event ; @cm_4cal compile_opt strictarr, strictarrsubs ; winfo_id = widget_info(event.handler, find_by_uname = 'infocal') widget_control, winfo_id, get_uvalue = infowid key_caltype = infowid.caltype ; widget_control, event.id, get_uvalue = uval ; high frequency calendar IF uval.name EQ 'step' THEN BEGIN infowid.date = jul2date(event.index + infowid.fakecal) ENDIF ELSE BEGIN ; possiblecase = ['day', 'month', 'year', 'impossiblecase'] whichcase = (where(possiblecase EQ uval.name))[0] if event.out NE 0 then BEGIN ; we use the +/- button and we want to go out of the combobox: ; to index = -1 (event.out=-1) or to index = combobox_number (event.out=1) ; we try to move the combobox just right, with name: possiblecase[whichcase+1] if widget_info(event.handler, find_by_uname = possiblecase[whichcase+1]) EQ 0 then BEGIN ; this widget do not exist we set cyclically the current widget to the ; value 0 if event.out=1 or combobox_number-1 if event.out=-1 widget_control, event.id, get_value = widvalue selected = (widvalue.combobox_number-1)*(event.out EQ -1) widget_control, event.id, set_value = {combobox_select:selected} ENDIF ELSE move, event, possiblecase[whichcase+1] ENDIF ; if we changed month(year), we need to update the day (and month) list if uval.name NE 'day' then begin event.out = 0 for name = whichcase-1, 0, -1 do BEGIN if widget_info(event.handler, find_by_uname = possiblecase[name]) NE 0 then $ set_cal_combobox, event, possiblecase[name] endfor ENDIF ; we update the date infowid = get_cal_value(event.handler, winfo_id) ENDELSE ; widget_control, winfo_id, set_uvalue = infowid return, {CW_CALENDAR, ID:event.handler, TOP:event.top, HANDLER:0L $ , VALUE:infowid.date, FAKECAL: infowid.fakecal} end ;---------------------------------------------------------------------- ;---------------------------------------------------------------------- ;+ ; @file_comments ; ; ; @categories ; Compound widget ; ; @param PARENT {in}{required} ; The widget ID of the parent widget. ; ; @param CALENDAR ; ; ; @param JDATE0 ; ; @keyword CALTYPE ; ; @keyword FAKECAL ; ; ; @keyword UVALUE ; ; @keyword UNAME ; ; ; @keyword _EXTRA ; Used to pass keywords ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ; ; @todo ; seb ; ;- ; FUNCTION cw_calendar, parent, calendar, jdate0, CALTYPE = CALTYPE, FAKECAL = fakecal, UVALUE = uvalue, UNAME = uname, _EXTRA = ex ; @cm_4cal ; compile_opt strictarr, strictarrsubs ; if keyword_set(caltype) then key_caltype = caltype ; months days years found in the calendar caldat, calendar, monthcal, daycal, yearcal, hourcal, mincal, scdcal ; starting date if n_elements(jdate0) EQ 0 then jdate0 = calendar[0] if (where(calendar EQ jdate0))[0] EQ -1 then jdate0 = calendar[0] ; caldat, jdate0, month0, day0, year0 ; test the type of calendar if n_elements(calendar) GT 1 then BEGIN ; each day have the same value if n_elements(uniq(daycal, sort(daycal))) EQ 1 then monthly = 1 ; each month and each day have the same value if keyword_set(monthly) AND n_elements(uniq(monthcal, sort(monthcal))) EQ 1 then yearly = 1 endif ;--------------------------------------------------------------------------------------- if NOT keyword_set(uvalue) then uvalue = {dummy:''} if NOT keyword_set(uname) then uname = '' base0 = widget_base(parent, /ROW $ , EVENT_FUNC = 'cw_calendar_event' $ , FUNC_GET_VALUE = 'cw_calendar_get_value' $ , PRO_SET_VALUE = 'cw_calendar_set_value' $ , UVALUE = uvalue, UNAME = uname, space = 0, _extra = ex) ; if n_elements(fakecal) eq 0 then fakecal = 0 base = widget_base(base0, space = 0, uname = 'infocal' $ , uvalue = {calendar:calendar, date:jul2date(jdate0), fakecal:fakecal, caltype: key_caltype}) ; IF keyword_set(fakecal) THEN BEGIN cmbbid = cw_combobox_pm(base, UVALUE = {name:'step'}, UNAME = 'step' $ , value = strtrim(indgen(n_elements(calendar)), 1)) widget_control, cmbbid, set_value = {combobox_select:(where(calendar EQ jdate0))[0]} ENDIF ELSE BEGIN ; vallen = widget_info(base, string_size = 'm') ;-------------day----------------- if NOT keyword_set(monthly) then begin dayindex = where(monthcal EQ month0 AND yearcal EQ year0) currentday = daycal[dayindex] currentday = strtrim(currentday, 1) cmbbid = cw_combobox_pm(base, UVALUE = {name:'day'}, UNAME = 'day', value = currentday) widget_control, cmbbid, set_value = {combobox_select:(where(long(currentday) EQ day0))[0]} endif ;-------------month--------------- if NOT keyword_set(yearly) then BEGIN monthindex = where(yearcal EQ year0) currentmonth = long(monthcal[monthindex]) ; we suppress the repeted months monthindexbis = uniq(currentmonth, sort(currentmonth)) monthindex = monthindex[monthindexbis] currentmonth = currentmonth[monthindexbis] xoff = (34 + 2*vallen[0])*(1-keyword_set(monthly)) cmbbid = cw_combobox_pm(base, UVALUE = {name:'month'}, UNAME = 'month', value = string(format = '(C(CMoA))', 31*(currentmonth-1)), xoffset = xoff) widget_control, cmbbid, set_value = {combobox_select:(where(long(currentmonth) EQ month0))[0]} endif ;-------------year---------------- yearindex = uniq(yearcal, sort(yearcal)) currentyear = strtrim(yearcal[yearindex], 1) xoff = (34 + 2*vallen[0])*(1-keyword_set(monthly)) + (33 + 3*vallen[0])*(1-keyword_set(yearly)) cmbbid = cw_combobox_pm(base, UVALUE = {name:'year'}, UNAME = 'year', value = currentyear, xoffset = xoff) widget_control, cmbbid, set_value = {combobox_select:(where(long(currentyear) EQ year0))[0]} ;----------------------------- ENDELSE ; return, base end