+#if !TARGET_API_MAC_CARBON
+static pascal SInt32 macctrl_sys7_default_cdef(SInt16 variant,
+ ControlRef control,
+ ControlDefProcMessage msg,
+ SInt32 param)
+{
+ RgnHandle rgn;
+ Rect rect;
+ int oval;
+
+ switch (msg) {
+ case drawCntl:
+ if ((*control)->contrlVis) {
+ rect = (*control)->contrlRect;
+ PenNormal();
+ PenSize(3, 3);
+ oval = (rect.bottom - rect.top) / 2 + 2;
+ FrameRoundRect(&rect, oval, oval);
+ }
+ return 0;
+ case calcCRgns:
+ if (param & (1 << 31)) {
+ param &= ~(1 << 31);
+ goto calcthumbrgn;
+ }
+ /* FALLTHROUGH */
+ case calcCntlRgn:
+ rgn = (RgnHandle)param;
+ RectRgn(rgn, &(*control)->contrlRect);
+ return 0;
+ case calcThumbRgn:
+ calcthumbrgn:
+ rgn = (RgnHandle)param;
+ SetEmptyRgn(rgn);
+ return 0;
+ }
+
+ return 0;
+}
+#endif
+
+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);
+
+ 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);
+
+ /* 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);
+}
+