home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
new
/
dev
/
e
/
amigae
/
rkrmsrc
/
intuition
/
menus
/
menulayout.e
next >
Wrap
Text File
|
1995-03-26
|
18KB
|
461 lines
-> menulayout.e - Example showing how to do menu layout in general. This
-> example also illustrates handling menu events, including IDCMP_MENUHELP
-> events.
->
-> Note that handling arbitrary fonts is fairly complex. Applications that
-> require V37 should use the simpler menu layout routines found in the
-> GadTools library.
OPT PREPROCESS
MODULE 'dos/dos',
'graphics/rastport',
'graphics/text',
'intuition/intuition',
'intuition/screens'
ENUM ERR_NONE, ERR_DRAW, ERR_FONT, ERR_KICK, ERR_MENU, ERR_PUB, ERR_WIN
RAISE ERR_DRAW IF GetScreenDrawInfo()=NIL,
ERR_FONT IF OpenFont()=NIL,
ERR_MENU IF SetMenuStrip()=FALSE,
ERR_PUB IF LockPubScreen()=NIL,
ERR_WIN IF OpenWindowTagList()=NIL
DEF firstMenu
-> Open all of the required libraries. Note that we require V37, as the
-> routine uses OpenWindowTags().
PROC main() HANDLE
IF KickVersion(37)=FALSE THEN Raise(ERR_KICK)
doWindow()
EXCEPT DO
-> E-Note: we can print a minimal error message
SELECT exception
CASE ERR_DRAW; WriteF('Error: Failed to get screen DrawInfo\n')
CASE ERR_KICK; WriteF('Error: Needs Kickstart V37+\n')
CASE ERR_MENU; WriteF('Error: Failed to attach menu\n')
CASE ERR_PUB; WriteF('Error: Failed to lock public screen\n')
CASE ERR_WIN; WriteF('Error: Failed to open window\n')
ENDSELECT
RETURN IF exception=ERR_NONE THEN RETURN_FAIL ELSE RETURN_OK
ENDPROC
-> Open a window with some properly positioned text. Layout and set the menus,
-> then process any events received. Cleanup when done.
PROC doWindow() HANDLE
-> E-Note: some of these are global arrays in the C version
DEF settItem, editItem, prtItem, projItem, menus,
winText0:PTR TO intuitext, winText1:PTR TO intuitext,
window=NIL:PTR TO window, screen=NIL:PTR TO screen,
drawinfo=NIL:PTR TO drawinfo,
win_width, alt_width, win_height
screen:=LockPubScreen(NIL)
drawinfo:=GetScreenDrawInfo(screen)
-> Window Text for Explanation of Program
-> Get the colors for the window text
-> Use the screen's font for the text
-> E-Note: link directly without an array
winText0:=[drawinfo.pens[TEXTPEN], drawinfo.pens[BACKGROUNDPEN], RP_JAM2,
0, 0, screen.font, 'How to do a Menu', NIL]:intuitext
winText1:=[drawinfo.pens[TEXTPEN], drawinfo.pens[BACKGROUNDPEN], RP_JAM2,
0, 0, screen.font, '(with Style)', winText0]:intuitext
-> Calculate window size
win_width:=100+IntuiTextLength(winText0)
alt_width:=100+IntuiTextLength(winText1)
IF win_width<alt_width THEN win_width:=alt_width
win_height:=1+screen.wbortop+screen.wborbottom+(screen.font.ysize*5)
-> Calculate the correct positions for the text in the window
winText0.leftedge:=Shr(win_width-IntuiTextLength(winText0), 1)
winText0.topedge:=1+screen.wbortop+(2*screen.font.ysize)
winText1.leftedge:=Shr(win_width-IntuiTextLength(winText1), 1)
winText1.topedge:=winText0.topedge+screen.font.ysize
-> Open the window
window:=OpenWindowTagList(NIL,
[WA_PUBSCREEN, screen,
WA_IDCMP, IDCMP_MENUPICK OR IDCMP_CLOSEWINDOW OR IDCMP_MENUHELP,
WA_FLAGS, WFLG_DRAGBAR OR WFLG_DEPTHGADGET OR WFLG_CLOSEGADGET OR
WFLG_ACTIVATE OR WFLG_NOCAREREFRESH,
WA_LEFT, 10, WA_TOP, screen.barheight+1,
WA_WIDTH, win_width, WA_HEIGHT, win_height,
WA_TITLE, 'Menu Example', WA_MENUHELP, TRUE,
NIL])
-> Give a brief explanation of the program
PrintIText(window.rport, winText1, 0, 0)
-> E-Note: define the menus using (local) typed lists rather than arrays
-> E-Note: link menu items in reverse order to layout
-> Settings Items
-> 'Eat It Too' (excludes 'Have Your Cake')
settItem:=[NIL, 0, 0, 0, 0,
ITEMTEXT OR ITEMENABLED OR HIGHCOMP OR CHECKIT, 4,
[0, 1, RP_JAM2, CHECKWIDTH, 1, NIL,
' Eat It Too', NIL]:intuitext,
NIL, NIL, NIL, MENUNULL]:menuitem
-> 'Have Your Cake' (initially selected, excludes 'Eat It Too')
settItem:=[settItem, 0, 0, 0, 0,
ITEMTEXT OR ITEMENABLED OR HIGHCOMP OR CHECKIT OR CHECKED, 8,
[0, 1, RP_JAM2, CHECKWIDTH, 1, NIL,
' Have Your Cake', NIL]:intuitext,
NIL, NIL, NIL, MENUNULL]:menuitem
-> 'Auto Save' (toggle-select, initially selected)
settItem:=[settItem, 0, 0, 0, 0,
ITEMTEXT OR ITEMENABLED OR HIGHCOMP OR CHECKIT OR
MENUTOGGLE OR CHECKED, 0,
[0, 1, RP_JAM2, CHECKWIDTH, 1, NIL,
' Auto Save', NIL]:intuitext,
NIL, NIL, NIL, MENUNULL]:menuitem
-> 'Sound...'
settItem:=[settItem, 0, 0, 0, 0,
ITEMTEXT OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL,
'Sound...', NIL]:intuitext,
NIL, NIL, NIL, MENUNULL]:menuitem
-> Edit Menu Items
-> 'Undo' (key-equivalent: "Z")
editItem:=[NIL, 0, 0, 0, 0,
ITEMTEXT OR COMMSEQ OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'Undo', NIL]:intuitext,
NIL, "Z", NIL, MENUNULL]:menuitem
-> 'Erase' (disabled)
editItem:=[editItem, 0, 0, 0, 0,
ITEMTEXT OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'Erase', NIL]:intuitext,
NIL, NIL, NIL, MENUNULL]:menuitem
-> 'Paste' (key-equivalent: "V")
editItem:=[editItem, 0, 0, 0, 0,
ITEMTEXT OR COMMSEQ OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'Paste', NIL]:intuitext,
NIL, "V", NIL, MENUNULL]:menuitem
-> 'Copy' (key-equivalent: "C")
editItem:=[editItem, 0, 0, 0, 0,
ITEMTEXT OR COMMSEQ OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'Copy', NIL]:intuitext,
NIL, "C", NIL, MENUNULL]:menuitem
-> 'Cut' (key-equivalent: "X")
editItem:=[editItem, 0, 0, 0, 0,
ITEMTEXT OR COMMSEQ OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'Cut', NIL]:intuitext,
NIL, "X", NIL, MENUNULL]:menuitem
-> Print Sub-Items
-> 'Draft'
prtItem:=[NIL, 0, 0, 0, 0,
ITEMTEXT OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'Draft', NIL]:intuitext,
NIL, NIL, NIL, MENUNULL]:menuitem
-> 'NLQ'
prtItem:=[prtItem, 0, 0, 0, 0,
ITEMTEXT OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'NLQ', NIL]:intuitext,
NIL, NIL, NIL, MENUNULL]:menuitem
-> Uses the >> character to indicate a sub-menu item.
-> This is \273 Octal, 0xBB Hex or Alt-0 from the Keyboard.
->
-> NOTE that standard menus place this character at the right margin of the
-> menu box. This may be done by using a second IntuiText structure for the
-> single character, linking this IntuiText to the first one, and positioning
-> the IntuiText so that the character appears at the right margin.
-> GadTools library will provide the correct behavior.
-> Project Menu Items
-> 'Quit' (key-equivalent: "Q")
projItem:=[NIL, 0, 0, 0, 0,
ITEMTEXT OR COMMSEQ OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'Quit', NIL]:intuitext,
NIL, "Q", NIL, MENUNULL]:menuitem
-> 'About...'
projItem:=[projItem, 0, 0, 0, 0,
ITEMTEXT OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'About...', NIL]:intuitext,
NIL, NIL, NIL, MENUNULL]:menuitem
-> 'Print' (has sub-menu)
projItem:=[projItem, 0, 0, 0, 0,
ITEMTEXT OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'Print »', NIL]:intuitext,
NIL, NIL, prtItem, MENUNULL]:menuitem
-> 'Save As...' (key-equivalent: "A")
projItem:=[projItem, 0, 0, 0, 0,
ITEMTEXT OR COMMSEQ OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'Save As...', NIL]:intuitext,
NIL, "A", NIL, MENUNULL]:menuitem
-> 'Save' (key-equivalent: "S")
projItem:=[projItem, 0, 0, 0, 0,
ITEMTEXT OR COMMSEQ OR ITEMENABLED OR HIGHCOMP, 0,
[0, 1, RP_JAM2, 2, 1, NIL, 'Save', NIL]:intu