X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/135c0f1a76a838ba8c3cda926afdfb9fc57e6a97..08a58231abed9e9ae14f0bbfd68a588ba327bdd5:/mac/macctrls.c diff --git a/mac/macctrls.c b/mac/macctrls.c index 201b4c51..b4e3c7d0 100644 --- a/mac/macctrls.c +++ b/mac/macctrls.c @@ -1,4 +1,4 @@ -/* $Id: macctrls.c,v 1.28 2003/04/05 17:19:38 ben Exp $ */ +/* $Id: macctrls.c,v 1.38 2003/04/14 23:28:58 ben Exp $ */ /* * Copyright (c) 2003 Ben Harris * All rights reserved. @@ -27,9 +27,11 @@ #include #include +#include #include #include #include +#include #include #include #include @@ -61,6 +63,7 @@ union macctrl { MACCTRL_RADIO, MACCTRL_CHECKBOX, MACCTRL_BUTTON, + MACCTRL_LISTBOX, MACCTRL_POPUP } type; /* Template from which this was generated */ @@ -91,10 +94,18 @@ union macctrl { struct { struct macctrl_generic generic; ControlRef tbctrl; + ControlRef tbring; } button; struct { struct macctrl_generic generic; ControlRef tbctrl; + ListHandle list; + unsigned int nids; + int *ids; + } listbox; + struct { + struct macctrl_generic generic; + ControlRef tbctrl; MenuRef menu; int menuid; unsigned int nids; @@ -131,6 +142,8 @@ static void macctrl_checkbox(struct macctrls *, WindowPtr, struct mac_layoutstate *, union control *); static void macctrl_button(struct macctrls *, WindowPtr, struct mac_layoutstate *, union control *); +static void macctrl_listbox(struct macctrls *, WindowPtr, + struct mac_layoutstate *, union control *); static void macctrl_popup(struct macctrls *, WindowPtr, struct mac_layoutstate *, union control *); #if !TARGET_API_MAC_CARBON @@ -138,6 +151,8 @@ static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16, ControlRef, ControlDefProcMessage, SInt32); static pascal SInt32 macctrl_sys7_default_cdef(SInt16, ControlRef, ControlDefProcMessage, SInt32); +static pascal SInt32 macctrl_sys7_listbox_cdef(SInt16, ControlRef, + ControlDefProcMessage, SInt32); #endif #if !TARGET_API_MAC_CARBON @@ -166,6 +181,8 @@ static void macctrl_init() (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_editbox_cdef); cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Default); (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_default_cdef); + cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_ListBox); + (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_listbox_cdef); inited = 1; #endif } @@ -197,6 +214,17 @@ static int macctrl_cmp_byctrl_find(void *av, void *bv) return 0; } +static union control panellist; + +static void panellist_handler(union control *ctrl, void *dlg, void *data, + int event) +{ + struct macctrls *mcs = dlg; + + if (event == EVENT_SELCHANGE) + macctrl_switchtopanel(mcs, dlg_listbox_index(ctrl, dlg) + 1); +} + void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, struct macctrls *mcs) { @@ -206,16 +234,13 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, Rect rect; macctrl_init(); + if (mac_gestalts.apprvers >= 0x100) + CreateRootControl(window, &root); #if TARGET_API_MAC_CARBON GetPortBounds(GetWindowPort(window), &rect); #else rect = window->portRect; #endif - curstate.pos.h = rect.left + 13; - curstate.pos.v = rect.bottom - 33; - curstate.width = rect.right - rect.left - (13 * 2); - if (mac_gestalts.apprvers >= 0x100) - CreateRootControl(window, &root); mcs->window = window; mcs->byctrl = newtree234(macctrl_cmp_byctrl); mcs->focus = NULL; @@ -229,17 +254,31 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, mcs->panels = snewn(mcs->npanels, union macctrl *); memset(mcs->panels, 0, sizeof(*mcs->panels) * mcs->npanels); curstate.panelnum = 0; + + curstate.pos.h = rect.left + 13; + curstate.pos.v = rect.top + 13; + curstate.width = 160; + panellist.listbox.type = CTRL_LISTBOX; + panellist.listbox.handler = &panellist_handler; + panellist.listbox.height = 20; + panellist.listbox.percentwidth = 100; + macctrl_listbox(mcs, window, &curstate, &panellist); + + curstate.pos.h = rect.left + 13 + 160 + 13; + curstate.pos.v = rect.bottom - 33; + curstate.width = rect.right - (rect.left + 13 + 160) - (13 * 2); for (i = 0; i < cb->nctrlsets; i++) { if (i > 0 && strcmp(cb->ctrlsets[i]->pathname, cb->ctrlsets[i-1]->pathname)) { curstate.pos.v = rect.top + 13; curstate.panelnum++; assert(curstate.panelnum < mcs->npanels); + dlg_listbox_add(&panellist, mcs, cb->ctrlsets[i]->pathname); } macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs); } macctrl_switchtopanel(mcs, 1); - /* 14 = proxies, 20 = SSH bugs */ + /* 14 = proxies, 19 = portfwd, 20 = SSH bugs */ } #define MAXCOLS 16 @@ -324,6 +363,8 @@ static void macctrl_layoutset(struct mac_layoutstate *curstate, case CTRL_LISTBOX: if (ctrl->listbox.height == 0) macctrl_popup(mcs, window, &cols[colstart], ctrl); + else + macctrl_listbox(mcs, window, &cols[colstart], ctrl); break; } } @@ -370,6 +411,18 @@ static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which) case MACCTRL_BUTTON: hideshow(mc->button.tbctrl); break; + case MACCTRL_LISTBOX: + hideshow(mc->listbox.tbctrl); + /* + * At least under Mac OS 8.1, hiding a list box + * doesn't hide its scroll bars. + */ +#if TARGET_API_MAC_CARBON + hideshow(GetListVerticalScrollBar(mc->listbox.list)); +#else + hideshow((*mc->listbox.list)->vScroll); +#endif + break; case MACCTRL_POPUP: hideshow(mc->popup.tbctrl); break; @@ -406,6 +459,8 @@ static void macctrl_enfocus(union macctrl *mc) static void macctrl_setfocus(struct macctrls *mcs, union macctrl *mc) { + if (mcs->focus == mc) + return; if (mcs->focus != NULL) macctrl_defocus(mcs->focus); mcs->focus = mc; @@ -569,6 +624,7 @@ static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16 variant, FrameRect(&rect); InsetRect(&rect, 3, 3); } + EraseRect(&rect); (*(TEHandle)(*control)->contrlData)->viewRect = rect; TEUpdate(&rect, (TEHandle)(*control)->contrlData); } @@ -714,6 +770,7 @@ static void macctrl_button(struct macctrls *mcs, WindowPtr window, c2pstrcpy(title, ctrl->button.label); mc->button.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1, pushButProc, (long)mc); + mc->button.tbring = NULL; if (mac_gestalts.apprvers >= 0x100) { Boolean isdefault = ctrl->button.isdefault; @@ -722,8 +779,8 @@ static void macctrl_button(struct macctrls *mcs, WindowPtr window, sizeof(isdefault), &isdefault); } else if (ctrl->button.isdefault) { InsetRect(&bounds, -4, -4); - NewControl(window, &bounds, title, TRUE, 0, 0, 1, - SYS7_DEFAULT_PROC, (long)mc); + mc->button.tbring = NewControl(window, &bounds, title, TRUE, 0, 0, 1, + SYS7_DEFAULT_PROC, (long)mc); } if (mac_gestalts.apprvers >= 0x110) { Boolean iscancel = ctrl->button.iscancel; @@ -751,17 +808,181 @@ static pascal SInt32 macctrl_sys7_default_cdef(SInt16 variant, 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; + + 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 + 16 * ctrl->listbox.height + 2; + + if (mac_gestalts.apprvers >= 0x100) { + InsetRect(&bounds, 3, 3); + mc->listbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, + 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, TRUE, + 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 +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); @@ -882,6 +1103,11 @@ void macctrl_activate(WindowPtr window, EventRecord *event) break; case MACCTRL_BUTTON: HiliteControl(mc->button.tbctrl, state); + if (mc->button.tbring != NULL) + HiliteControl(mc->button.tbring, state); + break; + case MACCTRL_LISTBOX: + HiliteControl(mc->listbox.tbctrl, state); break; case MACCTRL_POPUP: HiliteControl(mc->popup.tbctrl, state); @@ -902,7 +1128,7 @@ void macctrl_activate(WindowPtr window, EventRecord *event) void macctrl_click(WindowPtr window, EventRecord *event) { Point mouse; - ControlHandle control; + ControlHandle control, oldfocus; int part, trackresult; GrafPtr saveport; union macctrl *mc; @@ -916,11 +1142,27 @@ void macctrl_click(WindowPtr window, EventRecord *event) GlobalToLocal(&mouse); part = FindControl(mouse, window, &control); if (control != NULL) { - mc = (union macctrl *)GetControlReference(control); +#if !TARGET_API_MAC_CARBON + /* + * Special magic for scroll bars in list boxes, whose refcon + * is the list. + */ + if (part == kControlUpButtonPart || part == kControlDownButtonPart || + part == kControlPageUpPart || part == kControlPageDownPart || + part == kControlIndicatorPart) + mc = (union macctrl *) + (*(ListHandle)GetControlReference(control))->refCon; + else +#endif + mc = (union macctrl *)GetControlReference(control); + fprintf(stderr, "control = %p, part = %d, mc = %p\n", + control, part, mc); if (mac_gestalts.apprvers >= 0x100) { if (GetControlFeatures(control, &features) == noErr && (features & kControlSupportsFocus) && - (features & kControlGetsFocusOnClick)) + (features & kControlGetsFocusOnClick) && + GetKeyboardFocus(window, &oldfocus) == noErr && + control != oldfocus) SetKeyboardFocus(window, control, part); trackresult = HandleControlClick(control, mouse, event->modifiers, (ControlActionUPP)-1); @@ -934,6 +1176,19 @@ void macctrl_click(WindowPtr window, EventRecord *event) TEClick(mouse, !!(event->modifiers & shiftKey), te); goto done; } + if (mc->generic.type == MACCTRL_LISTBOX && + (control == mc->listbox.tbctrl || + control == (*mc->listbox.list)->vScroll)) { + + fprintf(stderr, "list = %p\n", mc->listbox.list); + macctrl_setfocus(mcs, mc); + if (LClick(mouse, event->modifiers, mc->listbox.list)) + /* double-click */ + ctrlevent(mcs, mc, EVENT_ACTION); + else + ctrlevent(mcs, mc, EVENT_SELCHANGE); + goto done; + } #endif trackresult = TrackControl(control, mouse, (ControlActionUPP)-1); } @@ -960,6 +1215,10 @@ void macctrl_click(WindowPtr window, EventRecord *event) if (trackresult != 0) ctrlevent(mcs, mc, EVENT_ACTION); break; + case MACCTRL_LISTBOX: + /* FIXME spot double-click */ + ctrlevent(mcs, mc, EVENT_SELCHANGE); + break; case MACCTRL_POPUP: ctrlevent(mcs, mc, EVENT_SELCHANGE); break; @@ -1007,7 +1266,14 @@ void macctrl_key(WindowPtr window, EventRecord *event) HandleControlKey(control, (event->message & keyCodeMask) >> 8, event->message & charCodeMask, event->modifiers); mc = (union macctrl *)GetControlReference(control); - ctrlevent(mcs, mc, EVENT_VALCHANGE); + switch (mc->generic.type) { + case MACCTRL_LISTBOX: + ctrlevent(mcs, mc, EVENT_SELCHANGE); + break; + default: + ctrlevent(mcs, mc, EVENT_VALCHANGE); + break; + } } } #if !TARGET_API_MAC_CARBON @@ -1214,7 +1480,7 @@ void dlg_radiobutton_set(union control *ctrl, void *dlg, int whichbutton) union macctrl *mc = findbyctrl(mcs, ctrl); int i; - assert(mc != NULL); + if (mc == NULL) return; for (i = 0; i < ctrl->radio.nbuttons; i++) { if (i == whichbutton) SetControlValue(mc->radio.tbctrls[i], @@ -1251,7 +1517,7 @@ void dlg_checkbox_set(union control *ctrl, void *dlg, int checked) struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); - assert(mc != NULL); + if (mc == NULL) return; SetControlValue(mc->checkbox.tbctrl, checked ? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue); @@ -1277,7 +1543,7 @@ void dlg_editbox_set(union control *ctrl, void *dlg, char const *text) union macctrl *mc = findbyctrl(mcs, ctrl); GrafPtr saveport; - assert(mc != NULL); + if (mc == NULL) return; assert(mc->generic.type == MACCTRL_EDITBOX); GetPort(&saveport); SetPort((GrafPtr)(GetWindowPort(mcs->window))); @@ -1340,6 +1606,7 @@ static void dlg_macpopup_clear(union control *ctrl, void *dlg) MenuRef menu = mc->popup.menu; unsigned int i, n; + if (mc == NULL) return; fprintf(stderr, " popup_clear\n"); n = CountMenuItems(menu); for (i = 0; i < n; i++) @@ -1350,11 +1617,31 @@ static void dlg_macpopup_clear(union control *ctrl, void *dlg) SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); } +static void dlg_maclist_clear(union control *ctrl, void *dlg) +{ + struct macctrls *mcs = dlg; + union macctrl *mc = findbyctrl(mcs, ctrl); + + if (mc == NULL) return; + fprintf(stderr, " maclist_clear\n"); + LDelRow(0, 0, mc->listbox.list); + mc->listbox.nids = 0; + sfree(mc->listbox.ids); + mc->listbox.ids = NULL; + DrawOneControl(mc->listbox.tbctrl); +} + void dlg_listbox_clear(union control *ctrl, void *dlg) { - if (ctrl->listbox.height == 0) - dlg_macpopup_clear(ctrl, dlg); + switch (ctrl->generic.type) { + case CTRL_LISTBOX: + if (ctrl->listbox.height == 0) + dlg_macpopup_clear(ctrl, dlg); + else + dlg_maclist_clear(ctrl, dlg); + break; + } } static void dlg_macpopup_del(union control *ctrl, void *dlg, int index) @@ -1363,6 +1650,7 @@ static void dlg_macpopup_del(union control *ctrl, void *dlg, int index) union macctrl *mc = findbyctrl(mcs, ctrl); MenuRef menu = mc->popup.menu; + if (mc == NULL) return; fprintf(stderr, " popup_del %d\n", index); DeleteMenuItem(menu, index + 1); if (mc->popup.ids != NULL) @@ -1371,11 +1659,31 @@ static void dlg_macpopup_del(union control *ctrl, void *dlg, int index) SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); } +static void dlg_maclist_del(union control *ctrl, void *dlg, int index) +{ + struct macctrls *mcs = dlg; + union macctrl *mc = findbyctrl(mcs, ctrl); + + if (mc == NULL) return; + fprintf(stderr, " maclist_del %d\n", index); + LDelRow(1, index, mc->listbox.list); + if (mc->listbox.ids != NULL) + memcpy(mc->listbox.ids + index, mc->listbox.ids + index + 1, + (mc->listbox.nids - index - 1) * sizeof(*mc->listbox.ids)); + DrawOneControl(mc->listbox.tbctrl); +} + void dlg_listbox_del(union control *ctrl, void *dlg, int index) { - if (ctrl->listbox.height == 0) - dlg_macpopup_del(ctrl, dlg, index); + switch (ctrl->generic.type) { + case CTRL_LISTBOX: + if (ctrl->listbox.height == 0) + dlg_macpopup_del(ctrl, dlg, index); + else + dlg_maclist_del(ctrl, dlg, index); + break; + } } static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text) @@ -1385,6 +1693,7 @@ static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text) MenuRef menu = mc->popup.menu; Str255 itemstring; + if (mc == NULL) return; fprintf(stderr, " popup_add %s\n", text); assert(text[0] != '\0'); c2pstrcpy(itemstring, text); @@ -1393,11 +1702,38 @@ static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text) SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); } + +static void dlg_maclist_add(union control *ctrl, void *dlg, char const *text) +{ + struct macctrls *mcs = dlg; + union macctrl *mc = findbyctrl(mcs, ctrl); + ListBounds bounds; + Cell cell = { 0, 0 }; + + if (mc == NULL) return; + fprintf(stderr, " maclist_add %s\n", text); +#if TARGET_API_MAC_CARBON + GetListDataBounds(mc->listbox.list, &bounds); +#else + bounds = (*mc->listbox.list)->dataBounds; +#endif + cell.v = bounds.bottom; + LAddRow(1, cell.v, mc->listbox.list); + LSetCell(text, strlen(text), cell, mc->listbox.list); + DrawOneControl(mc->listbox.tbctrl); +} + void dlg_listbox_add(union control *ctrl, void *dlg, char const *text) { - if (ctrl->listbox.height == 0) - dlg_macpopup_add(ctrl, dlg, text); + switch (ctrl->generic.type) { + case CTRL_LISTBOX: + if (ctrl->listbox.height == 0) + dlg_macpopup_add(ctrl, dlg, text); + else + dlg_maclist_add(ctrl, dlg, text); + break; + } } static void dlg_macpopup_addwithid(union control *ctrl, void *dlg, @@ -1408,7 +1744,8 @@ static void dlg_macpopup_addwithid(union control *ctrl, void *dlg, MenuRef menu = mc->popup.menu; unsigned int index; - fprintf(stderr, " popup_addwthindex %s, %d\n", text, id); + if (mc == NULL) return; + fprintf(stderr, " popup_addwthid %s, %d\n", text, id); dlg_macpopup_add(ctrl, dlg, text); index = CountMenuItems(menu) - 1; if (mc->popup.nids <= index) { @@ -1418,12 +1755,42 @@ static void dlg_macpopup_addwithid(union control *ctrl, void *dlg, mc->popup.ids[index] = id; } +static void dlg_maclist_addwithid(union control *ctrl, void *dlg, + char const *text, int id) +{ + struct macctrls *mcs = dlg; + union macctrl *mc = findbyctrl(mcs, ctrl); + ListBounds bounds; + int index; + + if (mc == NULL) return; + fprintf(stderr, " maclist_addwithid %s %d\n", text, id); + dlg_maclist_add(ctrl, dlg, text); +#if TARGET_API_MAC_CARBON + GetListDataBounds(mc->listbox.list, &bounds); +#else + bounds = (*mc->listbox.list)->dataBounds; +#endif + index = bounds.bottom; + if (mc->listbox.nids <= index) { + mc->listbox.nids = index + 1; + mc->listbox.ids = sresize(mc->listbox.ids, mc->listbox.nids, int); + } + mc->listbox.ids[index] = id; +} + void dlg_listbox_addwithid(union control *ctrl, void *dlg, char const *text, int id) { - if (ctrl->listbox.height == 0) - dlg_macpopup_addwithid(ctrl, dlg, text, id); + switch (ctrl->generic.type) { + case CTRL_LISTBOX: + if (ctrl->listbox.height == 0) + dlg_macpopup_addwithid(ctrl, dlg, text, id); + else + dlg_maclist_addwithid(ctrl, dlg, text, id); + break; + } } int dlg_listbox_getid(union control *ctrl, void *dlg, int index) @@ -1431,41 +1798,73 @@ int dlg_listbox_getid(union control *ctrl, void *dlg, int index) struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); - if (ctrl->listbox.height == 0) { - assert(mc->popup.ids != NULL && mc->popup.nids > index); - return mc->popup.ids[index]; + assert(mc != NULL); + switch (ctrl->generic.type) { + case CTRL_LISTBOX: + if (ctrl->listbox.height == 0) { + assert(mc->popup.ids != NULL && mc->popup.nids > index); + return mc->popup.ids[index]; + } else { + assert(mc->listbox.ids != NULL && mc->listbox.nids > index); + return mc->listbox.ids[index]; + } } - return 0; + return -1; } int dlg_listbox_index(union control *ctrl, void *dlg) { struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); + Cell cell = { 0, 0 }; - if (ctrl->listbox.height == 0) - return GetControlValue(mc->popup.tbctrl) - 1; - return 0; -}; + assert(mc != NULL); + switch (ctrl->generic.type) { + case CTRL_LISTBOX: + if (ctrl->listbox.height == 0) + return GetControlValue(mc->popup.tbctrl) - 1; + else { + if (LGetSelect(TRUE, &cell, mc->listbox.list)) + return cell.v; + else + return -1; + } + } + return -1; +} int dlg_listbox_issel(union control *ctrl, void *dlg, int index) { struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); + Cell cell = { 0, 0 }; - if (ctrl->listbox.height == 0) - return GetControlValue(mc->popup.tbctrl) - 1 == index; - return 0; -}; + assert(mc != NULL); + switch (ctrl->generic.type) { + case CTRL_LISTBOX: + if (ctrl->listbox.height == 0) + return GetControlValue(mc->popup.tbctrl) - 1 == index; + else { + cell.v = index; + return LGetSelect(FALSE, &cell, mc->listbox.list); + } + } + return FALSE; +} void dlg_listbox_select(union control *ctrl, void *dlg, int index) { struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); - if (ctrl->listbox.height == 0) - SetControlValue(mc->popup.tbctrl, index + 1); -}; + if (mc == NULL) return; + switch (ctrl->generic.type) { + case CTRL_LISTBOX: + if (ctrl->listbox.height == 0) + SetControlValue(mc->popup.tbctrl, index + 1); + break; + } +} /* @@ -1477,7 +1876,7 @@ void dlg_text_set(union control *ctrl, void *dlg, char const *text) struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); - assert(mc != NULL); + if (mc == NULL) return; if (mac_gestalts.apprvers >= 0x100) SetControlData(mc->text.tbctrl, kControlEntireControl, kControlStaticTextTextTag, strlen(text), text); @@ -1549,14 +1948,34 @@ void printer_finish_enum(printer_enum *pe) void dlg_coloursel_start(union control *ctrl, void *dlg, int r, int g, int b) { - + struct macctrls *mcs = dlg; + union macctrl *mc = findbyctrl(mcs, ctrl); + Point where = {-1, -1}; /* Screen with greatest colour depth */ + RGBColor incolour; + + if (HAVE_COLOR_QD()) { + incolour.red = r * 0x0101; + incolour.green = g * 0x0101; + incolour.blue = b * 0x0101; + mcs->gotcolour = GetColor(where, "\pModify Colour:", &incolour, + &mcs->thecolour); + ctrlevent(mcs, mc, EVENT_CALLBACK); + } else + dlg_beep(dlg); } int dlg_coloursel_results(union control *ctrl, void *dlg, int *r, int *g, int *b) { + struct macctrls *mcs = dlg; - return 0; + if (mcs->gotcolour) { + *r = mcs->thecolour.red >> 8; + *g = mcs->thecolour.green >> 8; + *b = mcs->thecolour.blue >> 8; + return 1; + } else + return 0; } /*