X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/cef180abf5f4c4c49e52c2743d981040219407e9..0ec4b50ff9d82409f851ea04b6587c42f97f1bdb:/mac/macdlg.c diff --git a/mac/macdlg.c b/mac/macdlg.c index 56f2d9a8..ad7a1ffa 100644 --- a/mac/macdlg.c +++ b/mac/macdlg.c @@ -1,4 +1,4 @@ -/* $Id: macdlg.c,v 1.9 2003/02/01 23:55:00 ben Exp $ */ +/* $Id: macdlg.c,v 1.12 2003/02/15 16:22:15 ben Exp $ */ /* * Copyright (c) 2002 Ben Harris * All rights reserved. @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -45,9 +46,15 @@ #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); + void mac_newsession(void) { Session *s; + WinInfo *wi; /* This should obviously be initialised by other means */ s = smalloc(sizeof(*s)); @@ -58,13 +65,21 @@ void mac_newsession(void) s->settings_window = GetDialogWindow(GetNewDialog(wSettings, NULL, (WindowPtr)-1)); - SetWRefCon(s->settings_window, (long)s); + wi = smalloc(sizeof(*wi)); + memset(wi, 0, sizeof(*wi)); + wi->s = s; + wi->wtype = wSettings; + wi->update = &mac_updatedlg; + wi->click = &mac_clickdlg; + wi->activate = &mac_activatedlg; + wi->adjustmenus = &mac_adjustdlgmenus; + SetWRefCon(s->settings_window, (long)wi); ShowWindow(s->settings_window); } void mac_dupsession(void) { - Session *s1 = (Session *)GetWRefCon(FrontWindow()); + Session *s1 = mac_windowsession(FrontWindow()); Session *s2; s2 = smalloc(sizeof(*s2)); @@ -112,23 +127,74 @@ static OSErr mac_opensessionfrom(FSSpec *fss) return err; } +static OSErr mac_openlist(AEDesc docs) +{ + OSErr err; + long ndocs, i; + FSSpec fss; + AEKeyword keywd; + DescType type; + Size size; + + err = AECountItems(&docs, &ndocs); + if (err != noErr) return err; + + for (i = 0; i < ndocs; i++) { + err = AEGetNthPtr(&docs, i + 1, typeFSS, + &keywd, &type, &fss, sizeof(fss), &size); + if (err != noErr) return err;; + err = mac_opensessionfrom(&fss); + if (err != noErr) return err; + } + return noErr; +} + void mac_opensession(void) { + + if (mac_gestalts.navsvers > 0) { + NavReplyRecord navr; + NavDialogOptions navopts; + NavTypeListHandle navtypes; + AEDesc defaultloc = { 'null', NULL }; + AEDesc *navdefault = NULL; + short vol; + long dirid; + FSSpec fss; + + if (NavGetDefaultDialogOptions(&navopts) != noErr) return; + /* XXX should we create sessions dir? */ + if (get_session_dir(FALSE, &vol, &dirid) == noErr && + FSMakeFSSpec(vol, dirid, NULL, &fss) == noErr && + AECreateDesc(typeFSS, &fss, sizeof(fss), &defaultloc) == noErr) + navdefault = &defaultloc; + /* Can't meaningfully preview a saved session yet */ + navopts.dialogOptionFlags &= ~kNavAllowPreviews; + navtypes = (NavTypeListHandle)GetResource('open', open_pTTY); + if (NavGetFile(navdefault, &navr, &navopts, NULL, NULL, NULL, navtypes, + NULL) == noErr && navr.validRecord) + mac_openlist(navr.selection); + NavDisposeReply(&navr); + if (navtypes != NULL) + ReleaseResource((Handle)navtypes); + } #if !TARGET_API_MAC_CARBON /* XXX Navigation Services */ - StandardFileReply sfr; - static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; + else { + StandardFileReply sfr; + static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; - StandardGetFile(NULL, 1, sftypes, &sfr); - if (!sfr.sfGood) return; + StandardGetFile(NULL, 1, sftypes, &sfr); + if (!sfr.sfGood) return; - mac_opensessionfrom(&sfr.sfFile); - /* XXX handle error */ + mac_opensessionfrom(&sfr.sfFile); + /* XXX handle error */ + } #endif } void mac_savesession(void) { - Session *s = (Session *)GetWRefCon(FrontWindow()); + Session *s = mac_windowsession(FrontWindow()); void *sesshandle; assert(s->hasfile); @@ -141,7 +207,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; @@ -180,12 +246,9 @@ pascal OSErr mac_aevt_odoc(const AppleEvent *req, AppleEvent *reply, long refcon) { DescType type; - AEKeyword keywd; Size size; AEDescList docs = { typeNull, NULL }; OSErr err; - long ndocs, i; - FSSpec fss; err = AEGetParamDesc(req, keyDirectObject, typeAEList, &docs); if (err != noErr) goto out; @@ -196,16 +259,7 @@ pascal OSErr mac_aevt_odoc(const AppleEvent *req, AppleEvent *reply, goto out; } - err = AECountItems(&docs, &ndocs); - if (err != noErr) goto out; - - for (i = 0; i < ndocs; i++) { - err = AEGetNthPtr(&docs, i + 1, typeFSS, - &keywd, &type, &fss, sizeof(fss), &size); - if (err != noErr) goto out; - err = mac_opensessionfrom(&fss); - if (err != noErr) goto out; - } + err = mac_openlist(docs); out: AEDisposeDesc(&docs); @@ -226,7 +280,7 @@ pascal OSErr mac_aevt_pdoc(const AppleEvent *req, AppleEvent *reply, return errAEEventNotHandled; } -void mac_activatedlg(WindowPtr window, EventRecord *event) +static void mac_activatedlg(WindowPtr window, EventRecord *event) { DialogItemType itemtype; Handle itemhandle; @@ -241,10 +295,10 @@ void mac_activatedlg(WindowPtr window, EventRecord *event) DialogSelect(event, &dialog, &item); } -void mac_clickdlg(WindowPtr window, EventRecord *event) +static 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)) @@ -256,6 +310,41 @@ void mac_clickdlg(WindowPtr window, EventRecord *event) } } +static void mac_updatedlg(WindowPtr window) +{ +#if TARGET_API_MAC_CARBON + RgnHandle rgn; +#endif + + BeginUpdate(window); +#if TARGET_API_MAC_CARBON + rgn = NewRgn(); + GetPortVisibleRegion(GetWindowPort(window), rgn); + UpdateDialog(GetDialogFromWindow(window), rgn); + DisposeRgn(rgn); +#else + UpdateDialog(window, window->visRgn); +#endif + EndUpdate(window); +} + +#if TARGET_API_MAC_CARBON +#define EnableItem EnableMenuItem +#define DisableItem DisableMenuItem +#endif +static void mac_adjustdlgmenus(WindowPtr window) +{ + MenuHandle menu; + + menu = GetMenuHandle(mFile); + DisableItem(menu, iSave); /* XXX enable if modified */ + EnableItem(menu, iSaveAs); + EnableItem(menu, iDuplicate); + + menu = GetMenuHandle(mEdit); + DisableItem(menu, 0); +} + /* * Local Variables: * c-file-style: "simon"