+static void macctrl_listbox(struct macctrls *mcs, WindowPtr window,
+ struct mac_layoutstate *curstate,
+ union control *ctrl)
+{
+ union macctrl *mc = snew(union macctrl);
+ Rect bounds;
+ ListHandle list;
+ Size olen;
+
+ if (mac_gestalts.apprvers < 0x100)
+ return;
+ if (ctrl->listbox.label != NULL)
+ fprintf(stderr, " label = %s\n", ctrl->listbox.label);
+ fprintf(stderr, " height = %d\n", ctrl->listbox.height);
+ if (ctrl->listbox.draglist)
+ fprintf(stderr, " draglist\n");
+ if (ctrl->listbox.multisel)
+ fprintf(stderr, " multisel\n");
+ fprintf(stderr, " ncols = %d\n", ctrl->listbox.ncols);
+ assert(ctrl->listbox.percentwidth == 100);
+ mc->generic.type = MACCTRL_LISTBOX;
+ mc->generic.ctrl = ctrl;
+ mc->generic.privdata = NULL;
+ /* The list starts off empty */
+ mc->listbox.nids = 0;
+ mc->listbox.ids = NULL;
+ bounds.left = curstate->pos.h;
+ bounds.right = bounds.left + curstate->width;
+ bounds.top = curstate->pos.v;
+ bounds.bottom = bounds.top + 20 * ctrl->listbox.height;
+
+ mc->button.tbctrl = NewControl(window, &bounds, NULL, TRUE,
+ ldes_Default, 0, 0,
+ kControlListBoxProc, (long)mc);
+ if (!ctrl->listbox.multisel) {
+ if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
+ kControlListBoxListHandleTag, sizeof(list), &list,
+ &olen) != noErr)
+ return;
+#if TARGET_API_MAC_CARBON
+ SetListSelectionFlags(list, lOnlyOne);
+#else
+ (*list)->selFlags = lOnlyOne;
+#endif
+ }
+ add234(mcs->byctrl, mc);
+ curstate->pos.v += 6 + 20 * ctrl->listbox.height;
+ mc->generic.next = mcs->panels[curstate->panelnum];
+ mcs->panels[curstate->panelnum] = mc;
+ ctrlevent(mcs, mc, EVENT_REFRESH);
+}
+
+
+static void macctrl_popup(struct macctrls *mcs, WindowPtr window,
+ struct mac_layoutstate *curstate,
+ union control *ctrl)
+{
+ union macctrl *mc = snew(union macctrl);
+ Rect bounds;
+ Str255 title;
+ unsigned int labelwidth;
+ static int nextmenuid = MENU_MIN;
+ int menuid;
+ MenuRef menu;
+
+ /*
+ * <http://developer.apple.com/qa/tb/tb42.html> explains how to
+ * create a popup menu with dynamic content.
+ */
+ assert(ctrl->listbox.height == 0);
+ assert(!ctrl->listbox.draglist);
+ assert(!ctrl->listbox.multisel);
+
+ if (ctrl->listbox.label != NULL)
+ fprintf(stderr, " label = %s\n", ctrl->listbox.label);
+ fprintf(stderr, " percentwidth = %d\n", ctrl->listbox.percentwidth);
+
+ mc->generic.type = MACCTRL_POPUP;
+ mc->generic.ctrl = ctrl;
+ mc->generic.privdata = NULL;
+ c2pstrcpy(title, ctrl->button.label == NULL ? "" : ctrl->button.label);
+
+ /* Find a spare menu ID and create the menu */
+ while (GetMenuHandle(nextmenuid) != NULL)
+ if (++nextmenuid >= MENU_MAX) nextmenuid = MENU_MIN;
+ menuid = nextmenuid++;
+ menu = NewMenu(menuid, "\pdummy");
+ if (menu == NULL) return;
+ mc->popup.menu = menu;
+ mc->popup.menuid = menuid;
+ InsertMenu(menu, kInsertHierarchicalMenu);
+
+ /* The menu starts off empty */
+ mc->popup.nids = 0;
+ mc->popup.ids = NULL;
+
+ bounds.left = curstate->pos.h;
+ bounds.right = bounds.left + curstate->width;
+ bounds.top = curstate->pos.v;
+ bounds.bottom = bounds.top + 20;
+ /* XXX handle percentwidth == 100 */
+ labelwidth = curstate->width * (100 - ctrl->listbox.percentwidth) / 100;
+ mc->popup.tbctrl = NewControl(window, &bounds, title, TRUE,
+ popupTitleLeftJust, menuid, labelwidth,
+ popupMenuProc + popupFixedWidth, (long)mc);
+ add234(mcs->byctrl, mc);
+ curstate->pos.v += 26;
+ mc->generic.next = mcs->panels[curstate->panelnum];
+ mcs->panels[curstate->panelnum] = mc;
+ ctrlevent(mcs, mc, EVENT_REFRESH);
+}
+