| 1 |
Easy Pop-Up Menus for System 6! |
| 2 |
Rockwell Schrock <rockwell@schrock.me> |
| 3 |
https://schrockwell.com |
| 4 |
|
| 5 |
This library makes it more convenient to add pop-up menus to System 6 |
| 6 |
applications. |
| 7 |
|
| 8 |
In System 7 and later, you can define a control with procID 1008, but |
| 9 |
prior to that, some hand-holding is required to achieve the expected |
| 10 |
control behavior. |
| 11 |
|
| 12 |
These functions take care of the grunt work for System 6: |
| 13 |
|
| 14 |
- drawing the control |
| 15 |
- opening the menu with PopUpMenuSelect() |
| 16 |
- storing the selected item |
| 17 |
|
| 18 |
To use it, you only need to provide: |
| 19 |
|
| 20 |
- a WindowPtr for the containing window |
| 21 |
- a Rect for the bounds of the menu control |
| 22 |
- a MenuHandle to the menu |
| 23 |
- styling options |
| 24 |
|
| 25 |
...and add hooks in three places: |
| 26 |
|
| 27 |
1. Initialization |
| 28 |
2. Event loop |
| 29 |
3. Window update |
| 30 |
|
| 31 |
See PopUp.h for more documentation and styling options. |
| 32 |
|
| 33 |
=== Example === |
| 34 |
|
| 35 |
// 1. Initialization |
| 36 |
|
| 37 |
PopUpPtr gPopup; // <--- |
| 38 |
|
| 39 |
void WindowInit() |
| 40 |
{ |
| 41 |
WindowPtr window; |
| 42 |
Rect windRect; |
| 43 |
Rect popupRect = { 10, 10, 29, 120 }; // <--- recommend 19px height |
| 44 |
MenuHandle menu; |
| 45 |
|
| 46 |
window = GetNewWindow(kBaseResID, nil, kMoveToFront); |
| 47 |
menu = GetMenu(kPopUpMenuResourceID); |
| 48 |
|
| 49 |
gPopup = CreatePopUp(window, &popupRect, menu, kPopUpStyleDefault); // <--- |
| 50 |
|
| 51 |
SetPort(window); |
| 52 |
ShowWindow(window); |
| 53 |
} |
| 54 |
|
| 55 |
// 2. Event loop |
| 56 |
|
| 57 |
void DoEvent(EventRecord *eventPtr) |
| 58 |
{ |
| 59 |
if (HandlePopUpEvent(gPopup, eventPtr)) // <--- |
| 60 |
{ |
| 61 |
// gPopup->item contains the newly-selected item |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
// ...rest of event handlers... |
| 66 |
} |
| 67 |
|
| 68 |
// 3. Window updates |
| 69 |
|
| 70 |
void DoUpdate(EventRecord *eventPtr) |
| 71 |
{ |
| 72 |
WindowPtr window = (WindowPtr)eventPtr->message; |
| 73 |
|
| 74 |
BeginUpdate(window); |
| 75 |
|
| 76 |
DrawPopUp(gPopup); // <--- |
| 77 |
|
| 78 |
EndUpdate(window); |
| 79 |
} |