X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/0a33efe12a62e0bbe703bb213933c617a6b45cde..cd3e71e8269cd02d3fd595062a7f62e6f21900cd:/mac/macctrls.c diff --git a/mac/macctrls.c b/mac/macctrls.c index 4300474e..4b6c382e 100644 --- a/mac/macctrls.c +++ b/mac/macctrls.c @@ -1,4 +1,4 @@ -/* $Id: macctrls.c,v 1.11 2003/03/24 22:41:38 ben Exp $ */ +/* $Id: macctrls.c,v 1.19 2003/03/29 20:16:51 ben Exp $ */ /* * Copyright (c) 2003 Ben Harris * All rights reserved. @@ -31,8 +31,11 @@ #include #include #include +#include #include +#include #include +#include #include #include @@ -53,6 +56,7 @@ union macctrl { struct macctrl_generic { enum { MACCTRL_TEXT, + MACCTRL_EDITBOX, MACCTRL_RADIO, MACCTRL_CHECKBOX, MACCTRL_BUTTON, @@ -62,6 +66,8 @@ union macctrl { union control *ctrl; /* Next control in this panel */ union macctrl *next; + void *privdata; + int freeprivdata; } generic; struct { struct macctrl_generic generic; @@ -69,7 +75,13 @@ union macctrl { } text; struct { struct macctrl_generic generic; + ControlRef tbctrl; + ControlRef tblabel; + } editbox; + struct { + struct macctrl_generic generic; ControlRef *tbctrls; + ControlRef tblabel; } radio; struct { struct macctrl_generic generic; @@ -107,8 +119,11 @@ struct mac_layoutstate { static void macctrl_layoutset(struct mac_layoutstate *, struct controlset *, WindowPtr, struct macctrls *); static void macctrl_switchtopanel(struct macctrls *, unsigned int); +static void macctrl_setfocus(struct macctrls *, union macctrl *); static void macctrl_text(struct macctrls *, WindowPtr, struct mac_layoutstate *, union control *); +static void macctrl_editbox(struct macctrls *, WindowPtr, + struct mac_layoutstate *, union control *); static void macctrl_radio(struct macctrls *, WindowPtr, struct mac_layoutstate *, union control *); static void macctrl_checkbox(struct macctrls *, WindowPtr, @@ -120,6 +135,8 @@ static void macctrl_popup(struct macctrls *, WindowPtr, #if !TARGET_API_MAC_CARBON static pascal SInt32 macctrl_sys7_text_cdef(SInt16, ControlRef, ControlDefProcMessage, SInt32); +static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16, ControlRef, + ControlDefProcMessage, SInt32); static pascal SInt32 macctrl_sys7_default_cdef(SInt16, ControlRef, ControlDefProcMessage, SInt32); #endif @@ -148,6 +165,8 @@ static void macctrl_init() if (inited) return; cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Text); (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_text_cdef); + cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_EditBox); + (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_editbox_cdef); cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Default); (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_default_cdef); inited = 1; @@ -200,7 +219,9 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, 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; /* Count the number of panels */ mcs->npanels = 1; for (i = 1; i < cb->nctrlsets; i++) @@ -218,7 +239,7 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, } macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs); } - macctrl_switchtopanel(mcs, 20); + macctrl_switchtopanel(mcs, 14); } static void macctrl_layoutset(struct mac_layoutstate *curstate, @@ -257,6 +278,9 @@ static void macctrl_layoutset(struct mac_layoutstate *curstate, case CTRL_TEXT: macctrl_text(mcs, window, curstate, ctrl); break; + case CTRL_EDITBOX: + macctrl_editbox(mcs, window, curstate, ctrl); + break; case CTRL_RADIO: macctrl_radio(mcs, window, curstate, ctrl); break; @@ -286,14 +310,23 @@ static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which) mcs->curpanel = which; /* Panel 0 is special and always visible. */ for (i = 1; i < mcs->npanels; i++) - for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) + for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) { +#if !TARGET_API_MAC_CARBON + if (mcs->focus == mc) + macctrl_setfocus(mcs, NULL); +#endif switch (mc->generic.type) { case MACCTRL_TEXT: hideshow(mc->text.tbctrl); break; + case MACCTRL_EDITBOX: + hideshow(mc->editbox.tbctrl); + hideshow(mc->editbox.tblabel); + break; case MACCTRL_RADIO: for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++) hideshow(mc->radio.tbctrls[j]); + hideshow(mc->radio.tblabel); break; case MACCTRL_CHECKBOX: hideshow(mc->checkbox.tbctrl); @@ -305,7 +338,45 @@ static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which) hideshow(mc->popup.tbctrl); break; } + } +} + +#if !TARGET_API_MAC_CARBON +/* + * System 7 focus manipulation + */ +static void macctrl_defocus(union macctrl *mc) +{ + + assert(mac_gestalts.apprvers < 0x100); + switch (mc->generic.type) { + case MACCTRL_EDITBOX: + TEDeactivate((TEHandle)(*mc->editbox.tbctrl)->contrlData); + break; + } +} + +static void macctrl_enfocus(union macctrl *mc) +{ + + assert(mac_gestalts.apprvers < 0x100); + switch (mc->generic.type) { + case MACCTRL_EDITBOX: + TEActivate((TEHandle)(*mc->editbox.tbctrl)->contrlData); + break; + } +} + +static void macctrl_setfocus(struct macctrls *mcs, union macctrl *mc) +{ + + if (mcs->focus != NULL) + macctrl_defocus(mcs->focus); + mcs->focus = mc; + if (mc != NULL) + macctrl_enfocus(mc); } +#endif static void macctrl_text(struct macctrls *mcs, WindowPtr window, struct mac_layoutstate *curstate, @@ -317,6 +388,7 @@ static void macctrl_text(struct macctrls *mcs, WindowPtr window, fprintf(stderr, " label = %s\n", ctrl->text.label); mc->generic.type = MACCTRL_TEXT; mc->generic.ctrl = ctrl; + mc->generic.privdata = NULL; bounds.left = curstate->pos.h; bounds.right = bounds.left + curstate->width; bounds.top = curstate->pos.v; @@ -381,6 +453,125 @@ static pascal SInt32 macctrl_sys7_text_cdef(SInt16 variant, ControlRef control, } #endif +static void macctrl_editbox(struct macctrls *mcs, WindowPtr window, + struct mac_layoutstate *curstate, + union control *ctrl) +{ + union macctrl *mc = smalloc(sizeof *mc); + Rect lbounds, bounds; + + fprintf(stderr, " label = %s\n", ctrl->editbox.label); + fprintf(stderr, " percentwidth = %d\n", ctrl->editbox.percentwidth); + if (ctrl->editbox.password) fprintf(stderr, " password\n"); + if (ctrl->editbox.has_list) fprintf(stderr, " has list\n"); + mc->generic.type = MACCTRL_EDITBOX; + mc->generic.ctrl = ctrl; + mc->generic.privdata = NULL; + lbounds.left = curstate->pos.h; + lbounds.top = curstate->pos.v; + if (ctrl->editbox.percentwidth == 100) { + lbounds.right = lbounds.left + curstate->width; + lbounds.bottom = lbounds.top + 16; + bounds.left = curstate->pos.h; + bounds.right = bounds.left + curstate->width; + curstate->pos.v += 18; + } else { + lbounds.right = lbounds.left + + curstate->width * (100 - ctrl->editbox.percentwidth) / 100; + lbounds.bottom = lbounds.top + 22; + bounds.left = lbounds.right; + bounds.right = lbounds.left + curstate->width; + } + bounds.top = curstate->pos.v; + bounds.bottom = bounds.top + 22; + if (mac_gestalts.apprvers >= 0x100) { + mc->editbox.tblabel = NewControl(window, &lbounds, NULL, TRUE, 0, 0, 0, + kControlStaticTextProc, (long)mc); + SetControlData(mc->editbox.tblabel, kControlEntireControl, + kControlStaticTextTextTag, + strlen(ctrl->editbox.label), ctrl->editbox.label); + InsetRect(&bounds, 2, 2); + mc->editbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0, + ctrl->editbox.password ? + kControlEditTextPasswordProc : + kControlEditTextProc, (long)mc); + } else { + Str255 title; + + c2pstrcpy(title, ctrl->editbox.label); + mc->editbox.tblabel = NewControl(window, &lbounds, title, TRUE, + 0, 0, 0, SYS7_TEXT_PROC, (long)mc); + mc->editbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0, + SYS7_EDITBOX_PROC, (long)mc); + } + curstate->pos.v += 28; + add234(mcs->byctrl, mc); + 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_editbox_cdef(SInt16 variant, + ControlRef control, + ControlDefProcMessage msg, + SInt32 param) +{ + RgnHandle rgn; + Rect rect; + TEHandle te; + long ssfs; + Point mouse; + + switch (msg) { + case initCntl: + rect = (*control)->contrlRect; + InsetRect(&rect, 3, 3); /* 2 if it's 20 pixels high */ + te = TENew(&rect, &rect); + ssfs = GetScriptVariable(smSystemScript, smScriptSysFondSize); + (*te)->txSize = LoWord(ssfs); + (*te)->txFont = HiWord(ssfs); + (*control)->contrlData = (Handle)te; + return noErr; + case dispCntl: + TEDispose((TEHandle)(*control)->contrlData); + return 0; + case drawCntl: + if ((*control)->contrlVis) { + rect = (*control)->contrlRect; + PenNormal(); + FrameRect(&rect); + InsetRect(&rect, 3, 3); + TEUpdate(&rect, (TEHandle)(*control)->contrlData); + } + return 0; + case testCntl: + mouse.h = LoWord(param); + mouse.v = HiWord(param); + return + PtInRect(mouse, &(*(TEHandle)(*control)->contrlData)->viewRect) ? + kControlEditTextPart : 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_radio(struct macctrls *mcs, WindowPtr window, struct mac_layoutstate *curstate, union control *ctrl) @@ -393,9 +584,28 @@ static void macctrl_radio(struct macctrls *mcs, WindowPtr window, fprintf(stderr, " label = %s\n", ctrl->radio.label); mc->generic.type = MACCTRL_RADIO; mc->generic.ctrl = ctrl; + mc->generic.privdata = NULL; mc->radio.tbctrls = smalloc(sizeof(*mc->radio.tbctrls) * ctrl->radio.nbuttons); colwidth = (curstate->width + 13) / ctrl->radio.ncolumns; + bounds.top = curstate->pos.v; + bounds.bottom = bounds.top + 16; + bounds.left = curstate->pos.h; + bounds.right = bounds.left + curstate->width; + if (mac_gestalts.apprvers >= 0x100) { + mc->radio.tblabel = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0, + kControlStaticTextProc, (long)mc); + SetControlData(mc->radio.tblabel, kControlEntireControl, + kControlStaticTextTextTag, + strlen(ctrl->radio.label), ctrl->radio.label); + } else { + Str255 title; + + c2pstrcpy(title, ctrl->radio.label); + mc->editbox.tblabel = NewControl(window, &bounds, title, TRUE, + 0, 0, 0, SYS7_TEXT_PROC, (long)mc); + } + curstate->pos.v += 18; for (i = 0; i < ctrl->radio.nbuttons; i++) { fprintf(stderr, " button = %s\n", ctrl->radio.buttons[i]); bounds.top = curstate->pos.v - 2; @@ -429,6 +639,7 @@ static void macctrl_checkbox(struct macctrls *mcs, WindowPtr window, fprintf(stderr, " label = %s\n", ctrl->checkbox.label); mc->generic.type = MACCTRL_CHECKBOX; mc->generic.ctrl = ctrl; + mc->generic.privdata = NULL; bounds.left = curstate->pos.h; bounds.right = bounds.left + curstate->width; bounds.top = curstate->pos.v; @@ -456,6 +667,7 @@ static void macctrl_button(struct macctrls *mcs, WindowPtr window, fprintf(stderr, " is default\n"); mc->generic.type = MACCTRL_BUTTON; mc->generic.ctrl = ctrl; + mc->generic.privdata = NULL; bounds.left = curstate->pos.h; bounds.right = bounds.left + 100; /* XXX measure string */ bounds.top = curstate->pos.v; @@ -553,6 +765,7 @@ static void macctrl_popup(struct macctrls *mcs, WindowPtr window, 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 */ @@ -594,25 +807,14 @@ void macctrl_activate(WindowPtr window, EventRecord *event) int i, j; ControlPartCode state; union macctrl *mc; -#if 0 - ControlRef root; -#endif GetPort(&saveport); SetPort((GrafPtr)GetWindowPort(window)); - if (mac_gestalts.apprvers >= 0x100) { + if (mac_gestalts.apprvers >= 0x100) SetThemeWindowBackground(window, active ? kThemeBrushModelessDialogBackgroundActive : kThemeBrushModelessDialogBackgroundInactive, TRUE); -#if 0 - GetRootControl(window, &root); - if (active) - ActivateControl(root); - else - DeactivateControl(root); -#endif - } state = active ? kControlNoPart : kControlInactivePart; for (i = 0; i <= mcs->curpanel; i += mcs->curpanel) for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) @@ -620,9 +822,14 @@ void macctrl_activate(WindowPtr window, EventRecord *event) case MACCTRL_TEXT: HiliteControl(mc->text.tbctrl, state); break; + case MACCTRL_EDITBOX: + HiliteControl(mc->editbox.tbctrl, state); + HiliteControl(mc->editbox.tblabel, state); + break; case MACCTRL_RADIO: for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++) HiliteControl(mc->radio.tbctrls[j], state); + HiliteControl(mc->radio.tblabel, state); break; case MACCTRL_CHECKBOX: HiliteControl(mc->checkbox.tbctrl, state); @@ -641,11 +848,12 @@ void macctrl_click(WindowPtr window, EventRecord *event) { Point mouse; ControlHandle control; - int part; + int part, trackresult; GrafPtr saveport; union macctrl *mc; struct macctrls *mcs = mac_winctrls(window); int i; + UInt32 features; GetPort(&saveport); SetPort((GrafPtr)GetWindowPort(window)); @@ -654,12 +862,29 @@ void macctrl_click(WindowPtr window, EventRecord *event) part = FindControl(mouse, window, &control); if (control != NULL) { mc = (union macctrl *)GetControlReference(control); + if (mac_gestalts.apprvers >= 0x100) { + if (GetControlFeatures(control, &features) == noErr && + (features & kControlSupportsFocus) && + (features & kControlGetsFocusOnClick)) + SetKeyboardFocus(window, control, part); + trackresult = HandleControlClick(control, mouse, event->modifiers, + (ControlActionUPP)-1); + } else { +#if !TARGET_API_MAC_CARBON + if (mc->generic.type == MACCTRL_EDITBOX && + control == mc->editbox.tbctrl) { + TEHandle te = (TEHandle)(*control)->contrlData; + + macctrl_setfocus(mcs, mc); + TEClick(mouse, !!(event->modifiers & shiftKey), te); + goto done; + } +#endif + trackresult = TrackControl(control, mouse, (ControlActionUPP)-1); + } switch (mc->generic.type) { - case MACCTRL_POPUP: - TrackControl(control, mouse, (ControlActionUPP)-1); - ctrlevent(mcs, mc, EVENT_SELCHANGE); case MACCTRL_RADIO: - if (TrackControl(control, mouse, NULL) != 0) { + if (trackresult != 0) { for (i = 0; i < mc->generic.ctrl->radio.nbuttons; i++) if (mc->radio.tbctrls[i] == control) SetControlValue(mc->radio.tbctrls[i], @@ -671,20 +896,39 @@ void macctrl_click(WindowPtr window, EventRecord *event) } break; case MACCTRL_CHECKBOX: - if (TrackControl(control, mouse, NULL) != 0) { + if (trackresult != 0) { SetControlValue(control, !GetControlValue(control)); ctrlevent(mcs, mc, EVENT_VALCHANGE); } break; case MACCTRL_BUTTON: - if (TrackControl(control, mouse, NULL) != 0) + if (trackresult != 0) ctrlevent(mcs, mc, EVENT_ACTION); break; + case MACCTRL_POPUP: + ctrlevent(mcs, mc, EVENT_SELCHANGE); + break; } } + done: SetPort(saveport); } +void macctrl_key(WindowPtr window, EventRecord *event) +{ + ControlRef control; + struct macctrls *mcs = mac_winctrls(window); + union macctrl *mc; + + if (mac_gestalts.apprvers >= 0x100 && + GetKeyboardFocus(window, &control) == noErr && control != NULL) { + HandleControlKey(control, (event->message & keyCodeMask) >> 8, + event->message & charCodeMask, event->modifiers); + mc = (union macctrl *)GetControlReference(control); + ctrlevent(mcs, mc, EVENT_VALCHANGE); + } +} + void macctrl_update(WindowPtr window) { #if TARGET_API_MAC_CARBON @@ -748,6 +992,8 @@ void macctrl_close(WindowPtr window) * still holds a reference to it seems rude. */ while ((mc = index234(mcs->byctrl, 0)) != NULL) { + if (mc->generic.privdata != NULL && mc->generic.freeprivdata) + sfree(mc->generic.privdata); switch (mc->generic.type) { case MACCTRL_POPUP: DisposeControl(mc->popup.tbctrl); @@ -815,25 +1061,44 @@ void dlg_end(void *dlg, int value) void dlg_refresh(union control *ctrl, void *dlg) { + struct macctrls *mcs = dlg; + union macctrl *mc; + if (ctrl == NULL) + return; /* FIXME */ + mc = findbyctrl(mcs, ctrl); + assert(mc != NULL); + ctrlevent(mcs, mc, EVENT_REFRESH); }; void *dlg_get_privdata(union control *ctrl, void *dlg) { + struct macctrls *mcs = dlg; + union macctrl *mc = findbyctrl(mcs, ctrl); - return NULL; + assert(mc != NULL); + return mc->generic.privdata; } void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr) { + struct macctrls *mcs = dlg; + union macctrl *mc = findbyctrl(mcs, ctrl); - fatalbox("dlg_set_privdata"); + assert(mc != NULL); + mc->generic.privdata = ptr; + mc->generic.freeprivdata = FALSE; } void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size) { + struct macctrls *mcs = dlg; + union macctrl *mc = findbyctrl(mcs, ctrl); - fatalbox("dlg_alloc_privdata"); + assert(mc != NULL); + mc->generic.privdata = smalloc(size); + mc->generic.freeprivdata = TRUE; + return mc->generic.privdata; } @@ -906,13 +1171,60 @@ int dlg_checkbox_get(union control *ctrl, void *dlg) void dlg_editbox_set(union control *ctrl, void *dlg, char const *text) { + struct macctrls *mcs = dlg; + union macctrl *mc = findbyctrl(mcs, ctrl); + GrafPtr saveport; -}; + assert(mc != NULL); + assert(mc->generic.type == MACCTRL_EDITBOX); + GetPort(&saveport); + SetPort((GrafPtr)(GetWindowPort(mcs->window))); + if (mac_gestalts.apprvers >= 0x100) + SetControlData(mc->editbox.tbctrl, kControlEntireControl, + ctrl->editbox.password ? + kControlEditTextPasswordTag : + kControlEditTextTextTag, + strlen(text), text); +#if !TARGET_API_MAC_CARBON + else + TESetText(text, strlen(text), + (TEHandle)(*mc->editbox.tbctrl)->contrlData); +#endif + DrawOneControl(mc->editbox.tbctrl); + SetPort(saveport); +} void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length) { + struct macctrls *mcs = dlg; + union macctrl *mc = findbyctrl(mcs, ctrl); + Size olen; -}; + assert(mc != NULL); + assert(mc->generic.type == MACCTRL_EDITBOX); + if (mac_gestalts.apprvers >= 0x100) { + if (GetControlData(mc->editbox.tbctrl, kControlEntireControl, + ctrl->editbox.password ? + kControlEditTextPasswordTag : + kControlEditTextTextTag, + length - 1, buffer, &olen) != noErr) + olen = 0; + if (olen > length - 1) + olen = length - 1; + } +#if !TARGET_API_MAC_CARBON + else { + TEHandle te = (TEHandle)(*mc->editbox.tbctrl)->contrlData; + + olen = (*te)->teLength; + if (olen > length - 1) + olen = length - 1; + memcpy(buffer, *(*te)->hText, olen); + } +#endif + buffer[olen] = '\0'; + fprintf(stderr, "dlg_editbox_get: %s\n", buffer); +} /* @@ -927,13 +1239,13 @@ static void dlg_macpopup_clear(union control *ctrl, void *dlg) unsigned int i, n; fprintf(stderr, " popup_clear\n"); - n = CountMItems(menu); + n = CountMenuItems(menu); for (i = 0; i < n; i++) DeleteMenuItem(menu, n - i); mc->popup.nids = 0; sfree(mc->popup.ids); mc->popup.ids = NULL; - SetControlMaximum(mc->popup.tbctrl, CountMItems(menu)); + SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); } void dlg_listbox_clear(union control *ctrl, void *dlg) @@ -954,7 +1266,7 @@ static void dlg_macpopup_del(union control *ctrl, void *dlg, int index) if (mc->popup.ids != NULL) memcpy(mc->popup.ids + index, mc->popup.ids + index + 1, (mc->popup.nids - index - 1) * sizeof(*mc->popup.ids)); - SetControlMaximum(mc->popup.tbctrl, CountMItems(menu)); + SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); } void dlg_listbox_del(union control *ctrl, void *dlg, int index) @@ -975,8 +1287,8 @@ static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text) assert(text[0] != '\0'); c2pstrcpy(itemstring, text); AppendMenu(menu, "\pdummy"); - SetMenuItemText(menu, CountMItems(menu), itemstring); - SetControlMaximum(mc->popup.tbctrl, CountMItems(menu)); + SetMenuItemText(menu, CountMenuItems(menu), itemstring); + SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); } void dlg_listbox_add(union control *ctrl, void *dlg, char const *text) @@ -986,8 +1298,8 @@ void dlg_listbox_add(union control *ctrl, void *dlg, char const *text) dlg_macpopup_add(ctrl, dlg, text); } -static void dlg_macpopup_addwithindex(union control *ctrl, void *dlg, - char const *text, int id) +static void dlg_macpopup_addwithid(union control *ctrl, void *dlg, + char const *text, int id) { struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); @@ -996,7 +1308,7 @@ static void dlg_macpopup_addwithindex(union control *ctrl, void *dlg, fprintf(stderr, " popup_addwthindex %s, %d\n", text, id); dlg_macpopup_add(ctrl, dlg, text); - index = CountMItems(menu) - 1; + index = CountMenuItems(menu) - 1; if (mc->popup.nids <= index) { mc->popup.nids = index + 1; mc->popup.ids = srealloc(mc->popup.ids, @@ -1005,12 +1317,12 @@ static void dlg_macpopup_addwithindex(union control *ctrl, void *dlg, mc->popup.ids[index] = id; } -void dlg_listbox_addwithindex(union control *ctrl, void *dlg, - char const *text, int id) +void dlg_listbox_addwithid(union control *ctrl, void *dlg, + char const *text, int id) { if (ctrl->listbox.height == 0) - dlg_macpopup_addwithindex(ctrl, dlg, text, id); + dlg_macpopup_addwithid(ctrl, dlg, text, id); } int dlg_listbox_getid(union control *ctrl, void *dlg, int index) @@ -1068,8 +1380,7 @@ void dlg_text_set(union control *ctrl, void *dlg, char const *text) assert(mc != NULL); if (mac_gestalts.apprvers >= 0x100) SetControlData(mc->text.tbctrl, kControlEntireControl, - kControlStaticTextTextTag, - strlen(ctrl->text.label), ctrl->text.label); + kControlStaticTextTextTag, strlen(text), text); else { c2pstrcpy(title, text); SetControlTitle(mc->text.tbctrl, title);