\  EXAMPLE.MF written 02/26/88 by Martin Murray
\	last modified 09/15/88

\ ******************************************************************************
\ *     THIS CODE IS IN NO WAY COPYRIGHT BY INOVATRONICS, INC.  IN FACT, YOU   *
\ *     CAN DO ANYTHING WITH IT THAT YOU WANT TO DO.  JUST REMEMBER,           *
\ *     INOVATRONICS, INC. WILL BEAR ABSOLUTELY NO RESPONSIBILITY FOR THE USE, *
\ *     MISUSE, INABILITY TO USE OR INABLITY TO UNDERSTAND ANY OR ALL PARTS OF *
\ *     THIS CODE.  ENJOY IT IN GOOD HEALTH.                                   *
\ ******************************************************************************
\ ******************************************************************************
\ *     THE PURPOSE OF THE CODE IS TO LET YOU SEE WHAT YOUR PowerWindows2      *
\ *     GENERATED SOURCE CODE WILL LOOK LIKE IN A PROGRAM.  IN MOST CASES, ALL *
\ *     YOU SHOULD HAVE TO DO IS INCLUDE THIS FILE.  IT WILL  AUTOMATICALLY    *
\ *     INCLUDE YOUR SOURCE FILE, PROVIDED IT IS IN THE DEFAULT DIRECTORY, AND *
\ *     IS NAMED "example.include".  JUST COMPILE IT, AND IT WILL RUN ITSELF.  *
\ *     IT DEFAULTS TO TERMINATING WHEN THE CLOSE GADGET IS HIT, BUT IF YOU    *
\ *     LOOK BELOW YOU'LL SEE HOW TO MAKE IT TERMINATE ON ANY EVENT AT ALL.    *
\ *     PLEASE NOTE: IT IS DESIGNED FOR ONLY 1 WINDOW, A SCREEN AND A PALETTE. *
\ *     REMOVE THE REFERENCES TO ANYTHING NOT IN YOUR GENERATED SOURCE. PLEASE *
\ *     TRY IT WITH EXAMPLE1.PW FIRST.                                         *
\ ******************************************************************************

anew example.marker

\ Un-comment these includes if using InovaTools1
\ include	pw2mf:itools1/ITools1inc.4th
\ include	pw2mf:itools1/ITools1calls.4th

\ This is true when no window is open.
variable NoWindow true NoWindow !

\ This word will close the window and screen and tell the event loop to
\    terminate.
: quit   drop ( HandleEvent sends the address of the event Object )
	CURRENTWINDOW @ dup ClearMenuStrip CloseWindow true NoWindow !
	CURRENTSCREEN @ CloseScreen	\ close the screen
;

\ Un-comment these next 2 lines if using InovaTools1
\ : HandleDragGadget +ggSpecialInfo @ CURRENTWINDOW @ swap DragGadget ;
\ : HandlePopUpGadget +ggSpecialInfo @ CURRENTWINDOW @ swap PopUpMenu drop ;

\ This word fetches the RastPort address of the current window
: CURRENTRPort  CURRENTWINDOW @ +wdRPort @ ;

\ Pull in the PW2MF generated code.
include	ram:example.include


\ This word opens the Screen, Window, Menu, etc. and waits for input.
: example

NewScreenStructure OpenScreen
CURRENTSCREEN @ +scViewPort 	\ point to the ViewPort
Palette PaletteColorCount 	\ and the Palette and the color count
LoadRGB4		\ load the Palette
CURRENTSCREEN @ NewWindowStructure1 +nwScreen ! \ point the window to the screen

\   NOTE: The CLOSEWINDOW IDCMP flag MUST be set and the WINDOWCLOSE gadget
\   should be in the window.

NewWindowStructure1 OpenWindow false NoWindow !   \ open the window
CURRENTWINDOW @ MenuList1 SetMenuStrip	\ set the Menu

\ now load the window text, borderlist and imagelist and knoblist
CURRENTRPort IntuiTextList1 0 0 PrintIText
CURRENTRPort BorderList1 0 0 DrawBorder
CURRENTRPort ImageList1 0 0 DrawImage

\ Un-comment this next line if using InovaTools1
\ CURRENTWINDOW @ KnobList1 DrawKnobs

\ This is the main event loop.
	begin
		GetEvent
		dup dup GADGETDOWN = swap GADGETUP = or
			if ThisEvent +eIAddress @ HandleEvent then
		dup MENUPICK =
			if MenuList1 ThisEvent +eCode w@ ItemAddress HandleEvent
			then
		fCLOSEWINDOW = if 0 ( dummy for quit ) quit then
	NoWindow @
	until

;

\ Un-comment this next line if using InovaTools1
\ openITools1		\ Open inovatools1.library

example			\ Now, run that window!
