Set the space required by a listbox sensibly as well.
[u/mdw/putty] / mac / macctrls.c
index 5a2ea4d..b4e3c7d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macctrls.c,v 1.32 2003/04/13 13:52:44 ben Exp $ */
+/* $Id: macctrls.c,v 1.38 2003/04/14 23:28:58 ben Exp $ */
 /*
  * Copyright (c) 2003 Ben Harris
  * All rights reserved.
@@ -27,6 +27,7 @@
 
 #include <MacTypes.h>
 #include <Appearance.h>
+#include <ColorPicker.h>
 #include <Controls.h>
 #include <ControlDefinitions.h>
 #include <Events.h>
@@ -213,6 +214,17 @@ static int macctrl_cmp_byctrl_find(void *av, void *bv)
        return 0;
 }
 
+static union control panellist;
+
+static void panellist_handler(union control *ctrl, void *dlg, void *data,
+                             int event)
+{
+    struct macctrls *mcs = dlg;
+
+    if (event == EVENT_SELCHANGE)
+       macctrl_switchtopanel(mcs, dlg_listbox_index(ctrl, dlg) + 1);
+}
+
 void macctrl_layoutbox(struct controlbox *cb, WindowPtr window,
                       struct macctrls *mcs)
 {
@@ -222,16 +234,13 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window,
     Rect rect;
 
     macctrl_init();
+    if (mac_gestalts.apprvers >= 0x100)
+       CreateRootControl(window, &root);
 #if TARGET_API_MAC_CARBON
     GetPortBounds(GetWindowPort(window), &rect);
 #else
     rect = window->portRect;
 #endif
-    curstate.pos.h = rect.left + 13;
-    curstate.pos.v = rect.bottom - 33;
-    curstate.width = rect.right - rect.left - (13 * 2);
-    if (mac_gestalts.apprvers >= 0x100)
-       CreateRootControl(window, &root);
     mcs->window = window;
     mcs->byctrl = newtree234(macctrl_cmp_byctrl);
     mcs->focus = NULL;
@@ -245,12 +254,26 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window,
     mcs->panels = snewn(mcs->npanels, union macctrl *);
     memset(mcs->panels, 0, sizeof(*mcs->panels) * mcs->npanels);
     curstate.panelnum = 0;
+
+    curstate.pos.h = rect.left + 13;
+    curstate.pos.v = rect.top + 13;
+    curstate.width = 160;
+    panellist.listbox.type = CTRL_LISTBOX;
+    panellist.listbox.handler = &panellist_handler;
+    panellist.listbox.height = 20;
+    panellist.listbox.percentwidth = 100;
+    macctrl_listbox(mcs, window, &curstate, &panellist);
+
+    curstate.pos.h = rect.left + 13 + 160 + 13;
+    curstate.pos.v = rect.bottom - 33;
+    curstate.width = rect.right - (rect.left + 13 + 160) - (13 * 2);
     for (i = 0; i < cb->nctrlsets; i++) {
        if (i > 0 && strcmp(cb->ctrlsets[i]->pathname,
                            cb->ctrlsets[i-1]->pathname)) {
            curstate.pos.v = rect.top + 13;
            curstate.panelnum++;
            assert(curstate.panelnum < mcs->npanels);
+           dlg_listbox_add(&panellist, mcs, cb->ctrlsets[i]->pathname);
        }
        macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs);
     }
@@ -601,6 +624,7 @@ static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16 variant,
                FrameRect(&rect);
                InsetRect(&rect, 3, 3);
            }
+           EraseRect(&rect);
            (*(TEHandle)(*control)->contrlData)->viewRect = rect;
            TEUpdate(&rect, (TEHandle)(*control)->contrlData);
        }
@@ -847,7 +871,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 +905,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);
@@ -1242,7 +1266,14 @@ void macctrl_key(WindowPtr window, EventRecord *event)
            HandleControlKey(control, (event->message & keyCodeMask) >> 8,
                             event->message & charCodeMask, event->modifiers);
            mc = (union macctrl *)GetControlReference(control);
-           ctrlevent(mcs, mc, EVENT_VALCHANGE);
+           switch (mc->generic.type) {
+             case MACCTRL_LISTBOX:
+               ctrlevent(mcs, mc, EVENT_SELCHANGE);
+               break;
+             default:
+               ctrlevent(mcs, mc, EVENT_VALCHANGE);
+               break;
+           }
        }
     }
 #if !TARGET_API_MAC_CARBON
@@ -1917,14 +1948,34 @@ void printer_finish_enum(printer_enum *pe)
 void dlg_coloursel_start(union control *ctrl, void *dlg,
                         int r, int g, int b)
 {
+    struct macctrls *mcs = dlg;
+    union macctrl *mc = findbyctrl(mcs, ctrl);
+    Point where = {-1, -1}; /* Screen with greatest colour depth */
+    RGBColor incolour;
 
+    if (HAVE_COLOR_QD()) {
+       incolour.red = r * 0x0101;
+       incolour.green = g * 0x0101;
+       incolour.blue = b * 0x0101;
+       mcs->gotcolour = GetColor(where, "\pModify Colour:", &incolour,
+                                 &mcs->thecolour);
+       ctrlevent(mcs, mc, EVENT_CALLBACK);
+    } else
+       dlg_beep(dlg);
 }
 
 int dlg_coloursel_results(union control *ctrl, void *dlg,
                          int *r, int *g, int *b)
 {
+    struct macctrls *mcs = dlg;
 
-    return 0;
+    if (mcs->gotcolour) {
+       *r = mcs->thecolour.red >> 8;
+       *g = mcs->thecolour.green >> 8;
+       *b = mcs->thecolour.blue >> 8;
+       return 1;
+    } else
+       return 0;
 }
 
 /*