Part III
Create a New Grid Function
Part IV
Merge Calendar( ) and CalendarCode ( ) into DsCalendar ( )
Copy Calendar ( ) into DsCalendar ( )
1. Copy ALL of Calendar ( ) function to DsCalendar ( ). Now we have to do a
bit of tidying to get this function working.
2. In DsCalendar ( ), Find/Replace all Local "Calendar" and Replace with "DsCalendar"
3. Copy the argument list from FUNCTION Calender ( ) to FUNCTION DsCalendar
( ). The argument lists for all grid functions are identical. You should end
up with the following :
FUNCTION DsCalendar (grid, message, v0, v1, v2, v3, r0, (r1, r1$,
r1[], r1$[]))
4. In the PROLOG, copy the argument list from Calendar ( ) to DsCalender
( ).
DECLARE FUNCTION DsCalendar (grid, message, v0, v1, v2, v3, r0, ANY)
Cut/Paste ALMOST all of CalendarCode ( ) into DsCalendar ( )
This is where things start to get more detailed. Basically
we need to copy just about everything we added to your CalendarCode ( ) function
into your new grid function. If you are feeling brave, then cut/paste the code
since we won't be needing it anymore in our CalendarCode ( ) function. Otherwise,
just copy it and you will have to delete it a bit later.
In our example we want to copy everything except the standard header template that was created by the Toolkit. Thus, in this example, I cut/pasted everything below the RETURN which is found beneath the END SELECT to DsCalendar ( ).
SELECT CASE message
CASE #CloseWindow : QUIT(0)
CASE #Selection : GOSUB Selection
' CASE #TextEvent : GOSUB TextEvent
END SELECT
RETURN
...copy remaining code to DsCalendar ( )
Modify DsCalendar ( )
Now we need to clean up DsCalendar ( ) so it functions properly.
1. Delete the previously existing SUB Selection. If you don't do this, you will have two SUBs with the same name. Don't delete the one you copied from CalendarCode ( ).
2. At the end of SUB Create, Add the following line to recover our
SUB Initialize:
IFZ initialize THEN GOSUB InitGrid
3. Rename SUB Initialize to SUB InitGrid. Since we already have a SUB Initialize, we need to rename the one that we used in CalendarCode ( ).
4. Copy any variable declarations from CalendarCode ( ) to the top of DsCalendar
( )
STATIC initialize
STATIC month$[], weekday$[], md[]
STATIC year, month, day, weekday, curDayGrid, lastDayGrid
5. ** In SUB Selection, replace kid with r0. If you use the variable kid in any part of your ProgramCode ( ) function, then you need to replace it with r0 in your new grid function.
6. In SUB Initialize you will need to make a few corrections:
-Set variables designX and designY to 0.
designX = 0
designY = 0
-Disable or Comment this line:
' func[#Callback] = &XuiCallback ()
-Enable or UnComment this line:
sub[#Callback] = SUBADDRESS (Callback)
Modify Calendar() function
At this point we need to modify Calendar ( ) to allow it
to create our new grid DsCalendar.
1. Delete all the grid/kid constants except for $Calendar and $UpperKid.
Add one constant for DsCalendar. Modify so that it looks like this:
$Calendar = 0
$DsCalendar = 1
$UpperKid = 1
2. In SUB Create, delete all of the grids except for the first one, XuiCreateGrid. SUB Create now looks like this:
SUB Create
IF (v0 <= 0) THEN v0 = 0
IF (v1 <= 0) THEN v1 = 0
IF (v2 <= 0) THEN v2 = designWidth
IF (v3 <= 0) THEN v3 = designHeight
XuiCreateGrid (@grid, Calendar, @v0, @v1, @v2, @v3, r0, r1,
&Calendar())
XuiSendMessage ( grid, #SetGridName, 0, 0, 0, 0, 0, @"Calendar")
GOSUB Resize
END SUB
3. Create the new DsCalendar grid by adding these lines to SUB Create beneath XuiSendMessage:
DsCalendar (@g, #Create, 0, 0, 224, 204, r0, grid)
XuiSendMessage ( g, #SetCallback, grid, &Calendar(), -1, -1, $DsCalendar,
grid)
XuiSendMessage ( g, #SetGridName, 0, 0, 0, 0, 0, @"DsCalendar")
4. In SUB Initialize, delete or comment out :
' XuiSetGridTypeProperty (gridType, @"focusKid",$MonthLeftArrowPressB)
Modify CalendarCode ( ) function
If you didn't cut/paste all of that code from CalendarCode
( ) earlier, then you have to do it now. You can replace the SUB Selection with
something very simple as shown below. And as in Calendar ( ), you should modify
the grid/kid constants. At this point you should have a bare minimum CalendarCode
( ) function.
FUNCTION CalendarCode (grid, message, v0, v1, v2, v3, kid, r1)
'
$Calendar = 0
$DsCalendar = 1
$UpperKid = 1
'
' XuiReportMessage (grid, message, v0, v1, v2, v3, kid, r1)
IF (message = #Callback) THEN message = r1
'
SELECT CASE message
CASE #CloseWindow : QUIT(0)
CASE #Selection : GOSUB Selection
END SELECT
RETURN
'
' ***** Selection *****
'
SUB Selection
SELECT CASE kid
END SELECT
END SUB
END FUNCTION
You can look at the resulting code by examining calendar3.x.
You're Finished (almost)
However, it still needs some more work. For one thing, you may have some big problems if you try to run more than one copy of this calendar in one program. This will be discussed in a later installment.
The following parts of this tutorial will also discuss
how to make some important modifications. One of the things we want to do is
provide a method for the calling program to change the calendar font typeface.
It would also be useful to have a #Selection callback message which returns
the currently selected date.
(c) 2000 David SZAFRANSKI