Skip to content

rigtmenulib

This library builds menus with GadTools, so the operating system lays them out: it positions the items, takes the font of the screen into account and draws bar items and check marks. It needs gadtools.library; without it, the commands that build the menus do nothing.

The library has its own object, GTMenuList. A program first builds the menus in a list of the object: GTMenuTitle adds titles, GTMenuItem items and GTSubItem sub items, and GTFreeMenu removes them again. Titles, items and sub items are numbered from 0, and a new entry is inserted at its number: the entry before it must exist, otherwise the command does nothing. CreateMenuStrip then turns the list into a menu strip for the screen in use, and GTSetMenu attaches it to the window in use; GTUnSetMenu takes it off again.

GTMenuState, GTMenuChecked, GTSetMenuChecked and GTGetUserData work on the menu strip itself, so CreateMenuStrip or GTSetMenu must have made it. A strip made again starts from the list, so the changes of GTMenuState and GTSetMenuChecked are lost. Before the list of a strip that is attached to a window is made again, the strip must be taken off with GTUnSetMenu.

The numbers of menus, items and sub items are checked only when the program runs with the debugger, which reports an illegal number; without it, a number that does not exist makes these commands read and write near address 0.

The library lays the menus out as new look menus; for the full new look, open the window with the flag $200000 (new look menus). A menu with two items and a bar between them, and an item with a shortcut:

WbToScreen 0
Window 0,0,20,320,100,$20100f,"Menus",1,2
GTMenuTitle 0,0,"Project"
GTMenuItem 0,0,0,0,"Open...","O"
GTMenuItem 0,0,0,1
GTMenuItem 0,0,0,2,"Quit","Q"
GTSetMenu 0
Repeat
  ev.l=WaitEvent
  If ev=$100 Then NPrint MenuHit," ",ItemHit
Until ev=$200

The fixed bugs of the library are listed in Fixes in rigtmenulib.

Based on the RI GTMenus Lib guide by Reflective Images (Red When Excited).

Library number 37. It manages GTMenuList objects, by default at most 5 (the compiler options set the maximum).

Commands

CreateMenuStrip

Makes a GadTools menu strip of the list of a GTMenuList object, laid out for the screen in use; an old strip of the object is freed first. As a function it returns -1 if the strip was made, else 0.

Statement or function, result .l. Help text: GTMenuList#
Arguments: .w

A screen must be in use. Call it again after the list has changed; take the strip off its window with GTUnSetMenu first. With the debugger, an empty list is reported as an error.

The result is 0 without gadtools.library, for a list without titles, and when GadTools cannot make or lay out the strip. The object then has no strip, so a later GTSetMenu attaches no menus.

GTFreeMenu

Removes a title, an item or a sub item from the list of a GTMenuList object, with the items and sub items that belong to it. The menu strip changes only when CreateMenuStrip makes it again.

Statement. Help text: GTMenuList#,Menu[,Item[,Subitem]]
3 forms:

  • .w, .w
  • .w, .w, .w
  • .w, .w, .w, .w

An entry that does not exist is ignored. A negative sub item number removes the whole item, as the form without a sub item does. With the debugger, a negative item number is reported as an error.

GTGetUserData

Returns the UserData of an item or sub item of the menu strip of a GTMenuList object, as given to GTMenuItem or GTSubItem. A Subitem of -1 means the item itself.

Function, result .l. Help text: (GTMenuList#,Menu,Item[,Subitem])
2 forms:

  • .w, .w, .w
  • .w, .w, .w, .w

GTMenuChecked

Returns -1 if the item or sub item of the menu strip of a GTMenuList object has its check mark, else 0.

Function, result .w. Help text: (GTMenuList#,Menu,Item[,Subitem])
2 forms:

  • .w, .w, .w
  • .w, .w, .w, .w

GTMenuItem

Inserts an item as item number item of title menu into the list of a GTMenuList object. Without itemtext$ it is a bar between items.

Statement. Help text: GTMenuList#,flags,menu,item[,itemtext$[,shortcut$[,mutualexclude[,UserData]]
5 forms:

  • .w, .w, .w, .w
  • .w, .w, .w, .w, $
  • .w, .w, .w, .w, $, $
  • .w, .w, .w, .w, $, $, .l
  • .w, .w, .w, .w, $, $, .l, .l

flags are the flags of a GadTools menu item, for example $1 for an item with a check mark, $8 for one that toggles, $100 for one checked at the start, $10 for a disabled one. shortcut$ is the key that selects the item with the Amiga key. mutualexclude is a bit mask of the items of the same title that are unchecked when this one is checked. UserData is a long that GTGetUserData returns. The title and the item before the new one must exist, otherwise the command does nothing.

GTMenuList

The object of this library, a list of menu titles, items and sub items and the menu strip that CreateMenuStrip makes of it.

Object name. Help text: List of GT Menus

Freeing the object frees the menu strip and the list, with the texts of the titles.

GTMenuState

Enables (On) or disables (Off) a title, an item or a sub item of the menu strip of a GTMenuList object; with no menu given, all titles.

Statement. Help text: GTMenuList#[,Menu[,Item[,Subitem]]],On|Off
4 forms:

  • .w, .w
  • .w, .w, .w
  • .w, .w, .w, .w
  • .w, .w, .w, .w, .w

The strip is changed directly, also while it is attached to a window, and not the list: a strip made again by CreateMenuStrip starts from the list and loses the change.

GTMenuTitle

Inserts a menu title with the text title$ as title number menu into the list of a GTMenuList object.

Statement. Help text: GTMenuList#,menu,title$
Arguments: .w, .w, $

Titles are numbered from 0; the title before the new one must exist, otherwise the command does nothing. The titles behind it move up by one.

GTSetMenu

Attaches the menu strip of a GTMenuList object to the window in use, replacing the menu strip the window has. If there is no strip yet, CreateMenuStrip is called first.

Statement. Help text: GTMenuList#
Arguments: .w

GTSetMenuChecked

Sets (On) or clears (Off) the check mark of an item or sub item of the menu strip of a GTMenuList object.

Statement. Help text: GTMenuList#,Menu,Item[,Subitem],Off|On
2 forms:

  • .w, .w, .w, .w
  • .w, .w, .w, .w, .w

The strip is changed directly, also while it is attached to a window, and not the list: a strip made again by CreateMenuStrip starts from the list and loses the change.

GTSubItem

Inserts a sub item as sub item number subitem of item item of title menu into the list of a GTMenuList object. Without itemtext$ it is a bar.

Statement. Help text: GTMenuList#,flags,menu,item,subitem[,itemtext$[,shortcut$[,mutualexclude[,UserData]]]]
5 forms:

  • .w, .w, .w, .w, .w
  • .w, .w, .w, .w, .w, $
  • .w, .w, .w, .w, .w, $, $
  • .w, .w, .w, .w, .w, $, $, .l
  • .w, .w, .w, .w, .w, $, $, .l, .l

The arguments are those of GTMenuItem; mutualexclude applies to the sub items of the same item. The title, the item and the sub item before the new one must exist, otherwise the command does nothing.

GTUnSetMenu

Takes the menu strip off the window in use.

Statement. Help text: - removes the gtmenulist from the current window
No arguments.