X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/9ef3c1cab755348f63c462bbd350af3c3c6ecfbe..71ed591e9e049cf1c64ec9ddc10e2158c2f76c89:/mac/macdlg.c diff --git a/mac/macdlg.c b/mac/macdlg.c index 3da50831..4d60492a 100644 --- a/mac/macdlg.c +++ b/mac/macdlg.c @@ -1,4 +1,4 @@ -/* $Id: macdlg.c,v 1.10 2003/02/02 15:59:00 ben Exp $ */ +/* $Id$ */ /* * Copyright (c) 2002 Ben Harris * All rights reserved. @@ -32,43 +32,176 @@ #include #include #include -#include #include #include #include +#include #include #include #include #include "putty.h" +#include "dialog.h" #include "mac.h" #include "macresid.h" #include "storage.h" +static void mac_config(int); +static void mac_closedlg(WindowPtr); +static void mac_enddlg_config(WindowPtr, int); +static void mac_enddlg_reconfig(WindowPtr, int); + void mac_newsession(void) { - Session *s; + mac_config(FALSE); +} - /* This should obviously be initialised by other means */ - s = smalloc(sizeof(*s)); - memset(s, 0, sizeof(*s)); - do_defaults(NULL, &s->cfg); - s->hasfile = FALSE; +void mac_reconfig(void) +{ + mac_config(TRUE); +} - s->settings_window = - GetDialogWindow(GetNewDialog(wSettings, NULL, (WindowPtr)-1)); +static void mac_config(int midsession) +{ + Session *s; + WinInfo *wi; + static struct sesslist sesslist; + Str255 mactitle; + char *str; + + if (midsession) { + s = mac_windowsession(FrontWindow()); + } else { + s = snew(Session); + memset(s, 0, sizeof(*s)); + do_defaults(NULL, &s->cfg); + s->hasfile = FALSE; + } - SetWRefCon(s->settings_window, (long)s); + /* Copy the configuration somewhere else in case this is a * + * reconfiguration and the user cancels the operation */ + + s->temp_cfg = s->cfg; + + if (HAVE_COLOR_QD()) + s->settings_window = GetNewCWindow(wSettings, NULL, (WindowPtr)-1); + else + s->settings_window = GetNewWindow(wSettings, NULL, (WindowPtr)-1); + + get_sesslist(&sesslist, TRUE); + s->ctrlbox = ctrl_new_box(); + setup_config_box(s->ctrlbox, &sesslist, midsession, 0, 0); + + s->settings_ctrls.data = &s->temp_cfg; + if (midsession) + s->settings_ctrls.end = &mac_enddlg_reconfig; + else + s->settings_ctrls.end = &mac_enddlg_config; + + macctrl_layoutbox(s->ctrlbox, s->settings_window, &s->settings_ctrls); + + wi = snew(WinInfo); + memset(wi, 0, sizeof(*wi)); + wi->s = s; + wi->mcs = &s->settings_ctrls; + wi->wtype = wSettings; + wi->update = &macctrl_update; + wi->click = &macctrl_click; + wi->key = &macctrl_key; + wi->activate = &macctrl_activate; + wi->adjustmenus = &macctrl_adjustmenus; + wi->close = &mac_closedlg; + SetWRefCon(s->settings_window, (long)wi); + if (midsession) + str = dupprintf("%s Reconfiguration", appname); + else + str = dupprintf("%s Configuration", appname); + c2pstrcpy(mactitle, str); + sfree(str); + SetWTitle(s->settings_window, mactitle); 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); +} + +static void mac_enddlg_config(WindowPtr window, int value) +{ + Session *s = mac_windowsession(window); + + if (value == 0) + mac_closedlg(window); + else { + s->cfg = s->temp_cfg; + mac_startsession(s); + mac_closedlg(window); + } +} + +static void mac_enddlg_reconfig(WindowPtr window, int value) +{ + Session *s = mac_windowsession(window); + + if (value == 0) + mac_closedlg(window); + else { + Config prev_cfg = s->cfg; + s->cfg = s->temp_cfg; + mac_closedlg(window); + + /* Pass new config data to the logging module */ + log_reconfig(s->logctx, &s->cfg); + + /* + * Flush the line discipline's edit buffer in the + * case where local editing has just been disabled. + */ + if (s->ldisc) + ldisc_send(s->ldisc, NULL, 0, 0); + + /* Change the palette */ + palette_reset(s); + + /* Pass new config data to the terminal */ + term_reconfig(s->term, &s->cfg); + + /* Pass new config data to the back end */ + if (s->back) + s->back->reconfig(s->backhandle, &s->cfg); + + /* Screen size changed ? */ + if (s->cfg.height != prev_cfg.height || + s->cfg.width != prev_cfg.width || + s->cfg.savelines != prev_cfg.savelines) { + request_resize(s, s->cfg.width, s->cfg.height); + } + + /* Set the window title */ + if (s->cfg.wintitle[0]) + set_title(s, s->cfg.wintitle); + + /* Scroll bar */ + if (s->cfg.scrollbar != prev_cfg.scrollbar) + request_resize(s, s->cfg.width, s->cfg.height); + + /* TODO: zoom, font */ + } +} + void mac_dupsession(void) { - Session *s1 = (Session *)GetWRefCon(FrontWindow()); + Session *s1 = mac_windowsession(FrontWindow()); Session *s2; - s2 = smalloc(sizeof(*s2)); + s2 = snew(Session); memset(s2, 0, sizeof(*s2)); s2->cfg = s1->cfg; s2->hasfile = s1->hasfile; @@ -84,7 +217,7 @@ static OSErr mac_opensessionfrom(FSSpec *fss) void *sesshandle; OSErr err; - s = smalloc(sizeof(*s)); + s = snew(Session); memset(s, 0, sizeof(*s)); err = FSpGetFInfo(fss, &fi); @@ -180,7 +313,7 @@ void mac_opensession(void) void mac_savesession(void) { - Session *s = (Session *)GetWRefCon(FrontWindow()); + Session *s = mac_windowsession(FrontWindow()); void *sesshandle; assert(s->hasfile); @@ -193,7 +326,7 @@ void mac_savesession(void) void mac_savesessionas(void) { #if !TARGET_API_MAC_CARBON /* XXX Navigation Services */ - Session *s = (Session *)GetWRefCon(FrontWindow()); + Session *s = mac_windowsession(FrontWindow()); StandardFileReply sfr; void *sesshandle; @@ -266,36 +399,6 @@ pascal OSErr mac_aevt_pdoc(const AppleEvent *req, AppleEvent *reply, return errAEEventNotHandled; } -void mac_activatedlg(WindowPtr window, EventRecord *event) -{ - DialogItemType itemtype; - Handle itemhandle; - short item; - Rect itemrect; - int active; - DialogRef dialog = GetDialogFromWindow(window); - - active = (event->modifiers & activeFlag) != 0; - GetDialogItem(dialog, wiSettingsOpen, &itemtype, &itemhandle, &itemrect); - HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); - DialogSelect(event, &dialog, &item); -} - -void mac_clickdlg(WindowPtr window, EventRecord *event) -{ - short item; - Session *s = (Session *)GetWRefCon(window); - DialogRef dialog = GetDialogFromWindow(window); - - if (DialogSelect(event, &dialog, &item)) - switch (item) { - case wiSettingsOpen: - HideWindow(window); - mac_startsession(s); - break; - } -} - /* * Local Variables: * c-file-style: "simon"