# program 11.2 from Dan's book, p368

# I'm cheating here. I know how to specify multiple fonts in a fontlist
# <fontname1>=charset1, <fontname2>=charset2
# and I know how to create XmStrings using C code to use these charsets,
# but I don't know how to do it in resource files. So I use 2 fontlists

set fontlist1 "-*-courier-bold-r-*--12-*"
set fontlist2 "-*-courier-medium-r-*--12-*"

set months "January, February, March, April, May, June, \
July, August, September, October, November, December"

# find the current month/year
set this_month [exec date "+%m"]
# this_month is a 2-digit number possibly starting with 0 
# this signals an octal number, so lose any starting 0
if { [regexp {^0} $this_month] } {
  regsub {^0} $this_month "" this_month
}
set year  [exec date "+%y"]
set this_year "19$year"

proc set_month {label month} {
    global this_year

    set text [exec cal $month $this_year]
    $label setValues -labelString $text
}

# now the objects:

xtAppInitialize
 . setValues -width 100 -height 100

topLevelShell .main managed -geometry "=400x200+0+0"

xmRowColumn .main.rowcol managed -orientation horizontal
xmFrame .main.rowcol.frame managed
xmLabel .main.rowcol.frame.month managed \
	-alignment alignment_beginning \
	-fontList $fontlist1

xmScrolledList .main.rowcol.list managed \
	-itemCount 12 \
	-items $months \
	-fontList $fontlist2
.main.rowcol.list browseSelectionCallback \
	{set_month .main.rowcol.frame.month %item_position}
.main.rowcol.list selectPosition $this_month true

. realizeWidget
. mainLoop

