X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/08a58231abed9e9ae14f0bbfd68a588ba327bdd5..2b3f6c19242cf99e7c0ab6b9e8f1253f480f1cfd:/mac/macctrls.c diff --git a/mac/macctrls.c b/mac/macctrls.c index b4e3c7d0..4ce523e6 100644 --- a/mac/macctrls.c +++ b/mac/macctrls.c @@ -1,4 +1,4 @@ -/* $Id: macctrls.c,v 1.38 2003/04/14 23:28:58 ben Exp $ */ +/* $Id$ */ /* * Copyright (c) 2003 Ben Harris * All rights reserved. @@ -64,7 +64,8 @@ union macctrl { MACCTRL_CHECKBOX, MACCTRL_BUTTON, MACCTRL_LISTBOX, - MACCTRL_POPUP + MACCTRL_POPUP, + MACCTRL_GROUPBOX } type; /* Template from which this was generated */ union control *ctrl; @@ -111,10 +112,16 @@ union macctrl { unsigned int nids; int *ids; } popup; + struct { + struct macctrl_generic generic; + ControlRef tbctrl; + } groupbox; }; struct mac_layoutstate { Point pos; + Point boxpos; + char *boxname; unsigned int width; unsigned int panelnum; }; @@ -130,6 +137,7 @@ struct mac_layoutstate { static void macctrl_layoutset(struct mac_layoutstate *, struct controlset *, WindowPtr, struct macctrls *); +static void macctrl_hideshowpanel(struct macctrls *, unsigned int, int); static void macctrl_switchtopanel(struct macctrls *, unsigned int); static void macctrl_setfocus(struct macctrls *, union macctrl *); static void macctrl_text(struct macctrls *, WindowPtr, @@ -146,6 +154,8 @@ static void macctrl_listbox(struct macctrls *, WindowPtr, struct mac_layoutstate *, union control *); static void macctrl_popup(struct macctrls *, WindowPtr, struct mac_layoutstate *, union control *); +static void macctrl_groupbox(struct macctrls *, WindowPtr, + struct mac_layoutstate *, union control *); #if !TARGET_API_MAC_CARBON static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16, ControlRef, ControlDefProcMessage, SInt32); @@ -153,6 +163,8 @@ static pascal SInt32 macctrl_sys7_default_cdef(SInt16, ControlRef, ControlDefProcMessage, SInt32); static pascal SInt32 macctrl_sys7_listbox_cdef(SInt16, ControlRef, ControlDefProcMessage, SInt32); +static pascal SInt32 macctrl_sys7_groupbox_cdef(SInt16, ControlRef, + ControlDefProcMessage, SInt32); #endif #if !TARGET_API_MAC_CARBON @@ -183,6 +195,8 @@ static void macctrl_init() (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_default_cdef); cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_ListBox); (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_listbox_cdef); + cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_GroupBox); + (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_groupbox_cdef); inited = 1; #endif } @@ -221,6 +235,7 @@ static void panellist_handler(union control *ctrl, void *dlg, void *data, { struct macctrls *mcs = dlg; + /* XXX what if there's no selection? */ if (event == EVENT_SELCHANGE) macctrl_switchtopanel(mcs, dlg_listbox_index(ctrl, dlg) + 1); } @@ -246,6 +261,7 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, mcs->focus = NULL; mcs->defbutton = NULL; mcs->canbutton = NULL; + mcs->curpanel = 1; /* Count the number of panels */ mcs->npanels = 1; for (i = 1; i < cb->nctrlsets; i++) @@ -263,6 +279,7 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, panellist.listbox.height = 20; panellist.listbox.percentwidth = 100; macctrl_listbox(mcs, window, &curstate, &panellist); + /* XXX Start with panel 1 active */ curstate.pos.h = rect.left + 13 + 160 + 13; curstate.pos.v = rect.bottom - 33; @@ -278,52 +295,55 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs); } macctrl_switchtopanel(mcs, 1); + macctrl_hideshowpanel(mcs, 0, TRUE); /* 14 = proxies, 19 = portfwd, 20 = SSH bugs */ } + + #define MAXCOLS 16 static void macctrl_layoutset(struct mac_layoutstate *curstate, struct controlset *s, WindowPtr window, struct macctrls *mcs) { - unsigned int i, j, ncols, colstart; - struct mac_layoutstate cols[MAXCOLS]; + unsigned int i, j, ncols, colstart, colspan; + struct mac_layoutstate cols[MAXCOLS], pos; + + /* Start a containing box, if we have a boxname. */ + if (s->boxname && *s->boxname) { + curstate->boxpos = curstate->pos; + if (s->boxtitle) { + curstate->boxname = s->boxtitle; + curstate->pos.v += 10; /* XXX determine font height */ + } else { + curstate->boxname = NULL; + } + curstate->pos.v += 6; + curstate->pos.h += 12; + curstate->width -= 24; + } - fprintf(stderr, "--- begin set ---\n"); - fprintf(stderr, "pathname = %s\n", s->pathname); - if (s->boxname && *s->boxname) - fprintf(stderr, "boxname = %s\n", s->boxname); - if (s->boxtitle) - fprintf(stderr, "boxtitle = %s\n", s->boxtitle); + /* Draw a title, if we have one. */ + if (!s->boxname && s->boxtitle) { + union control *ctrl = snew(union control); + ctrl->generic.handler = NULL; + ctrl->text.label = dupstr(s->boxtitle); + macctrl_text(mcs, window, curstate, ctrl); + /* FIXME: should be highlighted, centred or boxed */ + } cols[0] = *curstate; ncols = 1; for (i = 0; i < s->ncontrols; i++) { union control *ctrl = s->ctrls[i]; - char const *s; colstart = COLUMN_START(ctrl->generic.column); - switch (ctrl->generic.type) { - case CTRL_TEXT: s = "text"; break; - case CTRL_EDITBOX: s = "editbox"; break; - case CTRL_RADIO: s = "radio"; break; - case CTRL_CHECKBOX: s = "checkbox"; break; - case CTRL_BUTTON: s = "button"; break; - case CTRL_LISTBOX: s = "listbox"; break; - case CTRL_COLUMNS: s = "columns"; break; - case CTRL_FILESELECT: s = "fileselect"; break; - case CTRL_FONTSELECT: s = "fontselect"; break; - case CTRL_TABDELAY: s = "tabdelay"; break; - default: s = "unknown"; break; - } - fprintf(stderr, " control: %s\n", s); - switch (ctrl->generic.type) { - case CTRL_COLUMNS: + colspan = COLUMN_SPAN(ctrl->generic.column); + if (ctrl->generic.type == CTRL_COLUMNS) { if (ctrl->columns.ncols != 1) { ncols = ctrl->columns.ncols; - fprintf(stderr, " split to %d\n", ncols); assert(ncols <= MAXCOLS); for (j = 0; j < ncols; j++) { cols[j] = cols[0]; @@ -337,97 +357,128 @@ static void macctrl_layoutset(struct mac_layoutstate *curstate, ctrl->columns.percentages[j] / 100 - 6; } } else { - fprintf(stderr, " join\n"); for (j = 0; j < ncols; j++) if (cols[j].pos.v > cols[0].pos.v) cols[0].pos.v = cols[j].pos.v; cols[0].width = curstate->width; ncols = 1; } - break; - case CTRL_TEXT: - macctrl_text(mcs, window, &cols[colstart], ctrl); - break; - case CTRL_EDITBOX: - macctrl_editbox(mcs, window, &cols[colstart], ctrl); - break; - case CTRL_RADIO: - macctrl_radio(mcs, window, &cols[colstart], ctrl); - break; - case CTRL_CHECKBOX: - macctrl_checkbox(mcs, window, &cols[colstart], ctrl); - break; - case CTRL_BUTTON: - macctrl_button(mcs, window, &cols[colstart], ctrl); - break; - case CTRL_LISTBOX: - if (ctrl->listbox.height == 0) - macctrl_popup(mcs, window, &cols[colstart], ctrl); - else - macctrl_listbox(mcs, window, &cols[colstart], ctrl); - break; + } else { + pos = cols[colstart]; + pos.width = cols[colstart + colspan - 1].width + + (cols[colstart + colspan - 1].pos.h - cols[colstart].pos.h); + + for (j = colstart; j < colstart + colspan; j++) + if (pos.pos.v < cols[j].pos.v) + pos.pos.v = cols[j].pos.v; + + switch (ctrl->generic.type) { + case CTRL_TEXT: + macctrl_text(mcs, window, &pos, ctrl); + break; + case CTRL_EDITBOX: + macctrl_editbox(mcs, window, &pos, ctrl); + break; + case CTRL_RADIO: + macctrl_radio(mcs, window, &pos, ctrl); + break; + case CTRL_CHECKBOX: + macctrl_checkbox(mcs, window, &pos, ctrl); + break; + case CTRL_BUTTON: + macctrl_button(mcs, window, &pos, ctrl); + break; + case CTRL_LISTBOX: + if (ctrl->listbox.height == 0) + macctrl_popup(mcs, window, &pos, ctrl); + else + macctrl_listbox(mcs, window, &pos, ctrl); + break; + } + for (j = colstart; j < colstart + colspan; j++) + cols[j].pos.v = pos.pos.v; } } for (j = 0; j < ncols; j++) if (cols[j].pos.v > curstate->pos.v) curstate->pos.v = cols[j].pos.v; + + if (s->boxname && *s->boxname) { + union control *ctrl = snew(union control); + /* We're coming out of a box, so set the width back */ + curstate->pos.h -= 12; + curstate->width += 24; + /* And draw the box to the original width */ + macctrl_groupbox(mcs, window, curstate, ctrl); + } } -static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which) +static void macctrl_hideshowpanel(struct macctrls *mcs, unsigned int panel, + int showit) { - unsigned int i, j; union macctrl *mc; + int j; #define hideshow(c) do { \ - if (i == which) ShowControl(c); else HideControl(c); \ + if (showit) ShowControl(c); else HideControl(c); \ } while (0) - 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[panel]; mc != NULL; mc = mc->generic.next) { #if !TARGET_API_MAC_CARBON - if (mcs->focus == mc) - macctrl_setfocus(mcs, NULL); + 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); - if (mc->editbox.tblabel != NULL) - hideshow(mc->editbox.tblabel); - break; - case MACCTRL_RADIO: - for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++) - hideshow(mc->radio.tbctrls[j]); - if (mc->radio.tblabel != NULL) - hideshow(mc->radio.tblabel); - break; - case MACCTRL_CHECKBOX: - hideshow(mc->checkbox.tbctrl); - break; - 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. - */ + switch (mc->generic.type) { + case MACCTRL_TEXT: + hideshow(mc->text.tbctrl); + break; + case MACCTRL_EDITBOX: + hideshow(mc->editbox.tbctrl); + if (mc->editbox.tblabel != NULL) + hideshow(mc->editbox.tblabel); + break; + case MACCTRL_RADIO: + for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++) + hideshow(mc->radio.tbctrls[j]); + if (mc->radio.tblabel != NULL) + hideshow(mc->radio.tblabel); + break; + case MACCTRL_CHECKBOX: + hideshow(mc->checkbox.tbctrl); + break; + case MACCTRL_BUTTON: + hideshow(mc->button.tbctrl); + if (mc->button.tbring != NULL) + hideshow(mc->button.tbring); + 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)); + hideshow(GetListVerticalScrollBar(mc->listbox.list)); #else - hideshow((*mc->listbox.list)->vScroll); + hideshow((*mc->listbox.list)->vScroll); #endif - break; - case MACCTRL_POPUP: - hideshow(mc->popup.tbctrl); - break; - } + break; + case MACCTRL_POPUP: + hideshow(mc->popup.tbctrl); + break; + case MACCTRL_GROUPBOX: + hideshow(mc->groupbox.tbctrl); + break; } + } +} + +static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which) +{ + + macctrl_hideshowpanel(mcs, mcs->curpanel, FALSE); + macctrl_hideshowpanel(mcs, which, TRUE); + mcs->curpanel = which; } #if !TARGET_API_MAC_CARBON @@ -478,7 +529,6 @@ static void macctrl_text(struct macctrls *mcs, WindowPtr window, SInt16 height; assert(ctrl->text.label != NULL); - fprintf(stderr, " label = %s\n", ctrl->text.label); mc->generic.type = MACCTRL_TEXT; mc->generic.ctrl = ctrl; mc->generic.privdata = NULL; @@ -489,7 +539,7 @@ static void macctrl_text(struct macctrls *mcs, WindowPtr window, if (mac_gestalts.apprvers >= 0x100) { Size olen; - mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0, + mc->text.tbctrl = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, kControlStaticTextProc, (long)mc); SetControlData(mc->text.tbctrl, kControlEntireControl, kControlStaticTextTextTag, @@ -502,14 +552,13 @@ static void macctrl_text(struct macctrls *mcs, WindowPtr window, else { TEHandle te; - mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0, + mc->text.tbctrl = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, SYS7_TEXT_PROC, (long)mc); te = (TEHandle)(*mc->text.tbctrl)->contrlData; TESetText(ctrl->text.label, strlen(ctrl->text.label), te); height = TEGetHeight(1, (*te)->nLines, te); } #endif - fprintf(stderr, " height = %d\n", height); SizeControl(mc->text.tbctrl, curstate->width, height); curstate->pos.v += height + 6; add234(mcs->byctrl, mc); @@ -524,11 +573,6 @@ static void macctrl_editbox(struct macctrls *mcs, WindowPtr window, union macctrl *mc = snew(union macctrl); Rect lbounds, bounds; - if (ctrl->editbox.label != NULL) - 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; @@ -555,7 +599,7 @@ static void macctrl_editbox(struct macctrls *mcs, WindowPtr window, if (ctrl->editbox.label == NULL) mc->editbox.tblabel = NULL; else { - mc->editbox.tblabel = NewControl(window, &lbounds, NULL, TRUE, + mc->editbox.tblabel = NewControl(window, &lbounds, NULL, FALSE, 0, 0, 0, kControlStaticTextProc, (long)mc); SetControlData(mc->editbox.tblabel, kControlEntireControl, @@ -563,7 +607,7 @@ static void macctrl_editbox(struct macctrls *mcs, WindowPtr window, strlen(ctrl->editbox.label), ctrl->editbox.label); } InsetRect(&bounds, 3, 3); - mc->editbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0, + mc->editbox.tbctrl = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, ctrl->editbox.password ? kControlEditTextPasswordProc : kControlEditTextProc, (long)mc); @@ -573,13 +617,13 @@ static void macctrl_editbox(struct macctrls *mcs, WindowPtr window, if (ctrl->editbox.label == NULL) mc->editbox.tblabel = NULL; else { - mc->editbox.tblabel = NewControl(window, &lbounds, NULL, TRUE, + mc->editbox.tblabel = NewControl(window, &lbounds, NULL, FALSE, 0, 0, 0, SYS7_TEXT_PROC, (long)mc); TESetText(ctrl->editbox.label, strlen(ctrl->editbox.label), (TEHandle)(*mc->editbox.tblabel)->contrlData); } - mc->editbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0, + mc->editbox.tbctrl = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, SYS7_EDITBOX_PROC, (long)mc); } #endif @@ -667,8 +711,6 @@ static void macctrl_radio(struct macctrls *mcs, WindowPtr window, Str255 title; unsigned int i, colwidth; - if (ctrl->radio.label != NULL) - fprintf(stderr, " label = %s\n", ctrl->radio.label); mc->generic.type = MACCTRL_RADIO; mc->generic.ctrl = ctrl; mc->generic.privdata = NULL; @@ -682,7 +724,7 @@ static void macctrl_radio(struct macctrls *mcs, WindowPtr window, mc->radio.tblabel = NULL; else { if (mac_gestalts.apprvers >= 0x100) { - mc->radio.tblabel = NewControl(window, &bounds, NULL, TRUE, + mc->radio.tblabel = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, kControlStaticTextProc, (long)mc); SetControlData(mc->radio.tblabel, kControlEntireControl, @@ -691,7 +733,7 @@ static void macctrl_radio(struct macctrls *mcs, WindowPtr window, } #if !TARGET_API_MAC_CARBON else { - mc->radio.tblabel = NewControl(window, &bounds, NULL, TRUE, + mc->radio.tblabel = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, SYS7_TEXT_PROC, (long)mc); TESetText(ctrl->radio.label, strlen(ctrl->radio.label), (TEHandle)(*mc->radio.tblabel)->contrlData); @@ -700,7 +742,6 @@ static void macctrl_radio(struct macctrls *mcs, WindowPtr window, 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; bounds.bottom = bounds.top + 18; bounds.left = curstate->pos.h + colwidth * (i % ctrl->radio.ncolumns); @@ -711,7 +752,7 @@ static void macctrl_radio(struct macctrls *mcs, WindowPtr window, } else bounds.right = bounds.left + colwidth - 13; c2pstrcpy(title, ctrl->radio.buttons[i]); - mc->radio.tbctrls[i] = NewControl(window, &bounds, title, TRUE, + mc->radio.tbctrls[i] = NewControl(window, &bounds, title, FALSE, 0, 0, 1, radioButProc, (long)mc); } curstate->pos.v += 4; @@ -730,7 +771,6 @@ static void macctrl_checkbox(struct macctrls *mcs, WindowPtr window, Str255 title; assert(ctrl->checkbox.label != NULL); - fprintf(stderr, " label = %s\n", ctrl->checkbox.label); mc->generic.type = MACCTRL_CHECKBOX; mc->generic.ctrl = ctrl; mc->generic.privdata = NULL; @@ -739,7 +779,7 @@ static void macctrl_checkbox(struct macctrls *mcs, WindowPtr window, bounds.top = curstate->pos.v; bounds.bottom = bounds.top + 16; c2pstrcpy(title, ctrl->checkbox.label); - mc->checkbox.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1, + mc->checkbox.tbctrl = NewControl(window, &bounds, title, FALSE, 0, 0, 1, checkBoxProc, (long)mc); add234(mcs->byctrl, mc); curstate->pos.v += 22; @@ -757,9 +797,6 @@ static void macctrl_button(struct macctrls *mcs, WindowPtr window, Str255 title; assert(ctrl->button.label != NULL); - fprintf(stderr, " label = %s\n", ctrl->button.label); - if (ctrl->button.isdefault) - fprintf(stderr, " is default\n"); mc->generic.type = MACCTRL_BUTTON; mc->generic.ctrl = ctrl; mc->generic.privdata = NULL; @@ -768,7 +805,7 @@ static void macctrl_button(struct macctrls *mcs, WindowPtr window, bounds.top = curstate->pos.v; bounds.bottom = bounds.top + 20; c2pstrcpy(title, ctrl->button.label); - mc->button.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1, + mc->button.tbctrl = NewControl(window, &bounds, title, FALSE, 0, 0, 1, pushButProc, (long)mc); mc->button.tbring = NULL; if (mac_gestalts.apprvers >= 0x100) { @@ -779,7 +816,7 @@ static void macctrl_button(struct macctrls *mcs, WindowPtr window, sizeof(isdefault), &isdefault); } else if (ctrl->button.isdefault) { InsetRect(&bounds, -4, -4); - mc->button.tbring = NewControl(window, &bounds, title, TRUE, 0, 0, 1, + mc->button.tbring = NewControl(window, &bounds, title, FALSE, 0, 0, 1, SYS7_DEFAULT_PROC, (long)mc); } if (mac_gestalts.apprvers >= 0x110) { @@ -853,14 +890,7 @@ static void macctrl_listbox(struct macctrls *mcs, WindowPtr window, 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); + /* XXX Use label */ assert(ctrl->listbox.percentwidth == 100); mc->generic.type = MACCTRL_LISTBOX; mc->generic.ctrl = ctrl; @@ -875,7 +905,7 @@ static void macctrl_listbox(struct macctrls *mcs, WindowPtr window, if (mac_gestalts.apprvers >= 0x100) { InsetRect(&bounds, 3, 3); - mc->listbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, + mc->listbox.tbctrl = NewControl(window, &bounds, NULL, FALSE, ldes_Default, 0, 0, kControlListBoxProc, (long)mc); if (GetControlData(mc->listbox.tbctrl, kControlEntireControl, @@ -890,7 +920,7 @@ static void macctrl_listbox(struct macctrls *mcs, WindowPtr window, #if !TARGET_API_MAC_CARBON else { InsetRect(&bounds, -3, -3); - mc->listbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, + mc->listbox.tbctrl = NewControl(window, &bounds, NULL, FALSE, 0, 0, 0, SYS7_LISTBOX_PROC, (long)mc); mc->listbox.list = (ListHandle)(*mc->listbox.tbctrl)->contrlData; @@ -909,6 +939,11 @@ static void macctrl_listbox(struct macctrls *mcs, WindowPtr window, 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 @@ -1004,6 +1039,48 @@ static pascal SInt32 macctrl_sys7_listbox_cdef(SInt16 variant, } #endif +#if !TARGET_API_MAC_CARBON +static pascal SInt32 macctrl_sys7_groupbox_cdef(SInt16 variant, + ControlRef control, + ControlDefProcMessage msg, + SInt32 param) +{ + RgnHandle rgn; + Rect rect; + PenState savestate; + + switch (msg) { + case drawCntl: + if ((*control)->contrlVis) { + rect = (*control)->contrlRect; + GetPenState(&savestate); + PenNormal(); + PenSize(3, 3); + PenPat(&qd.gray); + FrameRect(&rect); + 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_popup(struct macctrls *mcs, WindowPtr window, struct mac_layoutstate *curstate, union control *ctrl) @@ -1024,10 +1101,6 @@ static void macctrl_popup(struct macctrls *mcs, WindowPtr window, 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; @@ -1053,7 +1126,7 @@ static void macctrl_popup(struct macctrls *mcs, WindowPtr window, 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, + mc->popup.tbctrl = NewControl(window, &bounds, title, FALSE, popupTitleLeftJust, menuid, labelwidth, popupMenuProc + popupFixedWidth, (long)mc); add234(mcs->byctrl, mc); @@ -1063,6 +1136,39 @@ static void macctrl_popup(struct macctrls *mcs, WindowPtr window, ctrlevent(mcs, mc, EVENT_REFRESH); } +static void macctrl_groupbox(struct macctrls *mcs, WindowPtr window, + struct mac_layoutstate *curstate, + union control *ctrl) +{ + union macctrl *mc = snew (union macctrl); + Str255 ptitle; + Rect r; + + r.top = curstate->boxpos.v; + r.left = curstate->boxpos.h; + r.bottom = curstate->pos.v; + r.right = curstate->boxpos.h + curstate->width; + + mc->generic.type = MACCTRL_GROUPBOX; + mc->generic.privdata = NULL; + mc->generic.ctrl = ctrl; + mc->generic.ctrl->generic.handler = NULL; + + if (curstate->boxname) + c2pstrcpy(ptitle, curstate->boxname); + else + c2pstrcpy(ptitle, ""); + if (mac_gestalts.apprvers >= 0x100) { /* Appearance Manager */ + mc->groupbox.tbctrl = NewControl(window, &r, ptitle, FALSE, 0, 0, 1, + kControlGroupBoxTextTitleProc, (long)mc); + } else { + mc->groupbox.tbctrl = NewControl(window, &r, ptitle, FALSE, 0, 0, 1, + SYS7_GROUPBOX_PROC, (long)mc); + } + add234(mcs->byctrl, mc); + mc->generic.next = mcs->panels[curstate->panelnum]; + mcs->panels[curstate->panelnum] = mc; +} void macctrl_activate(WindowPtr window, EventRecord *event) { @@ -1155,8 +1261,6 @@ void macctrl_click(WindowPtr window, EventRecord *event) 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) && @@ -1180,7 +1284,6 @@ void macctrl_click(WindowPtr window, EventRecord *event) (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 */ @@ -1431,9 +1534,18 @@ void dlg_refresh(union control *ctrl, void *dlg) { struct macctrls *mcs = dlg; union macctrl *mc; + int i; - if (ctrl == NULL) - return; /* FIXME */ + if (ctrl == NULL) { + /* NULL means refresh every control */ + for (i = 0 ; i < mcs->npanels; i++) { + for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) { + ctrlevent(mcs, mc, EVENT_REFRESH); + } + } + return; + } + /* Just refresh a specific control */ mc = findbyctrl(mcs, ctrl); assert(mc != NULL); ctrlevent(mcs, mc, EVENT_REFRESH); @@ -1591,7 +1703,6 @@ void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length) } #endif buffer[olen] = '\0'; - fprintf(stderr, "dlg_editbox_get: %s\n", buffer); } @@ -1607,7 +1718,6 @@ static void dlg_macpopup_clear(union control *ctrl, void *dlg) unsigned int i, n; if (mc == NULL) return; - fprintf(stderr, " popup_clear\n"); n = CountMenuItems(menu); for (i = 0; i < n; i++) DeleteMenuItem(menu, n - i); @@ -1623,7 +1733,6 @@ static void dlg_maclist_clear(union control *ctrl, void *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); @@ -1651,7 +1760,6 @@ static void dlg_macpopup_del(union control *ctrl, void *dlg, int index) 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) memcpy(mc->popup.ids + index, mc->popup.ids + index + 1, @@ -1665,7 +1773,6 @@ static void dlg_maclist_del(union control *ctrl, void *dlg, int index) 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, @@ -1694,7 +1801,6 @@ static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text) Str255 itemstring; if (mc == NULL) return; - fprintf(stderr, " popup_add %s\n", text); assert(text[0] != '\0'); c2pstrcpy(itemstring, text); AppendMenu(menu, "\pdummy"); @@ -1711,7 +1817,6 @@ static void dlg_maclist_add(union control *ctrl, void *dlg, char const *text) 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 @@ -1745,7 +1850,6 @@ static void dlg_macpopup_addwithid(union control *ctrl, void *dlg, unsigned int index; 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) { @@ -1764,7 +1868,6 @@ static void dlg_maclist_addwithid(union control *ctrl, void *dlg, 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);