AmendHub

Download: |

schrockwell

/

PopUp

 

(View History)


Pop-up menu helper for System 6

schrockwell   Rename kPopUpStyleAll to kPopUpStyleDefault

Name Last Commit Last Modified
PopUp.c Add initial PopUp library and README 5 days ago
PopUp.h Rename kPopUpStyleAll to kPopUpStyleDefault 5 days ago
README Rename kPopUpStyleAll to kPopUpStyleDefault 5 days ago

README
                        Easy Pop-Up Menus for System 6!
                     Rockwell Schrock <rockwell@schrock.me>
                            https://schrockwell.com

This library makes it more convenient to add pop-up menus to System 6
applications.

In System 7 and later, you can define a control with procID 1008, but
prior to that, some hand-holding is required to achieve the expected
control behavior.

These functions take care of the grunt work for System 6:

- drawing the control
- opening the menu with PopUpMenuSelect()
- storing the selected item

To use it, you only need to provide:

- a WindowPtr for the containing window
- a Rect for the bounds of the menu control
- a MenuHandle to the menu
- styling options

...and add hooks in three places:

1. Initialization
2. Event loop
3. Window update

See PopUp.h for more documentation and styling options.

=== Example ===

// 1. Initialization

PopUpPtr gPopup; // <---

void WindowInit()
{
  WindowPtr window;
  Rect windRect;
  Rect popupRect = { 10, 10, 29, 120 }; // <--- recommend 19px height
  MenuHandle menu;
  
  window = GetNewWindow(kBaseResID, nil, kMoveToFront);
  menu = GetMenu(kPopUpMenuResourceID);
  
  gPopup = CreatePopUp(window, &popupRect, menu, kPopUpStyleDefault); // <---
  
  SetPort(window);
  ShowWindow(window);
}

// 2. Event loop

void DoEvent(EventRecord *eventPtr)
{
  if (HandlePopUpEvent(gPopup, eventPtr)) // <---
  {
    // gPopup->item contains the newly-selected item
    return;
  }
  
  // ...rest of event handlers...
}

// 3. Window updates

void DoUpdate(EventRecord *eventPtr)
{
  WindowPtr window = (WindowPtr)eventPtr->message;
  
  BeginUpdate(window);
  
  DrawPopUp(gPopup); // <---
  
  EndUpdate(window);
}