X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/3976728b1aa1805bee688fcfa9131edcbe4dae88..f3ab148c2f5bc562133711998ac30d5fb31be460:/mac/mac.c diff --git a/mac/mac.c b/mac/mac.c index 2e4bfdf7..b3df4838 100644 --- a/mac/mac.c +++ b/mac/mac.c @@ -1,4 +1,4 @@ -/* $Id: mac.c,v 1.2 2002/11/23 15:11:13 ben Exp $ */ +/* $Id: mac.c,v 1.17 2003/01/04 12:45:11 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -40,8 +40,12 @@ #include #include #include +#include #include +#include +#include #include +#include #include #include @@ -69,10 +73,12 @@ static void mac_growwindow(WindowPtr, EventRecord *); static void mac_activatewindow(WindowPtr, EventRecord *); static void mac_activateabout(WindowPtr, EventRecord *); static void mac_updatewindow(WindowPtr); +static void mac_updatelicence(WindowPtr); static void mac_keypress(EventRecord *); static int mac_windowtype(WindowPtr); static void mac_menucommand(long); static void mac_openabout(void); +static void mac_openlicence(void); static void mac_adjustcursor(RgnHandle); static void mac_adjustmenus(void); static void mac_closewindow(WindowPtr); @@ -97,6 +103,7 @@ int main (int argc, char **argv) { static void mac_startup(void) { Handle menuBar; + TECInfoHandle ti; /* Init Memory Manager */ MaxApplZone(); @@ -111,9 +118,13 @@ static void mac_startup(void) { /* Init TextEdit */ TEInit(); /* Init Dialog Manager */ - InitDialogs(nil); + InitDialogs(NULL); cold = 0; + /* Get base system version (only used if there's no better selector) */ + if (Gestalt(gestaltSystemVersion, &mac_gestalts.sysvers) != noErr || + (mac_gestalts.sysvers &= 0xffff) < 0x700) + fatalbox("PuTTY requires System 7 or newer"); /* Find out if we've got Color Quickdraw */ if (Gestalt(gestaltQuickdrawVersion, &mac_gestalts.qdvers) != noErr) mac_gestalts.qdvers = gestaltOriginalQD; @@ -128,12 +139,33 @@ static void mac_startup(void) { if (&RegisterAppearanceClient == kUnresolvedCFragSymbolAddress) mac_gestalts.apprvers = 0; #endif +#if TARGET_CPU_68K + mac_gestalts.cntlattr = 0; + mac_gestalts.windattr = 0; +#else /* Mac OS 8.5 Control Manager (proportional scrollbars)? */ - if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr) + if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr || + &SetControlViewSize == kUnresolvedCFragSymbolAddress) mac_gestalts.cntlattr = 0; /* Mac OS 8.5 Window Manager? */ - if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr) + if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr || + &SetWindowContentColor == kUnresolvedCFragSymbolAddress) mac_gestalts.windattr = 0; +#endif + /* Text Encoding Conversion Manager? */ + if ( +#if TARGET_RT_MAC_CFM + &TECGetInfo == kUnresolvedCFragSymbolAddress || +#else + InitializeUnicodeConverter(NULL) != noErr || +#endif + TECGetInfo(&ti) != noErr) + mac_gestalts.encvvers = 0; + else { + mac_gestalts.encvvers = (*ti)->tecVersion; + mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures; + DisposeHandle((Handle)ti); + } /* We've been tested with the Appearance Manager */ if (mac_gestalts.apprvers != 0) @@ -150,6 +182,17 @@ static void mac_startup(void) { windows.about = NULL; windows.licence = NULL; + { + short vol; + long dirid; + + /* Set the default directory for loading and saving settings. */ + /* XXX Should we create it? */ + if (get_session_dir(FALSE, &vol, &dirid) == noErr) { + LMSetSFSaveDisk(-vol); + LMSetCurDirStore(dirid); + } + } init_ucs(); } @@ -237,13 +280,16 @@ static void mac_contentclick(WindowPtr window, EventRecord *event) { mac_clickterm(window, event); break; case wAbout: - if (DialogSelect(event, &(DialogPtr)window, &item)) + if (DialogSelect(event, &window, &item)) switch (item) { case wiAboutLicence: - /* XXX: Do something */ + mac_openlicence(); break; } break; + case wSettings: + mac_clickdlg(window, event); + break; } } @@ -264,6 +310,9 @@ static void mac_activatewindow(WindowPtr window, EventRecord *event) { case wTerminal: mac_activateterm(window, active); break; + case wSettings: + mac_activatedlg(window, event); + break; case wAbout: mac_activateabout(window, event); break; @@ -290,14 +339,36 @@ static void mac_updatewindow(WindowPtr window) { mac_updateterm(window); break; case wAbout: + case wSettings: BeginUpdate(window); UpdateDialog(window, window->visRgn); EndUpdate(window); break; case wLicence: - /* Do something */ - break; + mac_updatelicence(window); + break; + } +} + +static void mac_updatelicence(WindowPtr window) +{ + Handle h; + int len; + long fondsize; + + SetPort(window); + BeginUpdate(window); + fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize); + TextFont(HiWord(fondsize)); + TextSize(LoWord(fondsize)); + h = Get1Resource('TEXT', wLicence); + len = GetResourceSizeOnDisk(h); + if (h != NULL) { + HLock(h); + TETextBox(*h, len, &window->portRect, teFlushDefault); + HUnlock(h); } + EndUpdate(window); } /* @@ -306,6 +377,7 @@ static void mac_updatewindow(WindowPtr window) { */ static int mac_windowtype(WindowPtr window) { int kind; + long refcon; if (window == NULL) return wNone; @@ -314,7 +386,11 @@ static int mac_windowtype(WindowPtr window) { return wDA; if (GetWVariant(window) == zoomDocProc) return wTerminal; - return GetWRefCon(window); + refcon = GetWRefCon(window); + if (refcon < 1024) + return refcon; + else + return wSettings; } /* @@ -368,6 +444,9 @@ static void mac_menucommand(long result) { case iNew: mac_newsession(); goto done; + case iOpen: + mac_opensession(); + goto done; case iClose: mac_closewindow(window); goto done; @@ -398,17 +477,28 @@ static void mac_openabout(void) { SelectWindow(windows.about); else { windows.about = GetNewDialog(wAbout, NULL, (WindowPtr)-1); - /* XXX check we're using the right resource file? */ - vers = (VersRecHndl)GetResource('vers', 1); - assert(vers != NULL && *vers != NULL); - longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1; - GetDialogItem(windows.about, wiAboutVersion, &itemtype, &item, &box); - assert(itemtype & kStaticTextDialogItem); - SetDialogItemText(item, longvers); + vers = (VersRecHndl)Get1Resource('vers', 1); + if (vers != NULL && *vers != NULL) { + longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1; + GetDialogItem(windows.about, wiAboutVersion, + &itemtype, &item, &box); + assert(itemtype & kStaticTextDialogItem); + SetDialogItemText(item, longvers); + } ShowWindow(windows.about); } } +static void mac_openlicence(void) { + + if (windows.licence) + SelectWindow(windows.licence); + else { + windows.licence = GetNewWindow(wLicence, NULL, (WindowPtr)-1); + ShowWindow(windows.licence); + } +} + static void mac_closewindow(WindowPtr window) { switch (mac_windowtype(window)) { @@ -422,6 +512,10 @@ static void mac_closewindow(WindowPtr window) { windows.about = NULL; CloseWindow(window); break; + case wLicence: + windows.licence = NULL; + CloseWindow(window); + break; default: CloseWindow(window); break; @@ -499,6 +593,10 @@ static void mac_adjustcursor(RgnHandle cursrgn) { static void mac_shutdown(void) { +#if !TARGET_RT_MAC_CFM + if (mac_gestalts.encvvers != 0) + TerminateUnicodeConverter(); +#endif exit(0); } @@ -511,7 +609,7 @@ void fatalbox(char *fmt, ...) { stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); va_end(ap); ParamText(stuff, NULL, NULL, NULL); - StopAlert(128, nil); + StopAlert(128, NULL); exit(1); } @@ -524,7 +622,7 @@ void modalfatalbox(char *fmt, ...) { stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); va_end(ap); ParamText(stuff, NULL, NULL, NULL); - StopAlert(128, nil); + StopAlert(128, NULL); exit(1); }