Support for Windows PuTTY connecting straight to a local serial port
[u/mdw/putty] / mac / macctrls.c
index db454cf..e5e774d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macctrls.c,v 1.39 2003/04/14 23:47:07 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;
@@ -81,6 +82,11 @@ union macctrl {
        struct macctrl_generic generic;
        ControlRef tbctrl;
        ControlRef tblabel;
+       ControlRef tbbutton;
+       MenuRef menu;
+       int menuid;
+       unsigned int nids;
+       int *ids;
     } editbox;
     struct {
        struct macctrl_generic generic;
@@ -99,6 +105,8 @@ union macctrl {
     struct {
        struct macctrl_generic generic;
        ControlRef tbctrl;
+       ControlRef tbup;
+       ControlRef tbdown;
        ListHandle list;
        unsigned int nids;
        int *ids;
@@ -111,10 +119,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 +144,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 +161,11 @@ 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 *);
+static void draglist_up(union macctrl *, struct macctrls *);
+static void draglist_down(union macctrl *, struct macctrls *);
+
 #if !TARGET_API_MAC_CARBON
 static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16, ControlRef,
                                               ControlDefProcMessage, SInt32);
@@ -153,6 +173,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 +205,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 +245,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 +271,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 +289,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,17 +305,43 @@ 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;
+    }
+
+    /* 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;
@@ -297,8 +350,8 @@ static void macctrl_layoutset(struct mac_layoutstate *curstate,
        union control *ctrl = s->ctrls[i];
 
        colstart = COLUMN_START(ctrl->generic.column);
-       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;
                assert(ncols <= MAXCOLS);
@@ -320,90 +373,128 @@ static void macctrl_layoutset(struct mac_layoutstate *curstate,
                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);
+           if (mc->editbox.tbbutton != NULL)
+               hideshow(mc->editbox.tbbutton);
+           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);
+           if (mc->listbox.tbup != NULL)
+               hideshow(mc->listbox.tbup);
+           if (mc->listbox.tbdown != NULL)
+               hideshow(mc->listbox.tbdown);
+           /*
+            * 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
@@ -464,7 +555,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,
@@ -477,7 +568,7 @@ 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);
@@ -496,7 +587,10 @@ static void macctrl_editbox(struct macctrls *mcs, WindowPtr window,
                            union control *ctrl)
 {
     union macctrl *mc = snew(union macctrl);
-    Rect lbounds, bounds;
+    Rect lbounds, bounds, butbounds;
+    static int nextmenuid = MENU_MIN;
+    int menuid;
+    MenuRef menu;
 
     mc->generic.type = MACCTRL_EDITBOX;
     mc->generic.ctrl = ctrl;
@@ -520,11 +614,18 @@ static void macctrl_editbox(struct macctrls *mcs, WindowPtr window,
     }
     bounds.top = curstate->pos.v;
     bounds.bottom = bounds.top + 22;
+
+    if (ctrl->editbox.has_list) {
+       butbounds = bounds;
+       butbounds.left = butbounds.right - 20;
+       bounds.right -= 26; /* enough for 6 px gap and a button */
+    }
+
     if (mac_gestalts.apprvers >= 0x100) {
        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,
@@ -532,7 +633,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);
@@ -542,16 +643,37 @@ 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
+
+    if (ctrl->editbox.has_list) {
+       while (GetMenuHandle(nextmenuid) != NULL)
+           if (++nextmenuid >= MENU_MAX) nextmenuid = MENU_MIN;
+       menuid = nextmenuid++;
+       menu = NewMenu(menuid, "\pdummy");
+       if (menu == NULL) goto nomenu;
+       mc->editbox.menu = menu;
+       mc->editbox.menuid = menuid;
+       InsertMenu(menu, kInsertHierarchicalMenu);
+       mc->editbox.nids = 0;
+       mc->editbox.ids = NULL;
+
+       mc->editbox.tbbutton = NewControl(window, &butbounds, NULL, FALSE,
+                                         popupTitleLeftJust, menuid, 0,
+                                         popupMenuProc + popupFixedWidth,
+                                         (long)mc);
+    }
+
+  nomenu:
+
     curstate->pos.v += 28;
     add234(mcs->byctrl, mc);
     mc->generic.next = mcs->panels[curstate->panelnum];
@@ -626,7 +748,7 @@ static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16 variant,
     return 0;
 }
 #endif
-
+                            
 static void macctrl_radio(struct macctrls *mcs, WindowPtr window,
                          struct mac_layoutstate *curstate,
                          union control *ctrl)
@@ -649,7 +771,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,
@@ -658,7 +780,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);
@@ -677,7 +799,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;
@@ -704,7 +826,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;
@@ -730,7 +852,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) {
@@ -741,7 +863,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) {
@@ -812,9 +934,10 @@ static void macctrl_listbox(struct macctrls *mcs, WindowPtr window,
                            union control *ctrl)
 {
     union macctrl *mc = snew(union macctrl);
-    Rect bounds;
+    Rect bounds, upbounds, downbounds;
     Size olen;
 
+    /* XXX Use label */
     assert(ctrl->listbox.percentwidth == 100);
     mc->generic.type = MACCTRL_LISTBOX;
     mc->generic.ctrl = ctrl;
@@ -827,9 +950,19 @@ static void macctrl_listbox(struct macctrls *mcs, WindowPtr window,
     bounds.top = curstate->pos.v;
     bounds.bottom = bounds.top + 16 * ctrl->listbox.height + 2;
 
+    if (ctrl->listbox.draglist) {
+       upbounds = downbounds = bounds;
+       upbounds.left = upbounds.right - 58;
+       upbounds.bottom = upbounds.top + 20;
+       downbounds.left = downbounds.right - 58;
+       downbounds.top = upbounds.bottom + 6;
+       downbounds.bottom = downbounds.top + 20;
+       bounds.right -= 64; /* enough for 6 px gap and a button */
+    }
+
     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,
@@ -844,7 +977,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;
@@ -858,11 +991,24 @@ static void macctrl_listbox(struct macctrls *mcs, WindowPtr window,
        (*mc->listbox.list)->selFlags = lOnlyOne;
 #endif
     }
+
+    if (ctrl->listbox.draglist) {
+       mc->listbox.tbup = NewControl(window, &upbounds, "\pUp", FALSE, 0, 0, 1,
+                                     pushButProc, (long)mc);
+       mc->listbox.tbdown = NewControl(window, &downbounds, "\pDown", FALSE, 0, 0, 1,
+                                     pushButProc, (long)mc);
+    }
+
     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
@@ -958,6 +1104,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)
@@ -1003,7 +1191,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);
@@ -1013,6 +1201,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)
 {
@@ -1041,6 +1262,8 @@ void macctrl_activate(WindowPtr window, EventRecord *event)
                HiliteControl(mc->editbox.tbctrl, state);
                if (mc->editbox.tblabel != NULL)
                    HiliteControl(mc->editbox.tblabel, state);
+               if (mc->editbox.tbbutton != NULL)
+                   HiliteControl(mc->editbox.tbbutton, state);
                break;
              case MACCTRL_RADIO:
                for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
@@ -1058,10 +1281,16 @@ void macctrl_activate(WindowPtr window, EventRecord *event)
                break;
              case MACCTRL_LISTBOX:
                HiliteControl(mc->listbox.tbctrl, state);
+               if (mc->listbox.tbup != NULL)
+                   HiliteControl(mc->listbox.tbup, state);
+               if (mc->listbox.tbdown != NULL)
+                   HiliteControl(mc->listbox.tbdown, state);
                break;
              case MACCTRL_POPUP:
                HiliteControl(mc->popup.tbctrl, state);
                break;
+             case MACCTRL_GROUPBOX:
+               HiliteControl(mc->popup.tbctrl, state);
            }
 #if !TARGET_API_MAC_CARBON
            if (mcs->focus == mc) {
@@ -1124,6 +1353,12 @@ void macctrl_click(WindowPtr window, EventRecord *event)
                TEClick(mouse, !!(event->modifiers & shiftKey), te);
                goto done;
            }
+           if (mc->generic.type == MACCTRL_EDITBOX &&
+               control == mc->editbox.tbbutton) {
+               dlg_editbox_set(mc->generic.ctrl, mcs,
+                               cp_enumerate(dlg_listbox_index(mc->generic.ctrl, mcs)));
+               ctrlevent(mcs, mc, EVENT_VALCHANGE);
+           }
            if (mc->generic.type == MACCTRL_LISTBOX &&
                (control == mc->listbox.tbctrl ||
                 control == (*mc->listbox.list)->vScroll)) {
@@ -1136,6 +1371,12 @@ void macctrl_click(WindowPtr window, EventRecord *event)
                    ctrlevent(mcs, mc, EVENT_SELCHANGE);
                goto done;
            }
+           if (mc->generic.type == MACCTRL_LISTBOX &&
+               control == mc->listbox.tbup)
+               draglist_up(mc, mcs);
+           if (mc->generic.type == MACCTRL_LISTBOX &&
+               control == mc->listbox.tbdown)
+               draglist_down(mc, mcs);
 #endif
            trackresult = TrackControl(control, mouse, (ControlActionUPP)-1);
        }
@@ -1162,7 +1403,19 @@ void macctrl_click(WindowPtr window, EventRecord *event)
            if (trackresult != 0)
                ctrlevent(mcs, mc, EVENT_ACTION);
            break;
+         case MACCTRL_EDITBOX:
+           if (control == mc->editbox.tbbutton) {
+               dlg_editbox_set(mc->generic.ctrl, mcs,
+                               cp_enumerate(dlg_listbox_index(mc->generic.ctrl, mcs)));
+               ctrlevent(mcs, mc, EVENT_VALCHANGE);
+           }
+           break;
          case MACCTRL_LISTBOX:
+           if (control == mc->listbox.tbup)
+               draglist_up(mc, mcs);
+           if (control == mc->listbox.tbdown)
+               draglist_down(mc, mcs);
+
            /* FIXME spot double-click */
            ctrlevent(mcs, mc, EVENT_SELCHANGE);
            break;
@@ -1378,9 +1631,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);
@@ -1562,6 +1824,23 @@ static void dlg_macpopup_clear(union control *ctrl, void *dlg)
     SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
 }
 
+static void dlg_macedit_clear(union control *ctrl, void *dlg)
+{
+    struct macctrls *mcs = dlg;
+    union macctrl *mc = findbyctrl(mcs, ctrl);
+    MenuRef menu = mc->editbox.menu;
+    unsigned int i, n;
+
+    if (mc == NULL) return;
+    n = CountMenuItems(menu);
+    for (i = 0; i < n; i++)
+       DeleteMenuItem(menu, n - i);
+    mc->editbox.nids = 0;
+    sfree(mc->editbox.ids);
+    mc->editbox.ids = NULL;
+    SetControlMaximum(mc->editbox.tbbutton, CountMenuItems(menu));
+}
+
 static void dlg_maclist_clear(union control *ctrl, void *dlg)
 {
     struct macctrls *mcs = dlg;
@@ -1585,6 +1864,8 @@ void dlg_listbox_clear(union control *ctrl, void *dlg)
        else
            dlg_maclist_clear(ctrl, dlg);
        break;
+      case CTRL_EDITBOX:
+       dlg_macedit_clear(ctrl, dlg);
     }
 }
 
@@ -1602,6 +1883,20 @@ static void dlg_macpopup_del(union control *ctrl, void *dlg, int index)
     SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
 }
 
+static void dlg_macedit_del(union control *ctrl, void *dlg, int index)
+{
+    struct macctrls *mcs = dlg;
+    union macctrl *mc = findbyctrl(mcs, ctrl);
+    MenuRef menu = mc->editbox.menu;
+
+    if (mc == NULL) return;
+    DeleteMenuItem(menu, index + 1);
+    if (mc->editbox.ids != NULL)
+       memcpy(mc->editbox.ids + index, mc->editbox.ids + index + 1,
+              (mc->editbox.nids - index - 1) * sizeof(*mc->editbox.ids));
+    SetControlMaximum(mc->editbox.tbbutton, CountMenuItems(menu));
+}
+
 static void dlg_maclist_del(union control *ctrl, void *dlg, int index)
 {
     struct macctrls *mcs = dlg;
@@ -1625,6 +1920,8 @@ void dlg_listbox_del(union control *ctrl, void *dlg, int index)
        else
            dlg_maclist_del(ctrl, dlg, index);
        break;
+      case CTRL_EDITBOX:
+       dlg_macedit_del(ctrl, dlg, index);
     }
 }
 
@@ -1643,6 +1940,20 @@ static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text)
     SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
 }
 
+static void dlg_macedit_add(union control *ctrl, void *dlg, char const *text)
+{
+    struct macctrls *mcs = dlg;
+    union macctrl *mc = findbyctrl(mcs, ctrl);
+    MenuRef menu = mc->editbox.menu;
+    Str255 itemstring;
+
+    if (mc == NULL) return;
+    assert(text[0] != '\0');
+    c2pstrcpy(itemstring, text);
+    AppendMenu(menu, "\pdummy");
+    SetMenuItemText(menu, CountMenuItems(menu), itemstring);
+    SetControlMaximum(mc->editbox.tbbutton, CountMenuItems(menu));
+}
 
 static void dlg_maclist_add(union control *ctrl, void *dlg, char const *text)
 {
@@ -1673,6 +1984,9 @@ void dlg_listbox_add(union control *ctrl, void *dlg, char const *text)
        else
            dlg_maclist_add(ctrl, dlg, text);
        break;
+      case CTRL_EDITBOX:
+       dlg_macedit_add(ctrl, dlg, text);
+       break;
     }
 }
 
@@ -1694,6 +2008,24 @@ static void dlg_macpopup_addwithid(union control *ctrl, void *dlg,
     mc->popup.ids[index] = id;
 }
 
+static void dlg_macedit_addwithid(union control *ctrl, void *dlg,
+                                  char const *text, int id)
+{
+    struct macctrls *mcs = dlg;
+    union macctrl *mc = findbyctrl(mcs, ctrl);
+    MenuRef menu = mc->editbox.menu;
+    unsigned int index;
+
+    if (mc == NULL) return;
+    dlg_macedit_add(ctrl, dlg, text);
+    index = CountMenuItems(menu) - 1;
+    if (mc->editbox.nids <= index) {
+       mc->editbox.nids = index + 1;
+       mc->editbox.ids = sresize(mc->editbox.ids, mc->editbox.nids, int);
+    }
+    mc->editbox.ids[index] = id;
+}
+
 static void dlg_maclist_addwithid(union control *ctrl, void *dlg,
                                  char const *text, int id)
 {
@@ -1728,6 +2060,9 @@ void dlg_listbox_addwithid(union control *ctrl, void *dlg,
        else
            dlg_maclist_addwithid(ctrl, dlg, text, id);
        break;
+      case CTRL_EDITBOX:
+       dlg_macedit_addwithid(ctrl, dlg, text, id);
+       break;
     }
 }
 
@@ -1746,6 +2081,9 @@ int dlg_listbox_getid(union control *ctrl, void *dlg, int index)
            assert(mc->listbox.ids != NULL && mc->listbox.nids > index);
            return mc->listbox.ids[index];
        }
+      case CTRL_EDITBOX:
+       assert(mc->editbox.ids != NULL && mc->editbox.nids > index);
+       return mc->editbox.ids[index];
     }
     return -1;
 }
@@ -1767,6 +2105,8 @@ int dlg_listbox_index(union control *ctrl, void *dlg)
            else
                return -1;
        }
+      case CTRL_EDITBOX:
+       return GetControlValue(mc->editbox.tbbutton) - 1;
     }
     return -1;
 }
@@ -1786,6 +2126,8 @@ int dlg_listbox_issel(union control *ctrl, void *dlg, int index)
            cell.v = index;
            return LGetSelect(FALSE, &cell, mc->listbox.list);
        }
+      case CTRL_EDITBOX:
+       return GetControlValue(mc->editbox.tbbutton) - 1 == index;
     }
     return FALSE;
 }
@@ -1801,9 +2143,78 @@ void dlg_listbox_select(union control *ctrl, void *dlg, int index)
        if (ctrl->listbox.height == 0)
            SetControlValue(mc->popup.tbctrl, index + 1);
        break;
+      case CTRL_EDITBOX:
+       SetControlValue(mc->editbox.tbbutton, index + 1);
     }
 }
 
+static void draglist_move(union macctrl *mc, struct macctrls *mcs,
+                         int direction)
+{
+    ListBounds bounds;
+    Cell cell = {0, 0};
+    char current[255];
+    char new[255];
+    short curlength = 255;
+    short newlength = 255;
+    int curid, newid;
+
+    int index = dlg_listbox_index(mc->generic.ctrl, mcs);
+
+#if TARGET_API_MAC_CARBON
+    GetListDataBounds(mc->listbox.list, &bounds);
+#else
+    bounds = (*mc->listbox.list)->dataBounds;
+#endif
+
+    if ((index < 0) ||
+       (index == 0 && direction < 0) ||
+       (index == bounds.bottom-1 && direction > 0)) {
+       SysBeep(30);
+       return;
+    }
+
+    /* Swap the contents of the selected and target list cells */
+
+    cell.v = index;
+    LGetCell(current, &curlength, cell, mc->listbox.list);
+    current[curlength] = '\0';
+    cell.v += direction;
+    LGetCell(new, &newlength, cell, mc->listbox.list);
+    new[newlength] = '\0';
+
+    cell.v = index;
+    LSetCell(new, newlength, cell, mc->listbox.list);
+    cell.v += direction;
+    LSetCell(current, curlength, cell, mc->listbox.list);
+
+    /* Move the selection to the target list cell */
+
+    cell.v = index;
+    LSetSelect(FALSE, cell, mc->listbox.list);
+    cell.v += direction;
+    LSetSelect(TRUE, cell, mc->listbox.list);
+    DrawOneControl(mc->listbox.tbctrl);
+
+    /* Swap the ids of the list cells */
+
+    curid = mc->listbox.ids[index];
+    newid = mc->listbox.ids[index + direction];
+    mc->listbox.ids[index] = newid;
+    mc->listbox.ids[index + direction] = curid;
+                           
+    ctrlevent(mcs, mc, EVENT_VALCHANGE);
+}
+
+static void draglist_up(union macctrl *mc, struct macctrls *mcs)
+{
+    draglist_move(mc, mcs, -1);
+}
+
+static void draglist_down(union macctrl *mc, struct macctrls *mcs)
+{
+    draglist_move(mc, mcs, +1);
+}
 
 /*
  * Text control
@@ -1916,6 +2327,17 @@ int dlg_coloursel_results(union control *ctrl, void *dlg,
        return 0;
 }
 
+void dlg_label_change(union control *ctrl, void *dlg, char const *text)
+{
+    /*
+     * This function is currently only used by the config box to
+     * switch the labels on the host and port boxes between serial
+     * and network modes. Since the Mac port does not have a serial
+     * back end, this function can safely do nothing.
+     */
+}
+
+
 /*
  * Local Variables:
  * c-file-style: "simon"