From 217b88d1dad5aa3362e9e8c1af94b237933309a5 Mon Sep 17 00:00:00 2001 From: ben Date: Sun, 16 Feb 2003 14:27:37 +0000 Subject: [PATCH] Bring PuTTYgen into the world of object-oriented event handling. Also add a non-functional "generate" button the the key window. git-svn-id: svn://svn.tartarus.org/sgt/putty@2857 cda61777-01e9-0310-a592-d414129be87e --- Recipe | 2 +- mac/macpgen.c | 195 +++++++++++---------------------------------------------- mac/macpgen.r | 8 ++- mac/macpgkey.c | 57 ++++++++++++++++- mac/macpgrid.h | 3 +- 5 files changed, 99 insertions(+), 166 deletions(-) diff --git a/Recipe b/Recipe index 83da07fb..07bd56e0 100644 --- a/Recipe +++ b/Recipe @@ -161,4 +161,4 @@ PuTTYtel : [M] terminal wcwidth ldiscucs logging be_nossh mac macdlg macevlog + stricmp vsnprint PuTTYgen : [M] macpgen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version + sshrand macnoise sshsha macstore misc sshrsa sshdss macmisc sshpubk - + sshaes sshsh512 import macpgen.rsrc macpgkey + + sshaes sshsh512 import macpgen.rsrc macpgkey macabout diff --git a/mac/macpgen.c b/mac/macpgen.c index 16ef0550..2b1a3a7f 100644 --- a/mac/macpgen.c +++ b/mac/macpgen.c @@ -1,4 +1,4 @@ -/* $Id: macpgen.c,v 1.2 2003/02/15 14:20:43 ben Exp $ */ +/* $Id: macpgen.c,v 1.3 2003/02/16 14:27:37 ben Exp $ */ /* * Copyright (c) 1999, 2003 Ben Harris * All rights reserved. @@ -71,14 +71,10 @@ static void mac_event(EventRecord *); static void mac_contentclick(WindowPtr, EventRecord *); 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); @@ -299,106 +295,33 @@ static void mac_event(EventRecord *event) { } } -static void mac_contentclick(WindowPtr window, EventRecord *event) { - short item; - DialogRef dialog; +static void mac_contentclick(WindowPtr window, EventRecord *event) +{ - switch (mac_windowtype(window)) { - case wAbout: - dialog = GetDialogFromWindow(window); - if (DialogSelect(event, &dialog, &item)) - switch (item) { - case wiAboutLicence: - mac_openlicence(); - break; - } - break; - } + if (mac_wininfo(window)->click != NULL) + (*mac_wininfo(window)->click)(window, event); } -static void mac_growwindow(WindowPtr window, EventRecord *event) { +static void mac_growwindow(WindowPtr window, EventRecord *event) +{ - switch (mac_windowtype(window)) { - } + if (mac_wininfo(window)->grow != NULL) + (*mac_wininfo(window)->grow)(window, event); } -static void mac_activatewindow(WindowPtr window, EventRecord *event) { - int active; +static void mac_activatewindow(WindowPtr window, EventRecord *event) +{ - active = (event->modifiers & activeFlag) != 0; mac_adjustmenus(); - switch (mac_windowtype(window)) { - case wAbout: - mac_activateabout(window, event); - break; - } -} - -static void mac_activateabout(WindowPtr window, EventRecord *event) { - DialogRef dialog; - DialogItemType itemtype; - Handle itemhandle; - short item; - Rect itemrect; - int active; - - dialog = GetDialogFromWindow(window); - active = (event->modifiers & activeFlag) != 0; - GetDialogItem(dialog, wiAboutLicence, &itemtype, &itemhandle, &itemrect); - HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); - DialogSelect(event, &dialog, &item); + if (mac_wininfo(window)->activate != NULL) + (*mac_wininfo(window)->activate)(window, event); } static void mac_updatewindow(WindowPtr window) { -#if TARGET_API_MAC_CARBON - RgnHandle rgn; -#endif - switch (mac_windowtype(window)) { - case wAbout: - 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); - break; - case wLicence: - mac_updatelicence(window); - break; - } -} - -static void mac_updatelicence(WindowPtr window) -{ - Handle h; - int len; - long fondsize; - Rect textrect; - - SetPort((GrafPtr)GetWindowPort(window)); - BeginUpdate(window); - fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize); - TextFont(HiWord(fondsize)); - TextSize(LoWord(fondsize)); - h = Get1Resource('TEXT', wLicence); - len = GetResourceSizeOnDisk(h); -#if TARGET_API_MAC_CARBON - GetPortBounds(GetWindowPort(window), &textrect); -#else - textrect = window->portRect; -#endif - if (h != NULL) { - HLock(h); - TETextBox(*h, len, &textrect, teFlushDefault); - HUnlock(h); - } - EndUpdate(window); + if (mac_wininfo(window)->update != NULL) + (*mac_wininfo(window)->update)(window); } /* @@ -417,7 +340,8 @@ static int mac_windowtype(WindowPtr window) /* * Handle a key press */ -static void mac_keypress(EventRecord *event) { +static void mac_keypress(EventRecord *event) +{ WindowPtr window; window = FrontWindow(); @@ -425,12 +349,13 @@ static void mac_keypress(EventRecord *event) { mac_adjustmenus(); mac_menucommand(MenuKey(event->message & charCodeMask)); } else { - switch (mac_windowtype(window)) { - } + if (mac_wininfo(window)->key != NULL) + (*mac_wininfo(window)->key)(window, event); } } -static void mac_menucommand(long result) { +static void mac_menucommand(long result) +{ short menu, item; WindowPtr window; #if !TARGET_API_MAC_CARBON @@ -470,57 +395,15 @@ static void mac_menucommand(long result) { break; } /* If we get here, handling is up to window-specific code. */ - switch (mac_windowtype(window)) { - } + if (mac_wininfo(window)->menu != NULL) + (*mac_wininfo(window)->menu)(window, menu, item); + done: HiliteMenu(0); } -static void mac_openabout(void) { - DialogItemType itemtype; - Handle item; - 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; - GetDialogItem(GetDialogFromWindow(windows.about), wiAboutVersion, - &itemtype, &item, &box); - assert(itemtype & kStaticTextDialogItem); - SetDialogItemText(item, longvers); - } - ShowWindow(windows.about); - } -} - -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); - } -} - -static void mac_closewindow(WindowPtr window) { +static void mac_closewindow(WindowPtr window) +{ switch (mac_windowtype(window)) { #if !TARGET_API_MAC_CARBON @@ -528,14 +411,9 @@ static void mac_closewindow(WindowPtr window) { CloseDeskAcc(GetWindowKind(window)); break; #endif - case wAbout: - windows.about = NULL; - DisposeDialog(GetDialogFromWindow(window)); - break; - case wLicence: - windows.licence = NULL; - DisposeWindow(window); - break; + default: + if (mac_wininfo(window)->close != NULL) + (*mac_wininfo(window)->close)(window); } } @@ -569,15 +447,15 @@ static void mac_adjustmenus(void) { DisableItem(menu, iClose); EnableItem(menu, iQuit); - switch (mac_windowtype(window)) { - default: + if (mac_wininfo(window)->adjustmenus != NULL) + (*mac_wininfo(window)->adjustmenus)(window); + else { DisableItem(menu, iSave); DisableItem(menu, iSaveAs); menu = GetMenuHandle(mEdit); DisableItem(menu, 0); menu = GetMenuHandle(mWindow); DisableItem(menu, 0); /* Until we get more than 1 item on it. */ - break; } DrawMenuBar(); } @@ -585,7 +463,8 @@ static void mac_adjustmenus(void) { /* * Make sure the right cursor's being displayed. */ -static void mac_adjustcursor(RgnHandle cursrgn) { +static void mac_adjustcursor(RgnHandle cursrgn) +{ Point mouse; WindowPtr window, front; short part; @@ -618,8 +497,9 @@ static void mac_adjustcursor(RgnHandle cursrgn) { #endif } } else { - switch (mac_windowtype(window)) { - default: + if (mac_wininfo(window)->adjustcursor != NULL) + (*mac_wininfo(window)->adjustcursor)(window, mouse, cursrgn); + else { #if TARGET_API_MAC_CARBON GetQDGlobalsArrow(&arrow); SetCursor(&arrow); @@ -628,7 +508,6 @@ static void mac_adjustcursor(RgnHandle cursrgn) { SetCursor(&qd.arrow); CopyRgn(window->visRgn, cursrgn); #endif - break; } } } diff --git a/mac/macpgen.r b/mac/macpgen.r index ea0e25df..036b14f0 100644 --- a/mac/macpgen.r +++ b/mac/macpgen.r @@ -1,4 +1,4 @@ -/* $Id: macpgen.r,v 1.2 2003/02/15 14:20:43 ben Exp $ */ +/* $Id: macpgen.r,v 1.3 2003/02/16 14:27:37 ben Exp $ */ /* * Copyright (c) 1999, 2002 Ben Harris * All rights reserved. @@ -448,8 +448,8 @@ resource 'DLOG' (wKey, "key", purgeable) { noGrowDocProc, invisible, goAway, - wAbout, /* RefCon -- identifies the window to PuTTY */ - wAbout, /* DITL ID */ + wKey, /* RefCon -- identifies the window to PuTTY */ + wKey, /* DITL ID */ "untitled", staggerParentWindowScreen }; @@ -462,6 +462,8 @@ resource 'dlgx' (wKey, "key", purgeable) { resource 'DITL' (wKey, "key", purgeable) { { + { 13, 13, 33, 227 }, + Button { enabled, "Generate" }, } }; diff --git a/mac/macpgkey.c b/mac/macpgkey.c index 9558fd7e..c65d9397 100644 --- a/mac/macpgkey.c +++ b/mac/macpgkey.c @@ -1,4 +1,4 @@ -/* $Id: macpgkey.c,v 1.1 2003/02/16 13:03:12 ben Exp $ */ +/* $Id: macpgkey.c,v 1.2 2003/02/16 14:27:37 ben Exp $ */ /* * Copyright (c) 2003 Ben Harris * All rights reserved. @@ -35,6 +35,54 @@ #include "mac.h" #include "macpgrid.h" +static void mac_clickkey(WindowPtr window, EventRecord *event) +{ + short item; + DialogRef dialog; + + dialog = GetDialogFromWindow(window); + if (DialogSelect(event, &dialog, &item)) + switch (item) { + case wiKeyGenerate: + /* Do something */ + break; + } +} + +static void mac_activatekey(WindowPtr window, EventRecord *event) +{ + DialogRef dialog; + DialogItemType itemtype; + Handle itemhandle; + short item; + Rect itemrect; + int active; + + dialog = GetDialogFromWindow(window); + active = (event->modifiers & activeFlag) != 0; + GetDialogItem(dialog, wiKeyGenerate, &itemtype, &itemhandle, &itemrect); + HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); + DialogSelect(event, &dialog, &item); +} + +static void mac_updatekey(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); +} + void mac_newkey(void) { KeyState *ks; @@ -46,8 +94,11 @@ void mac_newkey(void) memset(wi, 0, sizeof(*wi)); wi->ks = ks; wi->wtype = wKey; - SetWRefCon(ks->box, (long)wi); - ShowWindow(ks->box); + wi->update = &mac_updatekey; + wi->click = &mac_clickkey; + wi->activate = &mac_activatekey; + SetWRefCon(GetDialogWindow(ks->box), (long)wi); + ShowWindow(GetDialogWindow(ks->box)); } /* diff --git a/mac/macpgrid.h b/mac/macpgrid.h index 5293bb0a..bc44def6 100644 --- a/mac/macpgrid.h +++ b/mac/macpgrid.h @@ -1,4 +1,4 @@ -/* $Id: macpgrid.h,v 1.2 2003/02/15 14:20:43 ben Exp $ */ +/* $Id: macpgrid.h,v 1.3 2003/02/16 14:27:37 ben Exp $ */ /* * macpgrid.h -- Mac resource IDs for PuTTYgen @@ -43,3 +43,4 @@ #define wiAboutVersion 3 #define wLicence 131 #define wKey 134 +#define wiKeyGenerate 1 -- 2.11.0