<--- Cannot embed stylesheet: [Errno 2] No such file or directory: '../../../aros.css' --->

popupmenu

Index


PM_AbortHook() PM_AlterState() PM_ExLstA() PM_FilterIMsgA()
PM_FindItem() PM_FreeIDList() PM_FreePopupMenu() PM_GetItemAttrsA()
PM_GetVersion() PM_InsertMenuItemA() PM_ItemChecked() PM_LayoutMenuA()
PM_MakeIDListA() PM_MakeItemA() PM_MakeMenuA() PM_OBSOLETEFilterIMsgA()
PM_OpenPopupMenuA() PM_ReloadPrefs() PM_RemoveMenuItem() PM_SetItemAttrsA()

PM_AbortHook()

Synopsis

BOOL PM_AbortHook(
   APTR handle)

Function

Check whether the pointer has left the item whose submenu is being
constructed. An existing child window may also be refreshed.

Inputs

handle - Opaque parent handle supplied to the active SubConstruct
    hook. Extract the IPTR value from the hook message and cast that
    value to APTR; do not pass the message pointer itself.

Result

TRUE if the pointer is outside the selected item; FALSE otherwise.

Notes

Use only during the constructor callback that supplied the handle.
NULL, expired handles and calls without an active selected item are
invalid. A TRUE result does not stop the constructor automatically;
the hook must decide whether to abandon its work and return NULL.
The refresh side effect can perform window operations and must run
in task context.

PM_AlterState()

Synopsis

void PM_AlterState(
   struct PopupMenu *pm, struct PM_IDLst *l, UWORD action)

Function

Apply each ID-list operation to the first matching menu item. Update
its checked and selected flags and any attached AutoStore value.

Inputs

pm - First menu item, or NULL.
l - ID list, or NULL.
action - 3 for selection; 2 for deselection. Other values do nothing.

Result

None.

Notes

For selection, Include and Reflect check the item; Exclude and
Inverse clear it. For deselection, Reflect clears the item and
Inverse checks it; Include and Exclude leave it unchanged. Missing
IDs are skipped. Operations run in list order without checking
Hidden, Disabled, Checkit or Toggle attributes.

This call does not redraw a displayed menu or invoke a menu handler.
The menu and list remain owned by their callers.

PM_ExLstA()

Synopsis

struct PM_IDLst * PM_ExLstA(
   ULONG *id)

Function

Create an exclusion list from an array of item IDs.

Inputs

id - Non-NULL readable ULONG array terminated by zero.

Result

The new list, or NULL for an empty array or any allocation failure.
On failure, all nodes allocated by this call are freed.

Notes

IDs are copied in order; the array is not retained. Zero cannot be
represented in this form. Use PM_MakeIDListA() for ID zero or other
operation kinds. Ownership follows PM_MakeIDListA().

PM_FilterIMsgA()

Synopsis

APTR PM_FilterIMsgA(
   struct Window *w, struct PopupMenu *pm, struct IntuiMessage *im, struct TagItem *tags)

Function

Handle right-command shortcuts or forward menu-button events to
PM_OpenPopupMenuA().

Inputs

w - Parent window for popup display, or NULL for the active screen.
pm - Menu tree, or NULL.
im - Caller-owned IntuiMessage, or NULL.
tags - Terminated option list, or NULL.

Tags

PM_MenuHandler (struct Hook *) - Optional synchronous selection hook.
    For a shortcut, the object is the item and the message is NULL.
PM_AutoPullDown - Presence enables handling MENUDOWN and MENUUP,
    even if ti_Data is FALSE.
PM_RawKey (BOOL) - Handle IDCMP_RAWKEY when TRUE; otherwise handle
    IDCMP_VANILLAKEY. Default FALSE.
Other tags are forwarded unchanged when a popup is opened.

Result

Selected UserData, or NULL when no item is selected. NULL UserData
also returns NULL, so this result is not a message-consumed flag.

Notes

The caller must reply to the original message; this function neither
replies nor takes ownership. NULL pm or im returns immediately.
Shortcuts require IEQUALIFIER_RCOMMAND and match the first command
key case-insensitively. Disabled items are ignored. Checkable items
toggle, update AutoStore and apply their ID list before the hook.
Keep the tree and callback data valid for the whole call. Popup
handling can block; call from task context.

Bugs

Shortcut handling ignores Hidden, NoSelect and Toggle restrictions.
Raw key codes are compared directly with command-key bytes without
keymap translation. Popup forwarding inherits PM_OpenPopupMenuA()
limitations, including ambiguous zero results.

PM_FindItem()

Synopsis

struct PopupMenu * PM_FindItem(
   struct PopupMenu *menu, ULONG id)

Function

Find the first item with the specified ID. Search each item before
its descendants, then continue with its next sibling.

Inputs

menu - First item of an acyclic menu tree, or NULL.
id - Item ID, including zero.

Result

A borrowed pointer to the first match, or NULL if absent.

Notes

Hidden, disabled and unselectable items are included. Duplicate IDs
are not rejected. The result remains valid only while its item exists;
this function neither detaches nor retains it.

PM_FreeIDList()

Synopsis

void PM_FreeIDList(
   struct PM_IDLst *list)

Function

Free every node of an ID list allocated by popupmenu.library.

Inputs

list - First node, or NULL.

Result

None.

Notes

Do not free a list still owned by an item. A shared list must remain
valid until every referring item has released it; its owner then
frees it once. Keep popupmenu.library open until disposal completes.

PM_FreePopupMenu()

Synopsis

void PM_FreePopupMenu(
   struct PopupMenu *p)

Function

Free an item, all following siblings and every descendant. Free
copied titles, copied user-data strings and owned ID lists.

Inputs

p - First item to free, or NULL.

Result

None.

Notes

Detach an item before freeing it if following siblings must survive.
Do not free a menu while it is displayed or used by a callback.
Objects, images, hooks, AutoStore targets, ordinary UserData and
shared exclusion lists remain caller-owned. SubDestruct hooks are
not called. All pointers to freed items and their owned data become
invalid. Keep popupmenu.library open until disposal completes.

PM_GetItemAttrsA()

Synopsis

LONG PM_GetItemAttrsA(
   struct PopupMenu *p, struct TagItem *tags)

Function

Copy supported item attributes into caller-provided storage.

Inputs

p - Item to query, or NULL.
tags - Terminated tag list, or NULL. Each ti_Data is the address
    of writable storage of the type stated below.

Tags

PM_Title (STRPTR *) - Borrowed copied title, in text mode only.
PM_TitleID (ULONG *) - Locale ID, in locale mode only.
PM_Object (Object **) - Borrowed object, in object mode only.
PM_UserData (APTR *) - Stored user data, including a copied string.
PM_ID (ULONG *) - Item ID.
PM_Sub, PM_Members (struct PopupMenu **) - Borrowed child list.
PM_LayoutMode, PM_Flags (ULONG *) - Layout value or flags.
PM_Exclude (struct PM_IDLst **) - Borrowed ID list.
PM_ImageSelected, PM_IconSelected (struct Image **) - Selected image.
PM_ImageUnselected, PM_IconUnselected (struct Image **) - Normal image.
PM_AutoStore (BOOL **) - Borrowed Boolean storage pointer.
PM_TextPen (ULONG *) - Stored pen number.
PM_CommKey (char *) - One command-key byte; no terminator is written.
PM_NoSelect, PM_FillPen, PM_ShadowPen, PM_ShinePen, PM_Checkit,
PM_Checked, PM_Italic, PM_Bold, PM_Underlined, PM_TitleBar,
PM_WideTitleBar, PM_ExcludeShared, PM_Disabled, PM_Shadowed,
PM_Center, PM_Hidden, PM_Toggle (BOOL *) - Corresponding state.

Result

Number of attributes written. Zero for NULL p. Unsupported tags and
title queries for an inactive title mode leave storage unchanged.

Notes

Tags are processed in order, including repeats. Returned pointers
are not copied or retained. Item-owned values become invalid when
replaced or when the item is freed. Keep the item stable during the
query; the function does not lock it.

Bugs

PM_TitleBar and PM_WideTitleBar test masks that include the
no-selection flag. An unselectable item can therefore report TRUE
without having the requested separator style.

PM_GetVersion()

Synopsis

STRPTR PM_GetVersion(
   )

Function

Build a descriptive library-version string, including detected
graphics-environment information.

Inputs

None.

Result

Pointer to a library-owned shared buffer containing a terminated
string. Do not modify or free it.

Notes

Each call overwrites the buffer. Copy the string before another call
or before closing the library. This text is not a numeric version
interface; use OpenLibrary() version requirements for compatibility.

PM_InsertMenuItemA()

Synopsis

LONG PM_InsertMenuItemA(
   struct PopupMenu *menu, struct TagItem *tags)

Function

Process insertion-method tags and link each subsequent item using
the selected method. No item is allocated or copied.

Inputs

menu - First menu item, or NULL.
tags - Terminated tag list, or NULL. Set a method before its items.

Tags

PM_Insert_After (struct PopupMenu *) - Insert after this item.
PM_Insert_AfterID (ULONG) - Insert after the first matching ID.
PM_Insert_Before (struct PopupMenu *) - Insert before this item;
    the item must have a preceding sibling. See BUGS.
PM_Insert_BeforeID (ULONG) - Find the preceding sibling of the first
    matching ID and insert after it. See BUGS for a list head.
PM_Insert_First (BOOL) - TRUE inserts after menu, preserving a header.
PM_Insert_Last (BOOL) - TRUE appends to menu's sibling list.
PM_InsertSub_First (struct PopupMenu *) - Prepend to this item's
    children and update its child-list pointer.
PM_InsertSub_Last (struct PopupMenu *) - Append to the sibling chain
    starting at this pointer, not to its child list.
PM_InsertSub_Sorted (struct PopupMenu *) - Broken; see BUGS.
PM_Insert_Item (struct PopupMenu *) - Distinct unlinked item to insert.
    May repeat. Unknown tags are ignored.

Result

Number of PM_Insert_Item tags with a non-NULL item and a non-NULL
selected target. This can exceed the number of successful insertions.
Zero for NULL menu.

Notes

The target remains unchanged between item tags. Repeated insertion
after one target or at the first position reverses item order.
A linked item's ownership passes to the menu. Keep an item unowned
elsewhere and keep the tree acyclic. Do not alter an active popup.

Bugs

Sorted insertion never finds an insertion point because the string
comparison result is unsigned and tested for less than zero; the
item tag can still count. Pointer-based insertion before a list head
can create a cycle. BeforeID at a list head inserts after that head.
Use a persistent header and avoid these unsupported cases.

PM_ItemChecked()

Synopsis

BOOL PM_ItemChecked(
   struct PopupMenu *p, ULONG id)

Function

Read the checked state of the first item with the specified ID.

Inputs

p - First item of an acyclic menu tree, or NULL.
id - Item ID.

Result

TRUE if checked, FALSE if unchecked, or PMERR (-5) if not found.

Notes

Test for PMERR before interpreting the result as a Boolean. A missing
item produces a nonzero result. PM_Checkit need not be enabled.

PM_LayoutMenuA()

Synopsis

LONG PM_LayoutMenuA(
   struct Window *window, struct PopupMenu *pm, struct TagItem *tags)

Function

Layout is not implemented by this entry point. No menu or window
state is changed.

Inputs

window, pm, tags - Ignored.

Result

Always zero.

PM_MakeIDListA()

Synopsis

struct PM_IDLst * PM_MakeIDListA(
   struct TagItem *tags)

Function

Allocate an ordered list of item IDs and state operations.

Inputs

tags - Terminated tag list, or NULL.

Tags

PM_ExcludeID (ULONG) - Clear this ID when the source is selected.
PM_IncludeID (ULONG) - Check this ID when the source is selected.
PM_ReflectID (ULONG) - Check on selection; clear on deselection.
PM_InverseID (ULONG) - Clear on selection; check on deselection.
Each tag may repeat. Zero is a valid ID. Other tags are ignored.

Result

The new list, or NULL if empty or if any allocation fails. On failure,
all nodes allocated by this call are freed.

Notes

The list contains IDs, not references to menu items. Missing IDs are
skipped when the list is applied. The caller owns the list until it
is assigned as an owned PM_Exclude attribute. Otherwise release it
with PM_FreeIDList().

PM_MakeItemA()

Synopsis

struct PopupMenu * PM_MakeItemA(
   struct TagItem *tags)

Function

Allocate a cleared menu item and apply its attributes in tag order.

Inputs

tags - Tag list accepted by PM_SetItemAttrsA(), or NULL.

Result

The new item, or NULL if the item allocation fails.

Notes

The caller owns the item until it is linked into an owning menu.
Release an unlinked item with PM_FreePopupMenu(). Attribute data
ownership follows PM_SetItemAttrsA(). Keep popupmenu.library open
until its items and ID lists have been released.

Bugs

Attribute allocation failures do not make this function return NULL.
A returned item can have an unset title or copied user-data string.

PM_MakeMenuA()

Synopsis

struct PopupMenu * PM_MakeMenuA(
   struct TagItem *tags)

Function

Link existing items into a sibling list in tag order. No container
item is allocated.

Inputs

tags - Terminated tag list, or NULL.

Tags

PM_Item (struct PopupMenu *) - Item to append. May be repeated.
    Supply distinct, unlinked items. Existing child lists remain
    attached. Other application tags are ignored.

Result

The first item, or NULL for an empty list or a NULL PM_Item.

Notes

Ownership of the supplied items passes to the resulting menu. If
any PM_Item is NULL, the scan continues and the entire linked result
is freed, including items supplied after the NULL tag. Do not free
those items again. Dispose of a successful result with
PM_FreePopupMenu(). A menu must be acyclic and must not share owned
items with another menu.

PM_OBSOLETEFilterIMsgA()

Synopsis

APTR PM_OBSOLETEFilterIMsgA(
   struct Window *window, struct PopupMenu *pm, struct IntuiMessage *im, struct TagItem *tags)

Function

Compatibility stub. No message processing is performed.

Inputs

window, pm, im, tags - Ignored.

Result

Always NULL.

Notes

The caller remains responsible for replying to im.

See also

PM_FilterIMsgA()


PM_OpenPopupMenuA()

Synopsis

IPTR PM_OpenPopupMenuA(
   struct Window *prevwnd, struct TagItem *tags)

Function

Display a popup and process input synchronously until it closes.
Update item selection state and invoke the optional menu handler
before returning.

Inputs

prevwnd - Live parent window. NULL uses the active screen, which
    must exist and remain available throughout the call.
tags - Terminated option list, or NULL.

Tags

PM_Menu (struct PopupMenu *) - Borrow the menu tree for this call.
PM_Left, PM_Top (LONG) - Position relative to the parent window.
    Odd left coordinates are increased by one before adding the
    parent offset. Defaults use the screen mouse position.
PM_MinWidth, PM_MinHeight (LONG) - Minimum menu dimensions.
PM_Right, PM_Bottom (LONG), PM_CenterScreen (BOOL) - Unsafe positioning
    options in this implementation; see BUGS.
PM_ForceFont (struct TextFont *) - Borrow a font for the call.
PM_PullDown (BOOL) - Request a horizontal pulldown. Its effect depends
    on the pulldown-position preference; when enabled it moves the
    root menu to the screen's top-left corner.
PM_MenuHandler (struct Hook *) - Enable multiple selection. Supply a
    valid hook; it receives each selected item after display closes.
    Its message points to a temporary IPTR containing zero.
PM_LocaleHook (struct Hook *) - Resolve locale title IDs to readable
    strings for measurement and drawing. The item is the hook object.
    Returned strings remain caller-owned. See BUGS for message layout.
PM_Code (UWORD) - Input-event code. The release prefix cancels display
    and stops processing further tags.
PM_UseLMB (BOOL) - Set button flags; see BUGS.
PM_HintBox - Presence selects hint display, even with FALSE data.
    A non-timer input event closes the hint.
Unknown tags, including PM_DRIPensOnly, are ignored.

Result

UserData from the last selected item, represented as IPTR, or zero
if no selection was recorded. Selecting an item with NULL UserData
also returns zero. There is no separate error result.

Notes

Call from task context. The function waits for input and timer
messages; there is no caller-selected timeout. It reloads shared
preferences and uses temporary windows and an input handler.

The menu is borrowed, not freed. Keep its items, images, AutoStore
storage, font, hooks and parent screen alive through all callbacks.
Do not concurrently modify or free the tree or reenter popup display
from a callback. Selection can change checked and AutoStore values.
A returned pointer to item-owned UserData remains valid only until
that data is replaced or the item is freed.

Bugs

PM_Right, PM_Bottom and PM_CenterScreen can dereference the root
window before it opens. Root-menu and timer allocation failures are
not handled safely on all paths; zero is not a reliable failure
notification. PM_UseLMB flags are not consulted by selection.

The locale hook receives an IPTR array during measurement but a
pointer to ULONG during drawing. Do not assume a consistent payload
layout on targets where those types differ in size.

PM_ReloadPrefs()

Synopsis

void PM_ReloadPrefs(
   )

Function

Reload shared popup-menu preferences from ENV:sys/PopupMenu.prefs.
Use built-in defaults if the preference file cannot be loaded.

Inputs

None.

Result

None. File and format failures are not reported to the caller.

Notes

This operation can perform DOS I/O; call from task context. The
settings are shared by library users. Serialize reloads with menu
display. PM_OpenPopupMenuA() reloads preferences on each invocation.

PM_RemoveMenuItem()

Synopsis

struct PopupMenu * PM_RemoveMenuItem(
   struct PopupMenu *menu, struct PopupMenu *item)

Function

Detach an item from one sibling list without freeing it or its
children. The first item in the list cannot be removed.

Inputs

menu - First item of the sibling list, or NULL.
item - Item to detach.

Result

The detached item with its next-sibling link cleared, or NULL if
absent or equal to menu.

Notes

Descendants are not searched. Pass their own sibling-list head to
operate on them. The caller owns a detached item and may reinsert it
or free it with PM_FreePopupMenu(). Do not modify an active popup.

PM_SetItemAttrsA()

Synopsis

LONG PM_SetItemAttrsA(
   struct PopupMenu *p, struct TagItem *tags)

Function

Apply item attributes in tag order. Changes take effect immediately;
allocation failures do not roll back earlier changes.

Inputs

p - Item to change, or NULL.
tags - Terminated tag list, or NULL. ti_Data contains the value.

Tags

PM_Title (STRPTR) - Copy a terminated string; NULL clears the title.
PM_TitleID (ULONG) - Store a locale string ID instead of a title.
PM_Object (Object *) - Borrow an object instead of a title.
PM_UserData (APTR) - Borrow arbitrary data returned on selection.
PM_UserDataString (STRPTR) - Copy a non-NULL terminated string.
PM_ID (ULONG) - Set the item ID.
PM_Sub (struct PopupMenu *) - Replace and own the child list, or
    clear it with NULL. Free the old children and select normal
    submenu mode. Do not pass the current list or its descendants.
PM_Members (struct PopupMenu *) - Replace and own group children.
    Free the old list; use horizontal layout if layout was zero.
PM_LayoutMode (ULONG) - Set layout; nonzero enables group mode.
    PML_Horizontal and PML_Vertical select the respective directions.
PM_Flags (ULONG) - Replace all flags, including ownership flags.
    Reserved for callers that preserve the item's ownership state.
PM_NoSelect (BOOL) - Set or clear the no-selection flag.
PM_Disabled (BOOL) - Set or clear disabled and no-selection flags.
PM_FillPen, PM_ShadowPen, PM_ShinePen (BOOL) - Enable the respective
    DrawInfo text-pen flag independently.
PM_Italic, PM_Bold, PM_Underlined (BOOL) - Set text-style flags.
PM_Shadowed, PM_Center (BOOL) - Enable shadowed or centered text.
PM_TextPen (ULONG) - Set a custom text pen, stored as an unsigned byte.
PM_TitleBar, PM_WideTitleBar (BOOL) - Set or clear separator masks,
    which also include the no-selection flag.
PM_Checkit (BOOL) - Enable checkmark space.
PM_Checked (BOOL) - Set checked and initial-checked flags. Does not
    write through an existing AutoStore pointer.
PM_Toggle (BOOL) - Allow a checked item to be toggled off by popup
    selection; initially TRUE.
PM_AutoStore (BOOL *) - Borrow writable Boolean storage, or detach
    with NULL. Read its current value into the checked flag now.
PM_Exclude (struct PM_IDLst *) - Attach an ID list. Free the old list
    unless the current ExcludeShared flag is set. See BUGS for NULL.
PM_ExcludeShared (BOOL) - Suppress freeing the attached ID list when
    TRUE. The caller owns a shared list and must keep it alive.
PM_ImageSelected, PM_ImageUnselected (struct Image *) - Borrow the
    selected or normal image and enable image mode. If the opposite
    slot is empty, assign the same pointer to it.
PM_IconSelected, PM_IconUnselected (struct Image *) - Assign the same
    slots but select icon mode; fill an empty opposite slot as above.
PM_CommKey (char *) - Copy the first byte from a readable pointer.
    NULL leaves the key unchanged. This is not a numeric character.
PM_ColourBox (ULONG) - Enable a colour box; store the pen as a byte.
PM_SubConstruct, PM_SubDestruct (struct Hook *) - Borrow submenu hooks.
    Construction receives the parent item and an IPTR message holding
    an opaque handle; return the child list or NULL to cancel.
    Destruction receives the parent item and a NULL message.
PM_Hidden (BOOL) - Set or clear hidden state.

Result

Number of processed attributes, excluding unsupported tags and failed
string copies. PM_Title with NULL clears the title but does not count.
Zero for NULL p. The count is not an all-or-nothing success result.

Notes

Replace title modes only with independent input: an owned old title
is freed before the new title is copied. The same restriction applies
to copied user data. Replaced children and owned ID lists are freed
before assignment. Shared-list flags affect the old list at the time
of replacement, so tag order changes ownership behaviour.

Keep borrowed objects, images, hooks and AutoStore storage valid while
the item uses them. Serialize menu changes with display, traversal
and callbacks. This function performs no redraw. Dynamic submenu
hooks run synchronously during popup use; the destructor is also
called if construction returns NULL. PM_FreePopupMenu() does not
invoke that destructor.

Bugs

PM_Exclude with NULL can free the old list while leaving its address
attached. Do not use it to detach an existing list.

BOOPSI layout and rendering are incomplete; PM_Object does not provide
a usable object-rendering contract. A constructor without an existing
child list does not enter the submenu-opening path.