-/* $Id: macctrls.c,v 1.7 2003/03/20 23:15:25 ben Exp $ */
+/* $Id: macctrls.c,v 1.8 2003/03/21 00:24:17 ben Exp $ */
/*
* Copyright (c) 2003 Ben Harris
* All rights reserved.
#include <Windows.h>
#include <assert.h>
+#include <string.h>
#include "putty.h"
#include "mac.h"
} type;
/* Template from which this was generated */
union control *ctrl;
+ /* Next control in this panel */
+ union macctrl *next;
} generic;
struct {
struct macctrl_generic generic;
struct mac_layoutstate {
Point pos;
unsigned int width;
+ unsigned int panelnum;
};
#define ctrlevent(mcs, mc, event) do { \
static void macctrl_layoutset(struct mac_layoutstate *, struct controlset *,
WindowPtr, struct macctrls *);
+static void macctrl_switchtopanel(struct macctrls *, unsigned int);
static void macctrl_text(struct macctrls *, WindowPtr,
struct mac_layoutstate *, union control *);
static void macctrl_radio(struct macctrls *, WindowPtr,
rect = window->portRect;
#endif
curstate.pos.h = rect.left + 13;
- curstate.pos.v = rect.top + 13;
+ curstate.pos.v = rect.bottom - 59;
curstate.width = rect.right - rect.left - (13 * 2);
if (mac_gestalts.apprvers >= 0x100)
CreateRootControl(window, &root);
mcs->byctrl = newtree234(macctrl_cmp_byctrl);
- for (i = 0; i < cb->nctrlsets; i++)
+ /* Count the number of panels */
+ mcs->npanels = 1;
+ for (i = 1; i < cb->nctrlsets; i++)
+ if (strcmp(cb->ctrlsets[i]->pathname, cb->ctrlsets[i-1]->pathname))
+ mcs->npanels++;
+ mcs->panels = smalloc(sizeof(*mcs->panels) * mcs->npanels);
+ memset(mcs->panels, 0, sizeof(*mcs->panels) * mcs->npanels);
+ curstate.panelnum = 0;
+ 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);
+ }
macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs);
+ }
+ macctrl_switchtopanel(mcs, 1);
}
static void macctrl_layoutset(struct mac_layoutstate *curstate,
}
}
+static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which)
+{
+ unsigned int i, j;
+ union macctrl *mc;
+
+ /* 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)
+ switch (mc->generic.type) {
+ case MACCTRL_TEXT:
+ if (i == which)
+ ShowControl(mc->text.tbctrl);
+ else
+ HideControl(mc->text.tbctrl);
+ break;
+ case MACCTRL_RADIO:
+ for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
+ if (i == which)
+ ShowControl(mc->radio.tbctrls[j]);
+ else
+ HideControl(mc->radio.tbctrls[j]);
+ break;
+ case MACCTRL_CHECKBOX:
+ if (i == which)
+ ShowControl(mc->checkbox.tbctrl);
+ else
+ HideControl(mc->checkbox.tbctrl);
+ break;
+ case MACCTRL_BUTTON:
+ if (i == which)
+ ShowControl(mc->button.tbctrl);
+ else
+ HideControl(mc->button.tbctrl);
+ break;
+
+ }
+}
+
static void macctrl_text(struct macctrls *mcs, WindowPtr window,
struct mac_layoutstate *curstate,
union control *ctrl)
SYS7_TEXT_PROC, (long)mc);
}
add234(mcs->byctrl, mc);
+ mc->generic.next = mcs->panels[curstate->panelnum];
+ mcs->panels[curstate->panelnum] = mc;
}
#if !TARGET_API_MAC_CARBON
0, 0, 1, radioButProc, (long)mc);
}
add234(mcs->byctrl, mc);
+ mc->generic.next = mcs->panels[curstate->panelnum];
+ mcs->panels[curstate->panelnum] = mc;
ctrlevent(mcs, mc, EVENT_REFRESH);
}
checkBoxProc, (long)mc);
add234(mcs->byctrl, mc);
curstate->pos.v += 22;
+ mc->generic.next = mcs->panels[curstate->panelnum];
+ mcs->panels[curstate->panelnum] = mc;
ctrlevent(mcs, mc, EVENT_REFRESH);
}
sizeof(iscancel), &iscancel);
}
add234(mcs->byctrl, mc);
+ mc->generic.next = mcs->panels[curstate->panelnum];
+ mcs->panels[curstate->panelnum] = mc;
curstate->pos.v += 26;
}
freetree234(mcs->byctrl);
mcs->byctrl = NULL;
-
-/* XXX
- DisposeWindow(window);
- if (s->window == NULL)
- sfree(s);
-*/
+ sfree(mcs->panels);
+ mcs->panels = NULL;
}
void dlg_update_start(union control *ctrl, void *dlg)
-/* $Id: macdlg.c,v 1.14 2003/03/17 22:38:18 ben Exp $ */
+/* $Id: macdlg.c,v 1.15 2003/03/21 00:24:17 ben Exp $ */
/*
* Copyright (c) 2002 Ben Harris
* All rights reserved.
#include "macresid.h"
#include "storage.h"
-static void mac_clickdlg(WindowPtr, EventRecord *);
-static void mac_activatedlg(WindowPtr, EventRecord *);
-static void mac_updatedlg(WindowPtr);
-static void mac_adjustdlgmenus(WindowPtr);
static void mac_closedlg(WindowPtr);
void mac_newsession(void)
wi->click = &macctrl_click;
wi->activate = &macctrl_activate;
wi->adjustmenus = &macctrl_adjustmenus;
- wi->close = &macctrl_close;
+ wi->close = &mac_closedlg;
SetWRefCon(s->settings_window, (long)wi);
ShowWindow(s->settings_window);
}
+static void mac_closedlg(WindowPtr window)
+{
+ Session *s = mac_windowsession(window);
+
+ macctrl_close(window);
+ DisposeWindow(window);
+ if (s->window == NULL)
+ sfree(s);
+}
+
+
void mac_dupsession(void)
{
Session *s1 = mac_windowsession(FrontWindow());