From 347bfcd74251d80fbc84ce9446cf87cd74a8ed8b Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 4 Feb 2003 23:39:26 +0000 Subject: [PATCH] Add a level of indirection to make it rather easier to work out which of a session's windows we're dealing with. git-svn-id: svn://svn.tartarus.org/sgt/putty@2804 cda61777-01e9-0310-a592-d414129be87e --- mac/mac.c | 37 +++++++++++++++++++------------------ mac/mac.h | 8 ++++++++ mac/macdlg.c | 10 +++++----- mac/macterm.c | 31 ++++++++++++++++++------------- 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/mac/mac.c b/mac/mac.c index 5abc49a9..2c4794df 100644 --- a/mac/mac.c +++ b/mac/mac.c @@ -1,4 +1,4 @@ -/* $Id: mac.c,v 1.44 2003/02/04 00:33:11 ben Exp $ */ +/* $Id: mac.c,v 1.45 2003/02/04 23:39:26 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -456,24 +456,15 @@ static void mac_updatelicence(WindowPtr window) /* * Work out what kind of window we're dealing with. - * Concept shamelessly nicked from SurfWriter. */ -static int mac_windowtype(WindowPtr window) { - int kind; - long refcon; - - if (window == NULL) - return wNone; - kind = GetWindowKind(window); - if (kind < 0) +static int mac_windowtype(WindowPtr window) +{ + +#if !TARGET_API_MAC_CARBON + if (GetWindowKind(window) < 0) return wDA; - if (GetWVariant(window) == zoomDocProc) - return wTerminal; - refcon = GetWRefCon(window); - if (refcon < 1024) - return refcon; - else - return wSettings; +#endif + return ((WinInfo *)GetWRefCon(window))->wtype; } /* @@ -568,12 +559,17 @@ static void mac_openabout(void) { VersRecHndl vers; Rect box; StringPtr longvers; + WinInfo *wi; if (windows.about) SelectWindow(windows.about); else { windows.about = GetDialogWindow(GetNewDialog(wAbout, NULL, (WindowPtr)-1)); + wi = smalloc(sizeof(*wi)); + wi->s = NULL; + wi->wtype = wAbout; + SetWRefCon(windows.about, (long)wi); vers = (VersRecHndl)Get1Resource('vers', 1); if (vers != NULL && *vers != NULL) { longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1; @@ -587,11 +583,16 @@ static void mac_openabout(void) { } static void mac_openlicence(void) { + WinInfo *wi; if (windows.licence) SelectWindow(windows.licence); else { windows.licence = GetNewWindow(wLicence, NULL, (WindowPtr)-1); + wi = smalloc(sizeof(*wi)); + wi->s = NULL; + wi->wtype = wLicence; + SetWRefCon(windows.licence, (long)wi); ShowWindow(windows.licence); } } @@ -601,7 +602,7 @@ static void mac_closewindow(WindowPtr window) { switch (mac_windowtype(window)) { #if !TARGET_API_MAC_CARBON case wDA: - CloseDeskAcc(((WindowPeek)window)->windowKind); + CloseDeskAcc(GetWindowKind(window)); break; #endif case wTerminal: diff --git a/mac/mac.h b/mac/mac.h index 1f14a0d1..0ab3d06b 100644 --- a/mac/mac.h +++ b/mac/mac.h @@ -40,6 +40,14 @@ extern struct mac_gestalts mac_gestalts; #define HAVE_COLOR_QD() (mac_gestalts.qdvers > gestaltOriginalQD) #endif +/* Every window used by PuTTY has a refCon field pointing to one of these. */ +typedef struct { + struct Session *s; + int wtype; +} WinInfo; + +#define mac_windowsession(w) (((WinInfo *)GetWRefCon(w))->s) + typedef struct Session { struct Session *next; struct Session **prev; diff --git a/mac/macdlg.c b/mac/macdlg.c index 3da50831..4f18bdd3 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: macdlg.c,v 1.11 2003/02/04 23:39:26 ben Exp $ */ /* * Copyright (c) 2002 Ben Harris * All rights reserved. @@ -65,7 +65,7 @@ void mac_newsession(void) void mac_dupsession(void) { - Session *s1 = (Session *)GetWRefCon(FrontWindow()); + Session *s1 = mac_windowsession(FrontWindow()); Session *s2; s2 = smalloc(sizeof(*s2)); @@ -180,7 +180,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 +193,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; @@ -284,7 +284,7 @@ void mac_activatedlg(WindowPtr window, EventRecord *event) void mac_clickdlg(WindowPtr window, EventRecord *event) { short item; - Session *s = (Session *)GetWRefCon(window); + Session *s = mac_windowsession(window); DialogRef dialog = GetDialogFromWindow(window); if (DialogSelect(event, &dialog, &item)) diff --git a/mac/macterm.c b/mac/macterm.c index d30031ee..52c33b86 100644 --- a/mac/macterm.c +++ b/mac/macterm.c @@ -1,4 +1,4 @@ -/* $Id: macterm.c,v 1.67 2003/02/04 02:08:03 ben Exp $ */ +/* $Id: macterm.c,v 1.68 2003/02/04 23:39:26 ben Exp $ */ /* * Copyright (c) 1999 Simon Tatham * Copyright (c) 1999, 2002 Ben Harris @@ -98,6 +98,7 @@ void mac_startsession(Session *s) { char *errmsg; int i; + WinInfo *wi; init_ucs(s); @@ -119,7 +120,10 @@ void mac_startsession(Session *s) s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1); else s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1); - SetWRefCon(s->window, (long)s); + wi = smalloc(sizeof(*wi)); + wi->s = s; + wi->wtype = wTerminal; + SetWRefCon(s->window, (long)wi); s->scrollbar = GetNewControl(cVScroll, s->window); s->term = term_init(&s->cfg, &s->ucsdata, s); @@ -385,7 +389,7 @@ void mac_adjusttermcursor(WindowPtr window, Point mouse, RgnHandle cursrgn) { #endif SetPort((GrafPtr)GetWindowPort(window)); - s = (Session *)GetWRefCon(window); + s = mac_windowsession(window); GlobalToLocal(&mouse); part = FindControl(mouse, window, &control); if (control == s->scrollbar) { @@ -435,7 +439,7 @@ void mac_adjusttermmenus(WindowPtr window) { long offset; #endif - s = (Session *)GetWRefCon(window); + s = mac_windowsession(window); menu = GetMenuHandle(mFile); DisableItem(menu, iSave); /* XXX enable if modified */ EnableItem(menu, iSaveAs); @@ -463,7 +467,7 @@ void mac_adjusttermmenus(WindowPtr window) { void mac_menuterm(WindowPtr window, short menu, short item) { Session *s; - s = (Session *)GetWRefCon(window); + s = mac_windowsession(window); switch (menu) { case mEdit: switch (item) { @@ -484,7 +488,7 @@ void mac_clickterm(WindowPtr window, EventRecord *event) { int part; static ControlActionUPP mac_scrolltracker_upp = NULL; - s = (Session *)GetWRefCon(window); + s = mac_windowsession(window); SetPort((GrafPtr)GetWindowPort(window)); mouse = event->where; GlobalToLocal(&mouse); @@ -705,9 +709,9 @@ static pascal void mac_scrolltracker(ControlHandle control, short part) { Session *s; #if TARGET_API_MAC_CARBON - s = (Session *)GetWRefCon(GetControlOwner(control)); + s = mac_windowsession(GetControlOwner(control)); #else - s = (Session *)GetWRefCon((*control)->contrlOwner); + s = mac_windowsession((*control)->contrlOwner); #endif switch (part) { case kControlUpButtonPart: @@ -726,7 +730,7 @@ static pascal void mac_scrolltracker(ControlHandle control, short part) { } void mac_keyterm(WindowPtr window, EventRecord *event) { - Session *s = (Session *)GetWRefCon(window); + Session *s = mac_windowsession(window); Key_Sym keysym = PK_NULL; unsigned int mods = 0, flags = PKF_NUMLOCK; UniChar utxt[1]; @@ -896,7 +900,7 @@ void mac_growterm(WindowPtr window, EventRecord *event) { FontInfo fi; #endif - s = (Session *)GetWRefCon(window); + s = mac_windowsession(window); #if !TARGET_API_MAC_CARBON draghooksave = LMGetDragHook(); @@ -970,7 +974,7 @@ static pascal void mac_growtermdraghook(void) void mac_closeterm(WindowPtr window) { - Session *s = (Session *)GetWRefCon(window); + Session *s = mac_windowsession(window); /* XXX warn on close */ HideWindow(s->window); @@ -982,6 +986,7 @@ void mac_closeterm(WindowPtr window) if (s->uni_to_font != NULL) DisposeUnicodeToTextInfo(&s->uni_to_font); term_free(s->term); + sfree((WinInfo *)GetWRefCon(s->window)); DisposeWindow(s->window); DisposePalette(s->palette); sfree(s); @@ -990,7 +995,7 @@ void mac_closeterm(WindowPtr window) void mac_activateterm(WindowPtr window, Boolean active) { Session *s; - s = (Session *)GetWRefCon(window); + s = mac_windowsession(window); s->term->has_focus = active; term_update(s->term); if (active) @@ -1012,7 +1017,7 @@ void mac_updateterm(WindowPtr window) { RgnHandle visrgn; #endif - s = (Session *)GetWRefCon(window); + s = mac_windowsession(window); SetPort((GrafPtr)GetWindowPort(window)); BeginUpdate(window); pre_paint(s); -- 2.11.0