REM Return the focused control ID
REM Obtain the instance of the BBjAPI object LET myAPI!=BBjAPI()
REM Open the SysGui device SYSGUI=UNT OPEN (SYSGUI) "X0"
REM Obtain the instance of the BBjSysGui object LET mySysGui!=myAPI!.getSysGui()
REM Create the main window and control objects GOSUB CreateCalendar
REM Display the initial data GOSUB DisplayMonth
REM Set the text for rest of the month starting at the current day myVector! = myAPI!.makeVector() FOR I = CurrentDay TO DaysInMonth myVector!.addItem(STR(I)) NEXT I Calendar!.setCellText(CurrRow,CurrCol,myVector!)
REM Display the main window MainWindow!.setVisible(mySysGui!.TRUE)
REM Register the CALLBACK routines CALLBACK(ON_CLOSE,DoAppClose,CalendarContext)
REM Focus control and get ID Calendar!.focus() print "focused control ID:", MainWindow!.getFocusedControlID()
REM Process Events PROCESS_EVENTS
REM Callback routine called when the user closes the application window DoAppClose: RELEASE RETURN
REM Subroutine called to display the days in the current selected month/year DisplayMonth: LET DayNum=0 LET FirstDayOfMonth=DayTable!.get(DATE(JUL(CurrentYear,CurrentMonth,1):"%Ds")) LET DaysInMonth=FNDaysInMonth(CurrentYear,CurrentMonth) MonthVector!.clear() IF CurrentDay>DaysInMonth+1 THEN CurrentDay=DaysInMonth+1 FI LET CurrentJul=JUL(CurrentYear,CurrentMonth,CurrentDay)
REM Week 0 FOR DayOfWeek=0 TO 6 IF FirstDayOfMonth>DayOfWeek THEN LET Item$=STR(0:DayMask$) ELSE LET Item$=STR(DayNum+1:DayMask$) LET DayNum=DayNum+1 FI MonthVector!.addItem(Item$) NEXT DayOfWeek
REM Week 1-3 FOR Week=1 TO 3 FOR DayOfWeek=0 TO 6 LET Item$=STR(DayNum+1:DayMask$) LET DayNum=DayNum+1 MonthVector!.addItem(Item$) NEXT DayOfWeek NEXT Week
REM Week 4-5 FOR week=4 TO 5 FOR DayOfWeek=0 TO 6 IF DayNum>DaysInMonth THEN LET Item$=STR(0:DayMask$) ELSE LET Item$=STR(DayNum+1:DayMask$) LET DayNum=DayNum+1 FI MonthVector!.addItem(Item$) NEXT DayOfWeek NEXT week
REM Set the current information Calendar!.setCellText(MonthVector!) LET CurrRow=INT((FirstDayOfMonth+CurrentDay-1)/7) LET CurrCol=MOD(FirstDayOfMonth+CurrentDay-1,7) Calendar!.setSelectedCell(CurrRow,CurrCol) LET CurrentMonthYear$=DATE(CurrentJul:"%Ml %Y") CurrDate!.setText(CurrentMonthYear$) Calendar!.setCellText(5,5," To") Calendar!.setCellText(5,6,"day ") RETURN
REM Function called to return the number of days in the passed year and month DEF FNDaysInMonth(fYear,fMonth) rem calculate the number of days in a month - zero based LET DaysInMonth=30 IF fMonth<>12 THEN LET DaysInMonth=NUM(DATE(JUL(fYear,fMonth+1,1)-1:"%D"))-1 FI RETURN DaysInMonth FNEND
REM Subroutine called to create the calendar CreateCalendar: REM Create the vector to hold month info LET MonthVector!=mySysGui!.makeVector()
REM Create a java hash table to hold day names LET DayTable!=new java.util.Hashtable()
REM Get standard date info from the STRING table DIM DateInfo$:"Mask:C(32*=0),SM[12]:C(3*=0),M[12]:C(32*=0),SD[7]:C(3*=0),D[7]:C(32*=0)" LET DateInfo$=STBL("!DATE")
REM Build the masks for the dates LET dateMask$=DateInfo.Mask$ LET M=POS("%M"=dateMask$),dateMask$=dateMask$(1,M+1)+"l"+dateMask$(M+3) LET M=POS("%Y"=dateMask$),dateMask$=dateMask$(1,M+1)+dateMask$(M+3) WHILE POS("/"=dateMask$) LET M=POS("/"=dateMask$),dateMask$(M,1)=" " WEND
REM Build the day table FOR X=0 TO 6 LET Item$=DateInfo.SD$[x+1] DayTable!.put(Item$,x) NEXT X
REM Get current date info LET CurrentDate$=DATE(CurrentJul:dateMask$) LET CurrentMonthYear$=DATE(CurrentJul:"%Ml %Y") LET CurrentDay=NUM(DATE(CurrentJul:"%Dz")) LET CurrentMonth=NUM(DATE(CurrentJul:"%Mz")) LET CurrentYear=NUM(DATE(CurrentJul:"%Y"))
REM Misc LET TITLE$="BBjGrid" LET DayMask$="##B" LET CurrentJul=0,CalX=400,CalY=400
REM Get the next available context LET CalendarContext=mySysGui!.getAvailableContext() mySysGui!.setContext(CalendarContext)
REM Create the main window LET MainWindow! = mySysGui!.addWindow(100,100,286,260,TITLE$,$00010013$)
REM Add the calendar (grid) to the main window LET Calendar! = MainWindow!.addGrid(100,3,26,278,221)
REM Set the attributes of the grid Calendar!.setGridEditable(1) blueColor! = mySysGui!.makeColor(mySysGui!.BLUE) Calendar!.setColumnHeaderForeColor(blueColor!) Calendar!.setNumRows(6) Calendar!.setRowHeight(20) Calendar!.setNumColumns(7) Calendar!.setMaxColumns(255) Calendar!.setHasColumnHeader(mySysGui!.TRUE) Calendar!.setVerticalLinesVisible(mySysGui!.TRUE) Calendar!.setHorizontalLinesVisible(mySysGui!.TRUE) Calendar!.setClientEdge(mySysGui!.TRUE) Calendar!.setSelectionMode(Calendar!.GRID_SELECT_CELL)
REM Set the attributes for the grid's columns FOR COL = 0 TO 6 Calendar!.setColumnWidth(COL, 39) Calendar!.setColumnAlignment(Col,Calendar!.GRID_ALIGN_RIGHT) Calendar!.setColumnForeColor(COL, blueColor!) NEXT COL
REM Set the attributes for the grid's column headers myVector! = mySysGui!.makeVector() myVector!.addItem("S") myVector!.addItem("M") myVector!.addItem("T") myVector!.addItem("W") myVector!.addItem("T") myVector!.addItem("F") myVector!.addItem("S") Calendar!.setColumnHeaderText(myVector!) Calendar!.setColumnHeaderForeColor(blueColor!) REM Set the attributes for the current date (static text control) LET CurrDate! = MainWindow!.addStaticText(101,45,3,90,20,"") CurrDate!.setClientEdge(mySysGui!.TRUE) CurrDate!.setForeColor(blueColor!)
RETURN
|