* MakeOptionGroupHorizontal() * function to take an option group and arrange the buttons so that they are horizontal instead * of the default vertical spacing; needed so can manipulate a class programmatically * Written by: Albert Gostick * Last Updated: Sep 27, 2005 * Parameters: * toOptionGroup: object reference to the option group to be changed * tnSpaceBetween: space between buttons; defaults to 10 pixels if not passed * tlButtonsSameSize: option to resize all the buttons to the same size (which will be the size of the * largest button) * tlDontResizeContainer: option to NOT resizse the container when done * Returns: nothing LPARAMETERS toOptionGroup, tnSpaceBetween, tlButtonsSameSize, tlDontResizeContainer LOCAL lnTopEdge, lnMaxSize, lnButtonNum, lnRightEdge, lnButtonBottom, lnBottomEdge WITH toOptionGroup * check parameters: if nothing passed in for tnSpaceBetween, default to 10 pixels; zero if valid IF VARTYPE(tnSpaceBetween) # "N" STORE 10 TO tnSpaceBetween ENDIF * grab the top edge of the first option in the group to use our our top edge for all STORE .Option1.Top TO lnTopEdge * if they are supposed to be all the same size, loop through the options figuring out the max size IF tlButtonsSameSize * init the var to track max size STORE 0 TO lnMaxSize FOR lnButtonNum = 1 TO .ButtonCount IF .Buttons[lnButtonNum].Width > lnMaxSize STORE .Buttons[lnButtonNum].Width TO lnMaxSize ENDIF ENDFOR ENDIF && for tlButtonsSameSize * loop through buttons 2 to x setting their top and left margins FOR lnButtonNum = 2 TO .ButtonCount STORE lnTopEdge TO .Buttons[lnButtonNum].Top * if buttons are supposed to be the same size, resize first IF tlButtonsSameSize STORE lnMaxSize TO .Buttons[lnButtonNum].Width ENDIF * set the left margin: this will be the distance from the previous button's left edge plus * that button's width plus the space between STORE .Buttons[lnButtonNum-1].Left + .Buttons[lnButtonNum-1].Width + tnSpaceBetween ; TO .Buttons[lnButtonNum].Left ENDFOR * Container sizing: if container sizing is not suppressed, resize the container as it most likely is * not wide enough now that the buttons are horizontal; as well, shrink the overall height IF NOT tlDontResizeContainer * check that right edge of last button used is not wider than container; if so, resize container STORE .Buttons[.ButtonCount].Left + .Buttons[.ButtonCount].Width TO lnRightEdge IF lnRightEdge # .Width STORE lnRightEdge TO .Width ENDIF * loop through buttons again getting the bottommost edge of them; note that this is a bit of * overkill as they are usually all the same height but just in case, will check * init a var to track STORE 0 TO lnBottomEdge FOR lnButtonNum = 1 TO .ButtonCount STORE .Buttons[lnButtonNum].Top + .Buttons[lnButtonNum].Height TO lnButtonBottom * if greater than current max, reset it IF lnButtonBottom > lnBottomEdge STORE lnButtonBottom TO lnBottomEdge ENDIF ENDFOR * resize the container if bottom edge of container is greater than largest button IF lnBottomEdge # .Height STORE lnBottomEdge TO .Height ENDIF ENDIF && for NOT tlDontResizeContainer ENDWITH && for toOptionGroup RETURN