+#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;
+ PenState savestate;
+
+ switch (msg) {
+ case drawCntl:
+ if ((*control)->contrlVis) {
+ rect = (*control)->contrlRect;
+ GetPenState(&savestate);
+ PenNormal();
+ PenSize(3, 3);
+ if ((*control)->contrlHilite == kControlInactivePart)
+ PenPat(&qd.gray);
+ oval = (rect.bottom - rect.top) / 2 + 2;
+ FrameRoundRect(&rect, oval, oval);
+ SetPenState(&savestate);
+ }
+ 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_listbox(struct macctrls *mcs, WindowPtr window,
+ struct mac_layoutstate *curstate,
+ union control *ctrl)
+{
+ union macctrl *mc = snew(union macctrl);
+ Rect bounds;
+ Size olen;
+
+ /* XXX Use label */
+ 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 + 16 * ctrl->listbox.height + 2;
+
+ if (mac_gestalts.apprvers >= 0x100) {
+ InsetRect(&bounds, 3, 3);
+ mc->listbox.tbctrl = NewControl(window, &bounds, NULL, FALSE,
+ ldes_Default, 0, 0,
+ kControlListBoxProc, (long)mc);
+ if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
+ kControlListBoxListHandleTag,
+ sizeof(mc->listbox.list), &mc->listbox.list,
+ &olen) != noErr) {
+ DisposeControl(mc->listbox.tbctrl);
+ sfree(mc);
+ return;
+ }
+ }
+#if !TARGET_API_MAC_CARBON
+ else {
+ InsetRect(&bounds, -3, -3);
+ mc->listbox.tbctrl = NewControl(window, &bounds, NULL, FALSE,
+ 0, 0, 0,
+ SYS7_LISTBOX_PROC, (long)mc);
+ mc->listbox.list = (ListHandle)(*mc->listbox.tbctrl)->contrlData;
+ (*mc->listbox.list)->refCon = (long)mc;
+ }
+#endif
+ if (!ctrl->listbox.multisel) {
+#if TARGET_API_MAC_CARBON
+ SetListSelectionFlags(mc->listbox.list, lOnlyOne);
+#else
+ (*mc->listbox.list)->selFlags = lOnlyOne;
+#endif
+ }
+ add234(mcs->byctrl, mc);
+ curstate->pos.v += 6 + 16 * ctrl->listbox.height + 2;
+ mc->generic.next = mcs->panels[curstate->panelnum];
+ mcs->panels[curstate->panelnum] = mc;
+ ctrlevent(mcs, mc, EVENT_REFRESH);
+#if TARGET_API_MAC_CARBON
+ HideControl(GetListVerticalScrollBar(mc->listbox.list));
+#else
+ HideControl((*mc->listbox.list)->vScroll);
+#endif
+}
+
+#if !TARGET_API_MAC_CARBON
+static pascal SInt32 macctrl_sys7_listbox_cdef(SInt16 variant,
+ ControlRef control,
+ ControlDefProcMessage msg,
+ SInt32 param)
+{
+ RgnHandle rgn;
+ Rect rect;
+ ListHandle list;
+ long ssfs;
+ Point mouse;
+ ListBounds bounds;
+ Point csize;
+ short savefont;
+ short savesize;
+ GrafPtr curport;
+
+ switch (msg) {
+ case initCntl:
+ rect = (*control)->contrlRect;
+ InsetRect(&rect, 4, 4);
+ rect.right -= 15; /* scroll bar */
+ bounds.top = bounds.bottom = bounds.left = 0;
+ bounds.right = 1;
+ csize.h = csize.v = 0;
+ GetPort(&curport);
+ savefont = curport->txFont;
+ savesize = curport->txSize;
+ ssfs = GetScriptVariable(smSystemScript, smScriptSysFondSize);
+ TextFont(HiWord(ssfs));
+ TextSize(LoWord(ssfs));
+ list = LNew(&rect, &bounds, csize, 0, (*control)->contrlOwner,
+ TRUE, FALSE, FALSE, TRUE);
+ SetControlReference((*list)->vScroll, (long)list);
+ (*control)->contrlData = (Handle)list;
+ TextFont(savefont);
+ TextSize(savesize);
+ return noErr;
+ case dispCntl:
+ /*
+ * If the dialogue box is being destroyed, the scroll bar
+ * might have gone already. In our situation, this is the
+ * only time we destroy a control, so NULL out the scroll bar
+ * handle to prevent LDispose trying to free it.
+ */
+ list = (ListHandle)(*control)->contrlData;
+ (*list)->vScroll = NULL;
+ LDispose(list);
+ return 0;
+ case drawCntl:
+ if ((*control)->contrlVis) {
+ rect = (*control)->contrlRect;
+ /* XXX input focus highlighting? */
+ InsetRect(&rect, 3, 3);
+ PenNormal();
+ FrameRect(&rect);
+ list = (ListHandle)(*control)->contrlData;
+ LActivate((*control)->contrlHilite != kControlInactivePart, list);
+ GetPort(&curport);
+ LUpdate(curport->visRgn, list);
+ }
+ return 0;
+ case testCntl:
+ mouse.h = LoWord(param);
+ mouse.v = HiWord(param);
+ rect = (*control)->contrlRect;
+ InsetRect(&rect, 4, 4);
+ /*
+ * We deliberately exclude the scrollbar so that LClick() can see it.
+ */
+ rect.right -= 15;
+ return PtInRect(mouse, &rect) ? kControlListBoxPart : kControlNoPart;
+ 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);
+
+ 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, FALSE,
+ 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);
+}
+