Part V
Modifying the Grid Function
We should also be able to provide a callback message to our calling program showing that some kind of event has taken place by the user. These callback messages could result from keyboard events or from mouse events in our grid function. For DsCalendar, it would be helpful for the calling program to know when a date selection has been made by sending a #Selection callback message to the calling program. Callback messages can also include other other data. We will send the currently selected date back to the calling program in the v0 argument in the callback function.
Responding to Messages from our calling program
In order for our grid function to be able to take action
on a #SetFont message, we need to set up a SUB SetFont for this message. But
first, in SUB Initialize we must add the following line:
Sub[#SetFont] = SUBADDRESS(SetFont)
This will register our SetFont subroutine address along with the array of other messages for our grid.
Next we need a SUB SetFont that will send our #SetFont message to all of the kid grids and modify their fonts.
SUB SetFont
typeface$ = r1$
FOR k = 1 TO $UpperKid
XuiSendMessage (grid, #GetFont, @size, @weight, @italic, @angle,
k, @tf$)
XuiSendToKid (grid, #SetFont, size, weight, italic, angle, k, @typeface$)
NEXT k
END SUB
Note that I am allowing the calling program to only change the typeface name. All of the remaining font arguments will remain the same.
Adding a callback function
We would like to create a #Selection callback message to
be sent to our calling program when the user selects a new date. I decided to
locate this callback function in the SUB SetSelectedDate since this
SUB is called internally whenever a user selection is made. I chose v0 as the
argument to pass the Gregorian Day Number back to the calling function.
v0 = DateToGregorianDayNumber (year, month, day)
XuiCallback (grid, #Selection, v0, 0, 0, 0, 0, grid)
In order to test this callback, I added a CASE selection to the SUB Selection in CalenderCode ( ).
SUB Selection
SELECT CASE kid
CASE $DsCalendar : PRINT "Selected Date: "; v0
END SELECT
END SUB
Now, whenever a selection is made in DsCalendar ( ), we get a #Selection message and from that message, we can retrieve the selected date in v0.
Our finished program is shown in calendar4.x.
In the next installment
Coming up next, we will look at adding keyboard event handling for the arrow keys.
(c) 2000 David SZAFRANSKI