Ignore:
Timestamp:
05/11/06 12:35:53 (18 years ago)
Author:
smasson
Message:

debug + new xxx

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_calendar.pro

    r51 r69  
    11; IDL> testwid,julday(1,1,1980)+lindgen(100)*5 
    22; 
    3 PRO testwid_event, event 
    4     DroplistId = 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, DroplistId, set_value = value 
    12       END 
    13       'get':BEGIN  
    14          widget_control, DroplistId, get_value = value 
    15          help,  value, /struct 
    16       END 
    17       ELSE: 
    18    endcase 
     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; 
     40PRO cw_calendar_set_value, id, value 
     41; 
     42  compile_opt strictarr, strictarrsubs  
     43; 
     44; 
     45@cm_4cal 
     46; get back the calendar and its related informations 
     47  winfo_id = widget_info(id, find_by_uname = 'infocal') 
     48  widget_control, winfo_id, get_uvalue = infowid 
     49  key_caltype = infowid.caltype 
     50   
     51; high freqeuncy calendar 
     52  IF keyword_set(infowid.fakecal) THEN BEGIN 
     53    value2 = date2jul(long(value)) - infowid.fakecal 
     54    IF value2 LT n_elements(infowid.calendar) AND value2 GE 0 THEN BEGIN   
     55      stepid = widget_info(id, find_by_uname = 'step') 
     56      widget_control, stepid, set_value = {combobox_select:value2} 
     57      infowid.date = jul2date(value2 + infowid.fakecal) 
     58      widget_control, winfo_id, set_uvalue = infowid 
     59    ENDIF 
     60  ENDIF ELSE BEGIN  
     61; 
     62    value = long(value[0]) 
     63; define year month day 
     64    year = value/10000l 
     65    month = (value MOD 10000L)/100L 
     66    day = value MOD 100L 
     67; make sure the values correspond to real dates 
     68    if year EQ 0 then year = -1  
     69    if month EQ 0 then month = 6 
     70    if day EQ 0 then day = 15 
     71; check that the date exists in the calendar 
     72  if (where(infowid.calendar EQ julday(month, day, year)))[0] EQ - 1 then return 
     73; update the value of infocal 
     74    infowid.date = value 
     75    widget_control, winfo_id, set_uvalue = infowid 
     76; update the combobox if needed... 
     77    possiblecase = ['day', 'month', 'year'] 
     78    for name = 2, 0, -1 do BEGIN 
     79; call set_cal_combobox with out = 2 to specify that the call is coming 
     80; from cw_calendar_set_value 
     81      if widget_info(id, find_by_uname = possiblecase[name]) NE 0 then $ 
     82         set_cal_combobox, {handler:id, out:2}, possiblecase[name], value 
     83    ENDFOR 
     84  ENDELSE 
     85; 
     86  return 
     87end 
     88;---------------------------------------------------------------------- 
     89FUNCTION cw_calendar_get_value, id 
     90; 
     91  compile_opt strictarr, strictarrsubs  
     92; 
     93  winfo_id = widget_info(id, find_by_uname = 'infocal') 
     94  widget_control, winfo_id, get_uvalue = infowid 
     95  return, infowid.date 
     96END 
     97;---------------------------------------------------------------------- 
     98FUNCTION get_cal_value, id, winfoid  
     99; 
     100  compile_opt strictarr, strictarrsubs  
     101; 
     102  winfo_id = widget_info(id, find_by_uname = 'infocal') 
     103  widget_control, winfo_id, get_uvalue = infowid 
     104  oldate = infowid.date 
     105;-------------day----------------- 
     106  wid_id = widget_info(id, find_by_uname = 'day') 
     107  if wid_id NE 0 then BEGIN 
     108    widget_control, wid_id, get_value = wid_value 
     109    date = long(wid_value.combobox_gettext) 
     110  ENDIF ELSE date = oldate MOD 100L 
     111;-------------month--------------- 
     112  wid_id = widget_info(id, find_by_uname = 'month') 
     113  if wid_id NE 0 then BEGIN 
     114    widget_control, wid_id, get_value = wid_value 
     115    allmonths = string(format = '(C(CMoA))', 31*(indgen(12))) 
     116    month = (where(allmonths EQ wid_value.combobox_gettext))[0] + 1  
     117    date = date + 100L * long(month) 
     118  ENDIF ELSE date = date + (oldate MOD 10000L)/100L 
     119;-------------year---------------- 
     120  wid_id = widget_info(id, find_by_uname = 'year') 
     121  widget_control, wid_id, get_value = wid_value 
     122  date = date + 10000L * long(wid_value.combobox_gettext) 
     123; 
     124  IF arg_present(winfoid) NE 0 THEN BEGIN 
     125    winfoid = winfo_id 
     126    infowid.date = date 
     127    return, infowid 
     128  ENDIF ELSE return, date 
     129end 
     130;---------------------------------------------------------------------- 
     131; redefine the value and index position of the combobox 
     132PRO set_cal_combobox, event, casename, date0 
     133; 
     134  compile_opt strictarr, strictarrsubs  
     135; 
     136; casename: Which widget shall we move: 'day', 'month' or 'year' ? 
     137  wid_id = widget_info(event.handler, find_by_uname = casename) 
     138; we get back the calendar... 
     139  winfo_id = widget_info(event.handler, find_by_uname = 'infocal') 
     140  widget_control, winfo_id, get_uvalue = infowid 
     141  caldat, infowid.calendar, monthcal, daycal, yearcal 
     142; ... and the current date 
     143  IF n_elements(date0) EQ 0 then date0 = get_cal_value(event.handler) 
     144  year0 = date0/10000L 
     145  month0 = (date0 MOD 10000L)/100L 
     146  day0 = date0 MOD 100L 
     147; index of days/months/years according to date0 
     148  case casename of 
     149    'day':BEGIN  
     150; list of days corresponding to month0 and year0 
     151      index = where(monthcal EQ month0 AND yearcal EQ year0) 
     152      current = daycal[index] 
     153    END 
     154    'month':BEGIN  
     155; list of months corresponding to year0 
     156      index = where(yearcal EQ year0) 
     157      current = monthcal[index] 
     158; keep only the uniq values 
     159      indexbis = uniq(current) 
     160      index = index[indexbis] 
     161      current = current[indexbis] 
     162    END 
     163    'year':BEGIN  
     164; keep only the uniq years 
     165      index = uniq(yearcal) 
     166      current = yearcal[index] 
     167    END 
     168  ENDCASE 
     169; we update the uvalue of the widget 
     170  widget_control, wid_id, set_uvalue = {name:casename} 
     171; for event.out = 0, we store the previous position of the combobox to use 
     172; it as the default position. 
     173  IF event.out EQ 0 THEN widget_control, wid_id, get_value = oldselect 
     174; we redefine the new list 
     175  if casename EQ 'month' then begin 
     176    widget_control, wid_id, set_value = string(format = '(C(CMoA))', 31*(current-1)) 
     177  ENDIF ELSE BEGIN  
     178    widget_control, wid_id, set_value = strtrim(current, 1) 
     179  ENDELSE 
     180; specify the index position within the new list of values. 
     181  widget_control, wid_id, get_value = combobox 
     182  CASE event.out OF 
     183; -1: we put to the biggest position 
     184    -1:selected = combobox.combobox_number - 1 
     185; 0: same as the previous position is the best choice... 
     186    0:selected = oldselect.combobox_index < (combobox.combobox_number - 1) 
     187; 1: we put to the smallest position 
     188    1:selected = 0 
     189; 2: a new date has been specified... 
     190    2:BEGIN  
     191      case casename of 
     192        'day':selected = (where(current EQ day0))[0] 
     193        'month':selected = (where(current EQ month0))[0] 
     194        'year':selected = (where(current EQ year0))[0] 
     195      ENDCASE 
     196    END 
     197  ENDCASE 
     198  widget_control, wid_id, set_value = {combobox_select:selected} 
     199; update the date... 
     200  infowid.date = get_cal_value(event.handler) 
     201  widget_control, winfo_id, set_uvalue = infowid 
     202  return 
     203end 
     204;---------------------------------------------------------------------- 
     205; move cyclicly the calendar to the 
     206; value 0 if event.out=1 or combobox_number-1 if event.out=-1 
     207PRO move, event, casename 
     208; 
     209  compile_opt strictarr, strictarrsubs  
     210; 
     211   possiblecase = ['day', 'month', 'year', 'impossiblecase'] 
     212   id = widget_info(event.handler, find_by_uname = casename) 
     213   widget_control, id, get_value = wvalue 
     214; we try to move but we are already at the beginning/end of the combobox 
     215; wvalue.combobox_index EQ (wvalue.combobox_number-1) and event.out EQ 1 
     216; wvalue.combobox_index EQ 0 and event.out EQ -1 (move is not called when out eq 0) 
     217   whichcase = (where(possiblecase EQ casename))[0] 
     218   if wvalue.combobox_index EQ (wvalue.combobox_number-1)*(event.out EQ 1) THEN BEGIN 
     219      if widget_info(event.handler, find_by_uname = possiblecase[whichcase+1]) EQ 0 then begin 
     220; it is impossible to move the "next" combobox... 
     221         widget_control, id, get_value = widvalue 
     222; we set to "widvalue.combobox_number-1" when event.out EQ -1 
     223; and to 0 when event.out EQ 1 
     224         selected = (widvalue.combobox_number-1)*(event.out EQ -1) 
     225         widget_control, id, set_value = {combobox_select:selected} 
     226; we call move for the next combobox 
     227      ENDIF ELSE move, event, possiblecase[whichcase+1] 
     228; it is possible to move from +/- 1 
     229   ENDIF ELSE widget_control, id, set_value = {combobox_select:wvalue.combobox_index+event.out} 
     230   set_cal_combobox, event, possiblecase[whichcase-1] 
    19231   return 
    20232end 
    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 PRO cw_calendar_set_value, id, value 
    41    possiblecase = ['day', 'month', 'year', 'century'] 
    42    name = 0 
    43    repeat begin 
    44       wid_id = widget_info(id,find_by_uname = possiblecase[name]) 
    45       name = name+1 
    46    endrep until wid_id NE 0 
    47    widget_control,wid_id, get_uvalue=wid_uvalue 
    48    value = long(value[0]) 
    49    year = value/10000l & month = (value-year*10000l)/100L & day = value-year*10000l-month*100L 
    50    if year EQ 0 then year = -1 & if month EQ 0 then month = 6 & if day EQ 0 then day = 15 
    51    julianvalue = julday(month, day, year) 
    52    if (where(wid_uvalue.calendar EQ julianvalue))[0] EQ - 1 then return 
    53    for name = 3, 0, -1 do BEGIN 
    54       if widget_info(id,find_by_uname = possiblecase[name]) NE 0  then $ 
    55          set_droplist, {handler:id, out:2}, possiblecase[name], value 
    56    endfor 
    57    return 
    58 end 
    59 ;---------------------------------------------------------------------- 
    60 FUNCTION cw_calendar_get_value, id 
    61    possiblecase = ['day', 'month', 'year', 'century'] 
    62    name = 0 
    63    repeat begin 
    64       wid_id = widget_info(id,find_by_uname = possiblecase[name]) 
    65       name = name+1 
    66    endrep until wid_id NE 0 
    67    widget_control,wid_id, get_uvalue=wid_uvalue 
    68    caldat, wid_uvalue.calendar,monthcal,daycal,yearcal 
    69    centurycal = yearcal/100L 
    70    if n_elements(centurycal[uniq(centurycal, sort(centurycal))]) NE 1 then $  
    71     yearcal = yearcal-centurycal*100 
    72    droplistname = ['day','month','year','century'] 
    73    for name = 0, n_elements(droplistname)-1  do begin 
    74       nothing = execute('wid_id = widget_info(id,find_by_uname = '''+droplistname[name]+''')') 
    75       if wid_id NE 0 then begin 
    76          widget_control,wid_id, get_value=wid_value 
    77          widget_control,wid_id, get_uvalue=wid_uvalue 
    78          nothing = execute('array = '+droplistname[name]+'cal[wid_uvalue.index]') 
    79          nothing = execute(droplistname[name]+' = array[wid_value.droplist_select]') 
    80       ENDIF ELSE nothing = execute(droplistname[name]+'= 0') 
    81    ENDFOR 
    82    return, 10000L*(year+100L*century)+100L*month+day 
    83 end 
    84 ;---------------------------------------------------------------------- 
    85 PRO set_droplist, event, casename, date0 
    86 ; casename: quel est le widget que l''on veut bouger: 'day', 'month', 
    87 ; 'year', 'century' ??? 
    88    wid_id = widget_info(event.handler,find_by_uname = casename) 
    89    possiblecase = ['day', 'month', 'year', 'century'] 
    90    whichcase = (where(possiblecase EQ casename))[0] 
    91 ; on recupere la uvalue attache au widget et qui nous donne ques sont 
    92 ; les 'day', 'month', 'year', 'century' en train d''etre traites et le 
    93 ; calendrier 
    94 ; on recuper ici le calendrier 
    95    widget_control,wid_id, get_uvalue=wid_uvalue 
    96    caldat, wid_uvalue.calendar,monthcal,daycal,yearcal 
    97    centurycal = yearcal/100 
    98 ; et la date courrante 
    99    if n_elements(date0) EQ 0 then date0 = cw_calendar_get_value(event.handler) 
    100    year0 = date0/10000l 
    101    century0 = year0/100 
    102    month0 = (date0-year0*10000l)/100L 
    103    day0 = date0-year0*10000l-month0*100L 
    104    if n_elements(centurycal[uniq(centurycal, sort(centurycal))]) NE 1 then BEGIN  
    105       yearcal = yearcal-centurycal*100 
    106       year0   = year0  -centurycal*100 
    107    ENDIF 
    108 ; index: 'day', 'month', 'year', 'century' possibles pour la date donnee 
    109    case casename of 
    110       'day':index = where(monthcal EQ month0 AND yearcal EQ year0 AND centurycal EQ century0) 
    111       'month':index = where(yearcal EQ year0 AND centurycal EQ century0) 
    112       'year':index = where(centurycal EQ century0) 
    113       'century':index = uniq(centurycal, sort(long(centurycal))) 
    114    ENDCASE 
    115 ; current: liste des mois possibles par ex 
    116    nothing = execute('current = '+possiblecase[whichcase]+'cal[index]') 
    117 ; supprime les boublons 
    118    indexbis = uniq(current, sort(current)) 
    119    index = index[indexbis]; 
    120 ; nouvelle liste des possibilites offertes par la droplist (par ex 
    121 ; liste des mois possibles) 
    122    current = current[indexbis] 
    123 ; on accualise la uvalue du widget (par ex on met la nouvelle liste de 
    124 ; mois possibles) 
    125    widget_control, wid_id, set_uvalue = {name:wid_uvalue.name, calendar:wid_uvalue.calendar, index:index} 
    126 ;on met en place la nouvelle liste possible 
    127    widget_control, wid_id, get_value = oldselect 
    128    if casename EQ 'month' then begin 
    129       widget_control, wid_id, set_value = string(format='(C(CMoA))',31*(current-1)) 
    130    ENDIF ELSE BEGIN  
    131       widget_control, wid_id, set_value = strtrim(current, 1) 
    132   ENDELSE 
    133 ; quel est l''index qu'il faut selectionner parmis la nouvelle liste! 
    134    widget_control, wid_id, get_value = droplist 
    135    if event.out EQ 2 then BEGIN  
    136     nothing = execute('widget_control, wid_id, set_value = {droplist_select:(where(current EQ '+casename+'0))[0]}')  
    137    ENDIF ELSE widget_control, wid_id, set_value $ 
    138     = {droplist_select:((droplist.droplist_number-1)*(event.out EQ -1)+oldselect.droplist_select*(event.out EQ 0)) < (droplist.droplist_number-1)} 
    139    return 
    140 end 
    141 ;---------------------------------------------------------------------- 
    142 PRO move, event, casename 
    143    possiblecase = ['day', 'month', 'year', 'century', 'impossiblecase'] 
    144    whichcase = (where(possiblecase EQ casename))[0] 
    145    id = widget_info(event.handler,find_by_uname = casename) 
    146    widget_control, id, get_value=wvalue 
    147    if wvalue.droplist_select EQ (wvalue.droplist_number-1)*(event.out EQ 1) THEN BEGIN 
    148       if casename EQ 'century' $ 
    149        OR widget_info(event.handler,find_by_uname = possiblecase[whichcase+1]) EQ 0 then begin 
    150          widget_control, id, get_value=widvalue 
    151          widget_control, id, set_value={droplist_select:(widvalue.droplist_number-1)*(event.out EQ -1)} 
    152       ENDIF ELSE nothing = execute('move, event,'''+possiblecase[whichcase+1]+'''')  
    153    ENDIF ELSE widget_control, id, set_value={droplist_select:wvalue.droplist_select+event.out} 
    154    nothing = execute('set_droplist, event,'''+possiblecase[whichcase-1]+'''') 
    155    return 
    156 end 
    157233;---------------------------------------------------------------------- 
    158234FUNCTION cw_calendar_event, event 
    159 ;help,  /struct, event 
    160    widget_control, event.id, get_uvalue=uval 
    161    possiblecase = ['day', 'month', 'year', 'century', 'impossiblecase'] 
    162    whichcase = (where(possiblecase EQ uval.name))[0] 
    163    if event.out NE 0 then BEGIN ; we use the +/- button and we want to go out of the droplist: 
    164 ; to index -1 (event.out=-1) or to index droplist_number (event.out=1) 
    165 ; we try to move the droplist just right named possiblecase[whichcase+1] 
    166       if widget_info(event.handler,find_by_uname = possiblecase[whichcase+1]) EQ 0 then BEGIN 
     235; 
     236@cm_4cal 
     237  compile_opt strictarr, strictarrsubs  
     238; 
     239  winfo_id = widget_info(event.top, find_by_uname = 'infocal') 
     240  widget_control, winfo_id, get_uvalue = infowid 
     241  key_caltype = infowid.caltype 
     242; 
     243  widget_control, event.id, get_uvalue = uval 
     244; high frequency calendar 
     245  IF uval.name EQ 'step' THEN BEGIN  
     246    infowid.date = jul2date(event.index + infowid.fakecal) 
     247  ENDIF ELSE BEGIN 
     248; 
     249    possiblecase = ['day', 'month', 'year', 'impossiblecase'] 
     250    whichcase = (where(possiblecase EQ uval.name))[0] 
     251    if event.out NE 0 then BEGIN ; we use the +/- button and we want to go out of the combobox: 
     252; to index = -1 (event.out=-1) or to index = combobox_number (event.out=1) 
     253; we try to move the combobox just right, with name: possiblecase[whichcase+1] 
     254      if widget_info(event.handler, find_by_uname = possiblecase[whichcase+1]) EQ 0 then BEGIN 
    167255; this widget do not exist we set cyclicly the current widget to the 
    168 ; value 0 if event.out=1 or droplist_number-1 if event.out=-1 
    169          widget_control, event.id, get_value=widvalue 
    170          widget_control, event.id, set_value={droplist_select:(widvalue.droplist_number-1)*(event.out EQ -1)} 
     256; value 0 if event.out=1 or combobox_number-1 if event.out=-1 
     257        widget_control, event.id, get_value = widvalue 
     258        selected = (widvalue.combobox_number-1)*(event.out EQ -1) 
     259        widget_control, event.id, set_value = {combobox_select:selected} 
    171260      ENDIF ELSE move, event, possiblecase[whichcase+1] 
    172    ENDIF 
    173    if uval.name NE 'day' then begin 
     261    ENDIF 
     262; if we changed month(year), we need to update the day (and month) list 
     263    if uval.name NE 'day' then begin 
    174264      event.out = 0 
    175       for name = whichcase-1, 0, -1 do begin 
    176          if widget_info(event.handler,find_by_uname = possiblecase[name]) NE 0 then $ 
    177           set_droplist, event, possiblecase[name] 
     265      for name = whichcase-1, 0, -1 do BEGIN 
     266        if widget_info(event.handler, find_by_uname = possiblecase[name]) NE 0 then $ 
     267           set_cal_combobox, event, possiblecase[name] 
    178268      endfor 
    179    endif 
    180    return, {CW_CALENDAR, ID:event.handler, TOP:event.top, HANDLER:0L $ 
    181             , VALUE:cw_calendar_get_value(event.handler)} 
    182 end 
    183 ;---------------------------------------------------------------------- 
    184 FUNCTION cw_calendar, parent, calendar, date0, UVALUE = uvalue, UNAME = uname, ROW = row, COLUMN = column, _extra = ex 
    185 ; cheking for row and column keywords 
    186    column = keyword_set(column)*(1-keyword_set(row)) 
    187    row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column)  
    188 ; liste des mois, jours annee disponibles ds le calendrier 
    189    caldat, calendar,monthcal,daycal,yearcal 
    190    centurycal = yearcal/100 
    191 ; date de depart 
    192    if n_elements(date0) EQ 0 then date0 = calendar[0] 
    193    if (where(calendar EQ date0))[0] EQ -1 then date0 = calendar[0] 
    194    caldat, date0,month0,day0,year0 
    195    century0 = year0/100 
    196 ; test du type de calendrier 
    197    if n_elements(calendar) GT 1 then begin 
    198       if total(daycal eq 15) EQ n_elements(calendar) then monthly = 1 
    199    if total(monthcal EQ 6) EQ n_elements(calendar) AND n_elements(uniq(daycal, sort(daycal))) EQ 1 then BEGIN  & monthly = 1 & yearly = 1 & endif 
    200    if total(yearcal EQ 50) EQ n_elements(calendar) then BEGIN  & monthly = 1 & yearly = 1 & centuryly = 1 & ENDIF 
    201    endif 
     269    ENDIF 
     270; we update the date 
     271    infowid = get_cal_value(event.handler, winfo_id) 
     272  ENDELSE  
     273; 
     274  widget_control, winfo_id, set_uvalue = infowid 
     275  return, {CW_CALENDAR, ID:event.handler, TOP:event.top, HANDLER:0L $ 
     276           , VALUE:infowid.date, FAKECAL: infowid.fakecal} 
     277end 
     278;---------------------------------------------------------------------- 
     279;---------------------------------------------------------------------- 
     280FUNCTION cw_calendar, parent, calendar, jdate0, CALTYPE = CALTYPE, FAKECAL = fakecal, UVALUE = uvalue, UNAME = uname, _extra = ex 
     281; 
     282@cm_4cal 
     283; 
     284  compile_opt strictarr, strictarrsubs  
     285; 
     286  if keyword_set(caltype) then key_caltype = caltype 
     287; months days years found in the calendar 
     288  caldat, calendar, monthcal, daycal, yearcal, hourcal, mincal, scdcal 
     289; starting date 
     290  if n_elements(jdate0) EQ 0 then jdate0 = calendar[0] 
     291  if (where(calendar EQ jdate0))[0] EQ -1 then jdate0 = calendar[0] 
     292 
     293  caldat, jdate0, month0, day0, year0 
     294; test the type of calendar 
     295  if n_elements(calendar) GT 1 then BEGIN 
     296; each day have the same value 
     297    if n_elements(uniq(daycal, sort(daycal))) EQ 1 then monthly = 1 
     298; each month and each day have the same value 
     299    if keyword_set(monthly) AND n_elements(uniq(monthcal, sort(monthcal))) EQ 1 then yearly = 1 
     300  endif 
    202301;--------------------------------------------------------------------------------------- 
    203    if NOT keyword_set(uvalue) then uvalue = '' 
    204    if NOT keyword_set(uname) then uname = '' 
    205    base = widget_base(parent, ROW = row, COLUMN = column $ 
     302  if NOT keyword_set(uvalue) then uvalue = {dummy:''} 
     303  if NOT keyword_set(uname) then uname = '' 
     304  base0 = widget_base(parent, /ROW $ 
    206305                      , EVENT_FUNC = 'cw_calendar_event' $ 
    207                       , FUNC_GET_VALUE='cw_calendar_get_value' $ 
    208                       , PRO_SET_VALUE='cw_calendar_set_value' $ 
    209                       , UVALUE = uvalue, UNAME = uname, _extra = ex)    
    210 ;-------------day---------------- 
    211    if NOT keyword_set(monthly)  then begin 
    212       dayindex = where(monthcal EQ month0 AND yearcal EQ year0 AND centurycal EQ century0) 
     306                      , FUNC_GET_VALUE = 'cw_calendar_get_value' $ 
     307                      , PRO_SET_VALUE = 'cw_calendar_set_value' $ 
     308                      , UVALUE = uvalue, UNAME = uname, space = 0, _extra = ex) 
     309; 
     310 
     311  if n_elements(fakecal) eq 0 then fakecal = 0 
     312  base = widget_base(base0, space = 0, uname = 'infocal' $ 
     313                     , uvalue = {calendar:calendar, date:jul2date(jdate0), fakecal:fakecal, caltype: key_caltype}) 
     314; 
     315  IF keyword_set(fakecal) THEN BEGIN  
     316    cmbbid = cw_combobox_pm(base, UVALUE = {name:'step'}, UNAME = 'step' $ 
     317                            , value = strtrim(indgen(n_elements(calendar)), 1)) 
     318    widget_control, cmbbid, set_value = {combobox_select:(where(calendar EQ jdate0))[0]} 
     319  ENDIF ELSE BEGIN  
     320; 
     321    vallen = widget_info(base, string_size = 'm') 
     322;-------------day----------------- 
     323    if NOT keyword_set(monthly)  then begin 
     324      dayindex = where(monthcal EQ month0 AND yearcal EQ year0) 
    213325      currentday = daycal[dayindex] 
    214       currentday = string(currentday) 
    215       for i = 0, n_elements(currentday)-1 do currentday[i] = strtrim(currentday[i], 1) 
    216       rien = cw_droplist_pm(base,UVALUE = {name:'day', calendar:calendar, index:dayindex}, UNAME = 'day', value = currentday) 
    217       widget_control, rien, set_value = {droplist_select:(where(long(currentday) EQ day0))[0]} 
    218    endif 
    219 ;-------------month---------------- 
    220    if NOT keyword_set(yearly)  then BEGIN 
    221 ; les mois du siecle en cours et de l''anne en cours 
    222       monthindex = where(yearcal EQ year0 AND centurycal EQ century0) 
     326      currentday = strtrim(currentday, 1) 
     327      cmbbid = cw_combobox_pm(base, UVALUE = {name:'day'}, UNAME = 'day', value = currentday) 
     328      widget_control, cmbbid, set_value = {combobox_select:(where(long(currentday) EQ day0))[0]} 
     329    endif 
     330;-------------month--------------- 
     331    if NOT keyword_set(yearly)  then BEGIN 
     332      monthindex = where(yearcal EQ year0) 
    223333      currentmonth = long(monthcal[monthindex]) 
    224 ; on supprime les elements repetes 
     334; we suppress the repeted months 
    225335      monthindexbis = uniq(currentmonth, sort(currentmonth)) 
    226336      monthindex = monthindex[monthindexbis] 
    227337      currentmonth = currentmonth[monthindexbis] 
    228 ; on cree une droplist avec comme valeur tous les mois possibles de 
    229 ; l''annee courrante (year0) 
    230 ;       rien = cw_droplist_pm(base,UVALUE = {name:'month', calendar:calendar, index:monthindex}, UNAME = 'month', value = string(format='(C(CMoA))',31*indgen(12))) 
    231       rien = cw_droplist_pm(base,UVALUE = {name:'month', calendar:calendar, index:monthindex}, UNAME = 'month', value = string(format='(C(CMoA))',31*(currentmonth-1))) 
    232 ; on possitionne le mois courrant sur le bon mois parmis les mois 
    233 ; possibles de l''annee courrante 
    234       widget_control, rien, set_value = {droplist_select:(where(long(currentmonth) EQ month0))[0]} 
    235    endif 
     338      xoff = (34 + 2*vallen[0])*(1-keyword_set(monthly)) 
     339      cmbbid = cw_combobox_pm(base, UVALUE = {name:'month'}, UNAME = 'month', value = string(format = '(C(CMoA))', 31*(currentmonth-1)), xoffset = xoff) 
     340      widget_control, cmbbid, set_value = {combobox_select:(where(long(currentmonth) EQ month0))[0]} 
     341    endif 
    236342;-------------year---------------- 
    237    if NOT keyword_set(centuryly)  then begin 
    238       if n_elements(centurycal[uniq(centurycal, sort(centurycal))]) NE 1 then BEGIN  
    239          yearcal = yearcal-centurycal*100 
    240          year0   = year0-centurycal*100 
    241       endif 
    242       yearindex = where(centurycal EQ century0) 
    243       currentyear = yearcal[yearindex] 
    244       yearindexbis = uniq(currentyear, sort(long(currentyear))) 
    245       yearindex = yearindex[yearindexbis] 
    246       currentyear = currentyear[yearindexbis] 
    247       currentyear = string(currentyear) 
    248       for i = 0, n_elements(currentyear)-1 do currentyear[i] = strtrim(currentyear[i], 1) 
    249       rien = cw_droplist_pm(base,UVALUE = {name:'year', calendar:calendar, index:yearindex}, UNAME = 'year', value = currentyear) 
    250       widget_control, rien, set_value = {droplist_select:(where(long(currentyear) EQ year0))[0]} 
    251    endif 
    252 ;-------------century---------------- 
    253    centuryindex = uniq(centurycal, sort(long(centurycal))) 
    254    currentcentury = centurycal[centuryindex] 
    255    currentcentury = string(currentcentury) 
    256    for i = 0, n_elements(currentcentury)-1 do currentcentury[i] = strtrim(currentcentury[i], 1) 
    257    if n_elements(uniq(centurycal, sort(centurycal))) NE 1 then BEGIN 
    258       rien = cw_droplist_pm(base,UVALUE = {name:'century', calendar:calendar, index:centuryindex}, UNAME = 'century', value = currentcentury) 
    259       widget_control, rien, set_value = {droplist_select:(where(long(currentcentury) EQ century0))[0]} 
    260    endif 
     343    yearindex = uniq(yearcal, sort(yearcal)) 
     344    currentyear = strtrim(yearcal[yearindex], 1) 
     345    xoff = (34 + 2*vallen[0])*(1-keyword_set(monthly)) + (33 + 3*vallen[0])*(1-keyword_set(yearly)) 
     346    cmbbid = cw_combobox_pm(base, UVALUE = {name:'year'}, UNAME = 'year', value = currentyear, xoffset = xoff) 
     347    widget_control, cmbbid, set_value = {combobox_select:(where(long(currentyear) EQ year0))[0]} 
    261348;----------------------------- 
    262 ; 
    263 ; 
    264    return, base 
    265 end 
     349  ENDELSE 
     350; 
     351  return, base 
     352end 
Note: See TracChangeset for help on using the changeset viewer.