Skip to content

GraphiteMenus: the Menu Manager - #28

Merged
colemancda merged 13 commits into
masterfrom
feature/menus
Nov 26, 2026
Merged

colemancda merged 13 commits into
masterfrom
feature/menus

Conversation

@colemancda

Copy link
Copy Markdown
Member

Summary

The Menu Manager, the next of the Toolbox's managers after the Window Manager: menus and their items, the menu bar they sit in, and the 'MENU' resources that define them — everything but the drawing and the tracking, which are the host's, as they were Perry's.

  • MenuItem: text in MacRoman, a mark (SetItemMark — the Menu Manager's glyphs, or any character), an icon, a style (SetItemStyle), a keyboard equivalent with its modifiers (SetItemCmd, SetMenuItemKeyEquivalentsMask), a submenu kept by its menu ID as the classic kept it, a command ID (SetMenuItemCommandID), a separator, and the enabled state EnableMenuItem answers. MenuItem(classic:) makes one from an AppendMenu string — the metacharacters as the classic defined them: ; between items, ( disables, < with B, I, U, O, S sets the styles, ! a mark, ^ an icon, / the keyboard equivalent — and a hyphen alone divides. A submenu is the character whose MacRoman byte is its menu ID, with $1B for the key, exactly as the classic's strings were written.
  • Menu (NewMenu, CreateNewMenu's attributes): AppendMenu and AppendMenuItemText, InsertMenuItem, DeleteMenuItem(s), DeleteAllMenuItems, SetMenuItemText, marks (CheckMenuItem's check mark among them), enabling, key equivalents, and the command-ID finds a menu makes alone. MenuAttributes, the seven the header gives, including kMenuAttrHidden, for menus kept in the bar for their keyboard equivalents alone.
  • MenuBar: InsertMenu's order — before the menu of an ID, after them all for 0, and hierMenu (-1), which keeps a submenu or pop-up menu in the list without a title in the bar — DeleteMenu, ClearMenuBar, GetMenuHandle; GetIndMenuItemWithCommandID, EnableMenuCommand and DisableMenuCommand across every menu in the list; MenuKey, which searches the bar's menus and the hierarchical list alike, as the classic did, with the modifiers held; HiliteMenu; and MenuSelect's answer as a menu ID and an item's number from 1. changeObserver tells the host the bar changed, for DrawMenuBar.
  • MenuDefinition, the MDEFs: the sizes a menu takes — the bar's height, an item's, mSizeMsg's width with its columns for the marks, icons and keys and mChooseMsg's geometry — with StandardMenuDefinition, the classic's look: a bar 20 tall, items 16.
  • Menu(bytes:) (GetMenu): a 'MENU' resource — the ID, the size placeholders, the definition's resource ID, the enable flags of the menu and its first 31 items (bit 0 the menu's, item i's bit i, items past 31 enabled), the title, and the items with their five bytes each, a hyphen an item the standard definition draws a divider — with submenus as the classic kept them, the menu ID in the mark field under $1B. menuInvalidErr for bytes a menu can't be read from; bytes past the last item ignored.

Notes for review

  • One commit per file, and the package builds at every one: the result codes first, then the sources as files no target reads yet, then "Added the GraphiteMenus module" wires them in.
  • The Menu Manager's result codes (-5620 through -5623, with the property ones -5603 and -5604) are Carbon's; the classic had only OSErr's. They live in MacError with the rest.
  • Inside Macintosh's Rez listings write 0b bit strings with the low bit first: the Apple menu's 0b111…101 is bits 1 set and 2 clear — About enabled, the divider disabled — which as a big-endian value is 0x3FFFFFFF, not 0xFFFFFFFD. The tests read the flags as the number they are, and the comment on the Rez listing says what it means.
  • Not here: 'MBAR' resources and GetNewMBar, which need the Resource Chain wired to the Menu Manager (GraphiteMenus depends only on GraphiteBase, as GraphiteSound does); 'mctb' color tables; AppendResMenu and InsertResMenu, which read the desktop's; the Font menu's and the Help menu's special places; pop-up menus as controls draw them, which is the Control Manager's to come; and menu balloons. Drawing and MenuSelect's tracking are the host's, as Perry's menus.c made them AppKit's.

Testing

  • 20 new tests in three files: the metacharacters (the styles' letters greedy, as the classic's were; the mark and icon as characters' codes; a disabled divider; a blank item's spaces its text; a submenu's ID in a control character), items made and changed (append, insert, remove, ranges, all; marks, checks, enabling, key equivalents with modifiers, command IDs, the ones that find nothing), 'MENU' resources (the manual's Apple menu; every field read back; the enable flags' bits, the items past 31 enabled, a disabled menu and item; a submenu from $1B and its ID; bytes after the items ignored; four damaged resources, each menuInvalidErr); the bar (inserting by ID and appending and hierMenu, a menu already in it unmoved, deleting, the hilite cleared, GetMenuHandle over both parts, submenus resolved, commands found and enabled and disabled across menus, hidden menus' commands still found, MenuKey through the hierarchical list, disabled items and menus finding nothing, modifiers held), and the definition (the width with its columns and without them, excludesMarkColumn, the height, item rectangles, hit testing at every edge).
  • The package's whole suite passes on macOS, with and without the FreeType trait. Linux and the 32-bit targets are left to CI.

@colemancda
colemancda merged commit cc21504 into master Nov 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant