Part VIII
Adding a Grid Resize Subroutine
Update SUB Initialize
First, we need to enable DsCalendar ( ) as well as the calling
function Calendar ( ) for resizing. When you create a GUI program using the
Toolkit, the resulting code that is generated creates a standard group of subroutines
which are initialized in the SUB Initialize. In order to enable the grid resizing
subroutine you need to enable or uncomment the following lines:
func[#GetSmallestSize]= 0
func[#Resize] = 0
sub[#GetSmallestSize] = SUBADDRESS(GetSmallestSize)
sub[#Resize] = SUBADDRESS
(Resize)
This needs to be done in BOTH DsCalendar ( ) and in Calendar ( ) where Calendar ( ) is the calling function which sends DsCalendar ( ) the #Resize message.
In SUB Initialize you will also need to comment out or disable the following lines which set the max and min Width and Height of our grid. At this stage we do not want to set any limits on the size of our grid.
' XuiSetGridTypeProperty (gridType, @"maxWidth",
designWidth)
' XuiSetGridTypeProperty (gridType, @"maxHeight",
designHeight)
' XuiSetGridTypeProperty (gridType, @"minWidth",
designWidth)
' XuiSetGridTypeProperty (gridType, @"minHeight",
designHeight)
Add Resizing code to Calendar ( ) SUB Resize
Now we want to add the code that allows us to resize the
window and which sends a #Resize message to our new grid function. Our SUB Resize
looks like this:
SUB Resize
XuiPositionGrid (grid, @v0, @v1, @v2, @v3)
'resize $DsCalendar grid
XuiSendMessage (grid, #Resize, 0, 0, v2, v3, $DsCalendar, 0)
XuiSendMessage (grid, #ResizeWindowToGrid, 0, 0, 0, 0, 0, 0)
END SUB

If you run the example program calendar8.x you will see that you can resize the window. Since we have not added any code to resize the kid grids in DsCalendar ( ), the calendar grid does not resize with the window.
Add Resizing code to DsCalendar ( ) SUB Resize
Now we need to add code which will resize every kid grid
in our grid function. Our calendar program isn't a very easy example since we
must calculate new positions and sizes for 58 grids. However, this is not as
difficult as it may appear. We are simply sending a #Resize message to each
kid grid and passing the newly calculated x, y, width, and height arguments.
I also added border width calculations so that DsCalendar ( ) can be assigned
any size border. Our SUB Resize is shown below:
SUB Resize
'v2,v3 = gridWidth, gridHeight
v2Entry = v2
v3Entry = v3
GOSUB GetSmallestSize
v2 = MAX (v2, v2Entry)
v3 = MAX (v3, v3Entry)
'get border width
XuiGetBorder (grid, #GetBorder, 0, 0, 0, 0, 0, @bw)
'position parent grid
XuiPositionGrid (grid, @v0, @v1, @v2, @v3)
'calc actual gridWidth, gridHeight less border
gridWidth = v2 - bw - bw
gridHeight = v3 - bw - bw
'calc sizes of various sub kids
kidWidth = gridWidth/7
kidHeight = gridHeight/10.2
'resize all kids
XuiSendMessage (grid, #Resize, bw, bw, 2*kidWidth, 2.2*kidHeight,
$CurrentDay, 0)
XuiSendMessage (grid, #Resize, bw+2*kidWidth, bw, gridWidth-2*kidWidth,
1.2*kidHeight, $Weekday, 0)
XuiSendMessage (grid, #Resize, bw+2*kidWidth, bw+1.2*kidHeight,
kidHeight, kidHeight, $MonthLeftArrowPressB, 0)
XuiSendMessage (grid, #Resize, bw+gridWidth-kidHeight, bw+1.2*kidHeight,
kidHeight, kidHeight, $MonthRightArrowPressB, 0)
XuiSendMessage (grid, #Resize, bw+2*kidWidth+kidHeight, bw+1.2*kidHeight,
gridWidth-(2*kidWidth)-(2*kidHeight), kidHeight, $Month, 0)
XuiSendMessage (grid, #Resize, bw+2*kidWidth, bw+2.2*kidHeight,
kidHeight, kidHeight, $YearLeftArrowPressB, 0)
XuiSendMessage (grid, #Resize, bw+gridWidth-kidHeight, bw+2.2*kidHeight,
kidHeight, kidHeight, $YearRightArrowPressB, 0)
XuiSendMessage (grid, #Resize, bw+2*kidWidth+kidHeight, bw+2.2*kidHeight,
gridWidth-(2*kidWidth)-(2*kidHeight), kidHeight, $Year, 0)
XuiSendMessage (grid, #Resize, bw, bw+2.2*kidHeight, 2*kidWidth, kidHeight, $TodayPushButton, 0)
weekDayLabelHeight = gridHeight-9.2*kidHeight
y = bw+3.2*kidHeight
x = bw
FOR i = $Sun TO $Sat
IF i = $Sat THEN
width = gridWidth - 6*kidWidth
ELSE
width = kidWidth
END IF
XuiSendMessage (grid, #Resize, x, y, width, weekDayLabelHeight, i,
0)
x = x + kidWidth
NEXT i
y = bw+3.2*kidHeight+weekDayLabelHeight
FOR i = $Day1 TO $Day42 STEP 7
x = bw
FOR j = 0 TO 6
IF j = 6 THEN
width = gridWidth - 6*kidWidth
ELSE
width = kidWidth
END IF
k = i + j
XuiSendMessage (grid, #Resize, x, y, width, kidHeight, k, 0)
x = x + kidWidth
NEXT j
y = y + kidHeight
NEXT i
XuiSendMessage (grid, #RedrawGrid, 0, 0, 0, 0, 0, 0)
END SUB
SUB GetSmallestSize
Our SUB Resize calls SUB GetSmallestSize. GetSmallestSize
can either calculate the smallest width and height which our grid function can
be "shrunk" or it can get the max/min size grid properties using XuiGetMaxMinSize
( ). We can initialize our grid minWidth and minHeight properties in SUB Initialize.
SUB GetSmallestSize
XuiSendMessage (grid, #GetMaxMinSize, @maxW, @maxH, @minW, @minH,
0, 0)
v2 = minW
v3 = minH
END SUB
In SUB Initialize, I set the minWidth, and MinHeight grid properties respectively to 168 and 153. Our grid cannot be resized below these values.
XuiSetGridTypeProperty (gridType, @"minWidth",
168)
XuiSetGridTypeProperty (gridType, @"minHeight", 153)
The code for our program up to this point can be found in Calendar9.x.
Part IX
(c) 2000 David SZAFRANSKI