GSDEMO.BAS

D:\GSDEMO.BAS
File saved: 3/6/2003 9:21:50 PM
Generated: 3/6/2003 9:23:37 PM

Table of Contents
Declarations


' TML BASIC Demo Program Table of Contents ' ' This is an example "Desktop" application. The program has several ' menus, 2 windows, a dialog box and other interesting features. ' The program demonstrates the use of TML BASIC statements and functions ' specfically designed for creating event-driven programs. 'Specify the libraries needed by this program LIBRARY "QuickDraw" LIBRARY "DeskTools" LIBRARY "Window" LIBRARY "Menu" LIBRARY "StdFile" 'Array declarations DIM WindowMenuStr!(200) ' The Winodws menu definition string DIM myWindTitle1!(10) ' Stores title for window 1 DIM myWindTitle2!(10) ' Stores title for window 2 DIM aReplyRecord!(149) ' Reply record for SFGetFile 'Main Program PROC StartUpTools(640,0) PROC SetUpMenus ' Menu item handling subroutines MENUDEF 5,DoClose MENUDEF 6,DoAbout MENUDEF 8,DoOpen MENUDEF 14,DoQuit MENUDEF 15,DoWindow1 MENUDEF 16,DoWindow2 MENUDEF 17,DoRects MENUDEF 18,DoOvals MENUDEF 19,DoRRects ' Event handling subroutines EVENTDEF 22,DoInGoAway ' Handle mouse down in window close box ' Window update drawing subroutines EVENTDEF 32,DrawWindow1 ' Drawing subroutine for window 1 myWindDrawing1@ = EXEVENT@(32) EVENTDEF 33,DrawWindow2 ' Drawing subroutine for window 2 myWindDrawing2@ = EXEVENT@(33) PROC SetUpWindows PROC MainEventLoop PROC ShutDownTools END DEF PROC SetUpMenus ' This procedure creates the 4 menus used in the GSDemo program. LOCAL MenuStr$ MenuStr$ = ">> Windows \N4\0" MenuStr$ = MenuStr$ + "==Window #1\N265\0" MenuStr$ = MenuStr$ + "==Window #2\N266\0" MenuStr$ = MenuStr$ + "==-\N377D\0" MenuStr$ = MenuStr$ + "==Rects\N267\0" MenuStr$ = MenuStr$ + "==Ovals\N268\0" MenuStr$ = MenuStr$ + "==Round Rects\N269\0." SET(WindowMenuStr!(0)) = ^MenuStr$ _InsertMenu(EXFN_NewMenu(VARPTR(WindowMenuStr!(1))),0) PROC StdEditMenu PROC StdFileMenu(1) PROC StdAppleMenu PROC DrawMenus ' Set the CurrentObj% to Rectangles CurrentObj% = 267 _CheckMItem(1,CurrentObj%) END PROC DEF PROC SetUpWindows ' This procedure creates the 2 windows used in the GSDemo program. LOCAL tmp$ tmp$ = "Window 1" SET(myWindTitle1!(0)) = ^tmp$ aWind1@ = FN StdWindow@(20,30,400,110,VARPTR(myWindTitle1!(0)),myWindDrawing1@) tmp$ = "Window 2" SET(myWindTitle2!(0)) = ^tmp$ aWind2@ = FN StdWindow@(40,50,420,130,VARPTR(myWindTitle2!(0)),myWindDrawing2@) END PROC DEF PROC MainEventLoop Quit% = 0 TASKPOLL INIT 8191 DO TASKPOLL -1 UNTIL Quit% END PROC DEF PROC SetWind1Object(MenuItemNum%) ' This procedure is used to change what objects are drawn in the ' contents of Window 1. In addition, it puts a check mark next to ' the current object in the Windows menu. The objects in Window 1 ' are forced to be redrawn by "invalidating" the content of the ' window, thus forcing an Update event which automatically calls ' DrawWindow1. _CheckMItem(0,CurrentObj%) CurrentObj% = MenuItemNum% _CheckMItem(1,CurrentObj%) _SetPort(aWind1@) _GetPortRect(VARPTR(aRect%(0))) _EraseRect(VARPTR(aRect%(0))) _InvalRect(VARPTR(aRect%(0))) END PROC DoAbout: PROC StdDialog("GSDemo.","A desktop application.",1) RETURN 0 DoOpen: ' This program does not support opening files, however selecting ' the Open menu item will display the Standard Get File Dialog. ' This particular call will display ALL files. To display only ' text files, applications, etc. use a TypeList with the ' appropriate file types specified. _SFGetFile(100,50,"Open what file:",0,0,VARPTR(aReplyRecord!(0))) RETURN 0 DoClose: ' Hide (make invisible) the top window when Close is chosen ' from the File menu. In this application, a Desk Accessory ' window is closed automatically by TASKPOLL and not here. theWindow@ = EXFN_FrontWindow IF theWindow@ <> 0 THEN _HideWindow(theWindow@) RETURN 0 DoQuit: ' Set the Quit% flag to 1 so that the MainEventLoop procedure will ' terminate. Quit% = 1 RETURN 0 DoWindow1: ' This routine makes sure that Window 1 is visible and then brings ' it to the front of the other windows. _SelectWindow(aWind1@) _ShowWindow(aWind1@) RETURN 0 DoWindow2: ' This routine makes sure that Window 2 is visible and then brings ' it to the front of the other windows. _SelectWindow(aWind2@) _ShowWindow(aWind2@) RETURN 0 DoRects: ' This routine makes the current Window 1 object be Rectangles ' The value 267 is passed to SetWindObject because the Rects ' menu item number is 267. PROC SetWind1Object(267) RETURN 0 DoOvals: ' This routine makes the current Window 1 object be Ovals ' The value 268 is passed to SetWindObject because the Ovals ' menu item number is 268. PROC SetWind1Object(268) RETURN 0 DoRRects: ' This routine makes the current Window 1 object be Round Corner Rects ' The value 269 is passed to SetWindObject because the Round Rects ' menu item number is 269. PROC SetWind1Object(269) RETURN 0 DoInGoAway: ' Hide (make invisible) the slected window when a mouse-down ' occurs in a window's close box. _HideWindow(TASKREC@(16)) RETURN 0 DrawWindow1: ' Draw the content of Window 1 _SetRect(VARPTR(aRect%(0)),10,10,225,35) _SetPenSize(2,1) FOR i% = 1 TO 10 IF CurrentObj% = 267 THEN _FrameRect(VARPTR(aRect%(0))) ELSEIF CurrentObj% = 268 THEN _FrameOval(VARPTR(aRect%(0))) ELSEIF CurrentObj% = 269 THEN _FrameRRect(VARPTR(aRect%(0)),20,30) END IF _OffsetRect(VARPTR(aRect%(0)),15,15) NEXT i% RETURN 0 DrawWindow2: ' Draw the content of Window 2 FOR i% = 1 to 15 _MoveTo(i%*11+20, i%*9+10) _DrawString("TML BASIC is Great!") NEXT i% RETURN 0