home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Global Amiga Experience
/
globalamigaexperience.iso
/
compressed
/
development
/
heliosdemodisk3.dms
/
heliosdemodisk3.adf
/
Source
/
IntuitionMenus.src
< prev
next >
Wrap
Text File
|
1978-03-31
|
31KB
|
745 lines
( ------------------------------------------------
*** HeliOS Menu Intuition Menu Example ***
------------------------------------------------
This code is included mainly as an exercise in how to initialise data
structures at run-time, which needs to be done in HeliOS if you allocate
32-bit addressed data structures within the 16-bit dictionary space.
Usually it is better to allocate all Amiga data structures dynamically
at run time rather than initialise them in the 16-bit dictionary space.
Nevertheless, this code does at least give you an alternative approach
which is OK for very simple applications.
This HeliOS source code module contains:
1. A fully commented predefined Intuition menu data structure.
2. HeliOS run-time menu-initialisation code.
3. A fully functional menu command interpreter which can,
if required, easily be integrated with the Helios gadget
command interpreter.
4. A simple Demo program which opens a Workbench window and
carries out menu commands.
All the material can be readily modified to your own specific
requirements and provides a simple means for dealing with all
Intuition Menu programming tasks.
To produce your own application all you need to do is alter the
data structures to suit your particular requirements, then enter
your own routines into the command vector table in place of the
Demo commands.
The run-time initialisation routines have been written in such
a way as to be very easy to understand and modify, but this
is not ideal in terms of speed and efficiency. Once you are
confident about what is happening you can easily speed up this
initialisation code if you wish.
<<< *** IMPORTANT *** >>>
WHY RUN-TIME INITIALISATION ?
WHY NOT INITIALISE THE STRUCTURE AS IT IS DECLARED?
You MUST dynamically set up all data structure links and pointers
at run-time if you wish to be able to save the data structure as
part of a precompiled HeliOS code module.
This has to be done because your data structures will obvously not
be reloaded into the same absolute position in memory as they occupied
when you first created them. This means that all the absolute pointers
in the structure must be re-initialised each time the module is loaded. )
\ ----------------------------------------------------------
\ "FORGET" all but core dictionary.
\ ----------------------------------------------------------
FORGET **CORE**
\ ----------------------------------------------------------
\ First we define all the Text Strings we require.
\ (In this case we are using 3 Menus each with 4 items.)
\ Edit the text strings below to your own requirements.
\ ----------------------------------------------------------
CREATEL MENU1$ <$ Menu1text $
CREATEL MENU2$ <$ Menu2text $
CREATEL MENU3$ <$ Menu3text $
CREATEL MENU11$ <$ Menu11text$
CREATEL MENU12$ <$ Menu12text$
CREATEL MENU13$ <$ Menu13text$
CREATEL MENU14$ <$ Menu14text$
CREATEL MENU21$ <$ Menu21text$
CREATEL MENU22$ <$ Menu22text$
CREATEL MENU23$ <$ Menu23text$
CREATEL MENU24$ <$ Menu24text$
CREATEL MENU31$ <$ Menu31text$
CREATEL MENU32$ <$ Menu32text$
CREATEL MENU33$ <$ Menu33text$
CREATEL MENU34$ <$ Menu34text$
\ ----------------------------------------------------------
\ Now set up Menu data structures, unlinked at this stage.
\ Note that we only need remember the address of the first.
\ ----------------------------------------------------------
D0 DVARIABLEL MENU1 \ Next MENU
0 , \ LEDGE
0 , \ TEDGE
80 , \ WIDTH
12 , \ HEIGHT
1 , \ FLAGS
D0 D, \ NAME 14-offset
D0 D, \ ITEM1 18-offset
0 , \ SYS
0 , \ SYS
0 , \ SYS
0 , \ SYS 30 Bytes
\ ----------------------------------------------------------
D0 D, \ Next MENU
80 , \ LEDGE
0 , \ TEDGE
80 , \ WIDTH
12 , \ HEIGHT
1 , \ FLAGS
D0 D, \ NAME
D0 D, \ ITEM1
0 , \ SYS
0 , \ SYS
0 , \ SYS
0 , \ SYS
\ ----------------------------------------------------------
D0 D, \ Next MENU
160 , \ LEDGE
0 , \ TEDGE
80 , \ WIDTH
12 , \ HEIGHT
1 , \ FLAGS
D0 D, \ NAME
D0 D, \ ITEM1
0 , \ SYS
0 , \ SYS
0 , \ SYS
0 , \ SYS
\ ----------------------------------------------------------
\ Etc etc ...... Add as many as you require..............
\ ----------------------------------------------------------
\ Then declare the total number of menus as MENU#........
\ In this case there are 3 Menus, so ........
3 CONSTANT MENU#
\ ----------------------------------------------------------
\ Now create the Menu Item data structures
\ Again we need only to remember the address of the first items
\ ----------------------------------------------------------
\ This is the 1st Menu Item list..................
\ ----------------------------------------------------------
D0 DVARIABLEL MENU11 \ Next ITEM ITEM11
0 , \ LEDGE
0 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL 18-offset
D0 D, \ SELFILL
ASCII 1 C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT 34 Bytes
\ ----------------------------------------------------------
2 C, \ FPEN ITEM11 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT 20 Bytes
\ ----------------------------------------------------------
D0 D, \ Next ITEM ITEM12
0 , \ LEDGE
20 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII 2 C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM12 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
D0 D, \ Next ITEM ITEM13
0 , \ LEDGE
40 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII 3 C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM13 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
D0 D, \ Next ITEM ITEM14
0 , \ LEDGE
60 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII 4 C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM14 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
\ Etc etc ...... Add as many as you require..............
\ ----------------------------------------------------------
\ Then declare the total number of menu items as MENU1ITEM#..
\ In this case there are 4 Menu1 Items, so ........
4 CONSTANT MENU1ITEM#
\ ----------------------------------------------------------
\ Next the 2nd Menu Items..............
\ ----------------------------------------------------------
D0 DVARIABLEL MENU21 \ Next ITEM ITEM21
0 , \ LEDGE
0 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII 5 C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM21 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
D0 D, \ Next ITEM ITEM22
0 , \ LEDGE
20 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII 6 C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM22 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
D0 D, \ Next ITEM ITEM23
0 , \ LEDGE
40 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII 7 C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM23 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
D0 D, \ Next ITEM ITEM24
0 , \ LEDGE
60 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII 8 C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM24 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
\ Etc etc ...... Add as many as you require..............
\ ----------------------------------------------------------
\ Then declare the total number of menu items as MENU2ITEM#..
\ In this case there are 4 Menu2 Items, so ........
4 CONSTANT MENU2ITEM#
\ ----------------------------------------------------------
\ Now the 3rd Menu.........................
\ ----------------------------------------------------------
D0 DVARIABLEL MENU31 \ Next ITEM ITEM31
0 , \ LEDGE
0 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII A C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM31 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
D0 D, \ Next ITEM ITEM32
0 , \ LEDGE
20 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII B C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM32 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
D0 D, \ Next ITEM ITEM33
0 , \ LEDGE
40 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII C C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM33 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
D0 D, \ Next ITEM ITEM34
0 , \ LEDGE
60 , \ TEDGE
200 , \ WIDTH
20 , \ HEIGHT
HEX 56 DECIMAL , \ FLAGS
D0 D, \ MEXC
D0 D, \ FILL
D0 D, \ SELFILL
ASCII D C, \ CMD
0 C, \ KLUDGE
D0 D, \ SUBITEM
0 , \ SELNEXT
\ ----------------------------------------------------------
2 C, \ FPEN ITEM34 TEXT
0 C, \ BPEN
0 C, \ MODE
0 C, \ KLUDGE
3 , \ LEDGE
2 , \ TEDGE
D0 D, \ FONT
D0 D, \ TEXT
D0 D, \ NEXTTEXT
\ ----------------------------------------------------------
\ Etc etc ...... Add as many as you require..............
\ ----------------------------------------------------------
\ Then declare the total number of menu items as MENU3ITEM#..
\ In this case there are 4 Menu3 Items, so ........
4 CONSTANT MENU3ITEM#
\ ----------------------------------------------------------
\ Now create words to reference the various structures
\ ----------------------------------------------------------
: MENU \ Menunumber(w) - - - Structure Address(l)
1- 30 * \ Offset into list of structures
0 \ Make into 32-bit number
MENU1 D+ ; \ Add to start address
: MENUITEM \ ItemStructure(l), Itemnumber(w) - - - Structure Address(l)
1- 54 *
0
D+ ;
\ ----------------------------------------------------------
\ And now a word to initialise the menus.........
\ ----------------------------------------------------------
: INITMENUS
MENU3$ MENU2$ MENU1$
MENU# 0
DO
I 1+ MENU 14. D+ D!L \ Set name text
LOOP
MENU# 0 \ Set Menu Links
DO
I 1+ MENU# <
IF
I 2+ MENU
I 1+ MENU D!L
THEN
LOOP
MENU31 MENU21 MENU11
MENU# 0
DO
1 MENUITEM I 1+ MENU 18. D+ D!L \ Set 1st Item Pointer
LOOP
MENU14$ MENU13$ MENU12$ MENU11$ \ Set Menu 1
MENU11
MENU1ITEM# 0
DO
I 1+ MENU1ITEM# <
IF \ Set Item Links
DDUP I 2+ MENUITEM
DOVER I 1+ MENUITEM D!L
THEN
DDUP I 1+ MENUITEM 18. D+ \ Set IntuiText Pointers
DDUP 16. DUNDER+ D!L
DSWAP DOVER
I 1+ MENUITEM 46. D+ D!L \ Set Text Pointers
LOOP
DDROP
MENU24$ MENU23$ MENU22$ MENU21$ \ Set Menu 2
MENU21
MENU2ITEM# 0
DO
I 1+ MENU2ITEM# <
IF \ Set Item Links
DDUP I 2+ MENUITEM
DOVER I 1+ MENUITEM D!L
THEN
DDUP I 1+ MENUITEM 18. D+ \ Set IntuiText Pointers
DDUP 16. DUNDER+ D!L
DSWAP DOVER
I 1+ MENUITEM 46. D+ D!L \ Set Text Pointers
LOOP
DDROP
MENU34$ MENU33$ MENU32$ MENU31$ \ Set Menu 3
MENU31
MENU3ITEM# 0
DO
I 1+ MENU3ITEM# <
IF \ Set Item Links
DDUP I 2+ MENUITEM
DOVER I 1+ MENUITEM D!L
THEN
DDUP I 1+ MENUITEM 18. D+ \ Set IntuiText Pointers
DDUP 16. DUNDER+ D!L
DSWAP DOVER
I 1+ MENUITEM 46. D+ D!L \ Set Text Pointers
LOOP
DDROP
;
\ ----------------------------------------------------------
\ A set of dummy Menu commands
\ ----------------------------------------------------------
: M11 4 11 CURPUT ." MENU11ACTION" ;
: M12 4 11 CURPUT ." MENU12ACTION" ;
: M13 4 11 CURPUT ." MENU13ACTION" ;
: M14 4 11 CURPUT ." MENU14ACTION" ;
: M21 4 14 CURPUT ." MENU21ACTION" ;
: M22 4 14 CURPUT ." MENU22ACTION" ;
: M23 4 14 CURPUT ." MENU23ACTION" ;
: M24 4 14 CURPUT ." MENU24ACTION" ;
: M31 4 17 CURPUT ." MENU31ACTION" ;
: M32 4 17 CURPUT ." MENU32ACTION" ;
: M33 4 17 CURPUT ." MENU33ACTION" ;
: M34 4 17 CURPUT ." MENU34ACTION" ;
\ ----------------------------------------------------------
\ The Menu Command Interpreter Vector Table
\ ----------------------------------------------------------
\ See the HeliOS Dictionary and Amiga Intuition Reference Manual
\ for full definition and description of the Menu Number fields.
\ Very briefly, these are as follows :
\ Menunumber in Binary Format: 1111100000100000
\ Menu number bits : ^^^^^ = Menu 1
\ Menu Item number bits : ^^^^^^ = Menu Item 2
\ Menu Sub-Item number bits : ^^^^^ = Menu Sub-Item Null
\ In other words: ALL BITS SET IN FIELD = NULL FIELD
\ and NO BITS SET IN FIELD = 1st item
\ You can replace the commands M11.......M34 defined above and used
\ in the Menuvector table below with any routines of your own.
BIN 1111100000000000 VARIABLE MENUVECTORS \ Menu 1 Item 1
' M11 CFA ,
1111100000100000 , \ Menu 1 Item 2
' M12 CFA ,
1111100001000000 , \ Menu 1 Item 3
' M13 CFA ,
1111100001100000 , \ Menu 1 Item 4
' M14 CFA ,
1111100000000001 , \ Menu 2 Item 1
' M21 CFA ,
1111100000100001 , \ Menu 2 Item 2
' M22 CFA ,
1111100001000001 , \ Menu 2 Item 3
' M23 CFA ,
1111100001100001 , \ Menu 2 Item 4
' M24 CFA ,
1111100000000010 , \ Menu 3 Item 1
' M31 CFA ,
1111100000100010 , \ Menu 3 Item 2
' M32 CFA ,
1111100001000010 , \ Menu 3 Item 3
' M33 CFA ,
1111100001100010 , \ Menu 3 Item 4
' M34 CFA , DECIMAL
HERE
255 ,
' NOOP CFA ,
CONSTANT MENUEND
\ ----------------------------------------------------------
\ The Menu Command Interpreter
\ ----------------------------------------------------------
: MENUCHECK
MENUEND MENUVECTORS
DO
I DDUP @
=
IF
2+ LEAP
THEN
DROP
4
+LOOP
MENUEND 2+
;
: MENUACTION DROP MENUNUMBER MENUCHECK @EXECUTE ;
\ ----------------------------------------------------------
\ Install and Remove Menus
\ ----------------------------------------------------------
$CONSTANT WINTITLE $MENUTEST$ \ Window Title for Demo window
D0 DVARIABLE WINDOW1 \ DVARIABLE to contain your Window handle
: SETMENU \ Install Menus
WINDOW1 D@ 0 AREG D!
MENU1 1 AREG D!
INTUBASE -264 LIBRARY
;
: CLEARMENU \ Remove Menus
WINDOW1 D@ 0 AREG D!
INTUBASE -54 LIBRARY
;
\ ---------------------
\ Demonstration Program
\ ---------------------
: TESTMENU
TIMEOFF \ Switch off auto-time display
INITMENUS \ Initialise Menu structures
STDWINDOW \ Set up for standard Workbench window
DRAGGAD \ Include Drag gadget
DEPTHGAD \ Include Depth gadget
CLOSEGAD \ Include Close gadget..........
WINDOWCLOSE 0! \ ..and set up Window Close Gadget Flag
WINTITLE \ Window Title Text String
0 0 400 190 \ Window Dimensions
2 0 \ 2-Bitplanes, no Superbitmap Window
OPENWINDOW \ Open the new Window
DFLAG0= IF \ ??? Window failed to open ???
DDROP \ We have no window, so finish
ELSE
DTRIP \ Window opened OK, so
WINDOW1 D! \ Store window handle
MAKEINWINDOW \ Make Inputwindow
MAKEOUTWINDOW \ Make Outputwindow
CUROFF \ Switch off cursor
EVENTON \ Switch on Event Reporting
SETMENU \ Install Menus into Window
WBENCHTOFRONT \ Display Workbench
CR
." Hello!" \ Hailing Text
CR CR
." Try all the menu selections."
CR CR
." Press <Esc> to exit this Demo,"
CR CR
." or Click on the window CLOSE Gadget."
BEGIN \ Input processing loop
KEY
DUP 1254 = IF MENUACTION THEN
27 = \ Check for <Esc>
WINDOWCLOSE @ OR \ or Window Close Gadget
UNTIL \ Now Clear-up and Exit
CLEARMENU \ Remove Menus
FORTHOUTWINDOW \ Reset HeliOS Output
FORTHINWINDOW \ Reset HeliOS Input
WINDOW1 D@ CLOSEWINDOW \ Close Window
THEN
TIMEON \ Switch on auto-time display
WBENCHTOBACK \ Move Workbench to back
;
TESTMENU
\ ---------------------------------------------------------------------------
\ The End
\ ---------------------------------------------------------------------------