X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/4bd083f7b36774602d7a3054778cf959a0cac9c1..f11d78f2647ddf2f7c8f457fa4847da7193cda1b:/mac/macctrls.c diff --git a/mac/macctrls.c b/mac/macctrls.c index 5a2ea4da..2529c8c5 100644 --- a/mac/macctrls.c +++ b/mac/macctrls.c @@ -1,4 +1,4 @@ -/* $Id: macctrls.c,v 1.32 2003/04/13 13:52:44 ben Exp $ */ +/* $Id: macctrls.c,v 1.40 2003/05/10 11:26:33 ben Exp $ */ /* * Copyright (c) 2003 Ben Harris * All rights reserved. @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -213,6 +214,18 @@ 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; + + /* XXX what if there's no selection? */ + if (event == EVENT_SELCHANGE) + macctrl_switchtopanel(mcs, dlg_listbox_index(ctrl, dlg) + 1); +} + void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, struct macctrls *mcs) { @@ -222,16 +235,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; @@ -245,12 +255,27 @@ 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); + /* XXX Start with panel 1 active */ + + 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); } @@ -267,40 +292,17 @@ static void macctrl_layoutset(struct mac_layoutstate *curstate, unsigned int i, j, ncols, colstart; struct mac_layoutstate cols[MAXCOLS]; - 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); - 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: 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]; @@ -314,7 +316,6 @@ 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; @@ -455,7 +456,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; @@ -486,7 +486,6 @@ static void macctrl_text(struct macctrls *mcs, WindowPtr window, 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); @@ -501,11 +500,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; @@ -601,6 +595,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); } @@ -643,8 +638,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; @@ -676,7 +669,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); @@ -706,7 +698,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; @@ -733,9 +724,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; @@ -829,14 +817,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; @@ -847,7 +828,7 @@ static void macctrl_listbox(struct macctrls *mcs, WindowPtr window, bounds.left = curstate->pos.h; bounds.right = bounds.left + curstate->width; bounds.top = curstate->pos.v; - bounds.bottom = bounds.top + 20 * ctrl->listbox.height; + bounds.bottom = bounds.top + 16 * ctrl->listbox.height + 2; if (mac_gestalts.apprvers >= 0x100) { InsetRect(&bounds, 3, 3); @@ -881,7 +862,7 @@ static void macctrl_listbox(struct macctrls *mcs, WindowPtr window, #endif } add234(mcs->byctrl, mc); - curstate->pos.v += 6 + 20 * ctrl->listbox.height; + 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); @@ -1000,10 +981,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; @@ -1131,8 +1108,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) && @@ -1156,7 +1131,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 */ @@ -1242,7 +1216,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 @@ -1560,7 +1541,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); } @@ -1576,7 +1556,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); @@ -1592,7 +1571,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); @@ -1620,7 +1598,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, @@ -1634,7 +1611,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, @@ -1663,7 +1639,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"); @@ -1680,7 +1655,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 @@ -1714,7 +1688,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) { @@ -1733,7 +1706,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); @@ -1917,14 +1889,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; } /*