Be careful not to try to get information from windows we don't own, or that

don't exist at all.  Also a small PuTTYgen change that I can't be bothered
to filter out of this commit.

[originally from svn r2874]
This commit is contained in:
Ben Harris 2003-02-20 22:31:52 +00:00
Родитель fb90fa8650
Коммит f53c998569
3 изменённых файлов: 33 добавлений и 8 удалений

Просмотреть файл

@ -1,4 +1,4 @@
/* $Id: mac.c,v 1.49 2003/02/15 16:22:15 ben Exp $ */
/* $Id: mac.c,v 1.50 2003/02/20 22:31:52 ben Exp $ */
/*
* Copyright (c) 1999, 2003 Ben Harris
* All rights reserved.
@ -377,7 +377,7 @@ static int mac_windowtype(WindowPtr window)
static void mac_keypress(EventRecord *event) {
WindowPtr window;
window = FrontWindow();
window = mac_frontwindow();
/*
* Check for a command-key combination, but ignore it if it counts
* as a meta-key combination and we're in a terminal window.
@ -388,7 +388,7 @@ static void mac_keypress(EventRecord *event) {
mac_adjustmenus();
mac_menucommand(MenuKey(event->message & charCodeMask));
} else {
if (mac_wininfo(window)->key != NULL)
if (window != NULL && mac_wininfo(window)->key != NULL)
(*mac_wininfo(window)->key)(window, event);
}
}
@ -402,7 +402,7 @@ static void mac_menucommand(long result) {
menu = HiWord(result);
item = LoWord(result);
window = FrontWindow();
window = mac_frontwindow();
/* Things which do the same whatever window we're in. */
switch (menu) {
case mApple:
@ -445,7 +445,7 @@ static void mac_menucommand(long result) {
break;
}
/* If we get here, handling is up to window-specific code. */
if (mac_wininfo(window)->menu != NULL)
if (window != NULL && mac_wininfo(window)->menu != NULL)
(*mac_wininfo(window)->menu)(window, menu, item);
done:
@ -483,7 +483,7 @@ static void mac_adjustmenus(void) {
WindowPtr window;
MenuHandle menu;
window = FrontWindow();
window = mac_frontwindow();
menu = GetMenuHandle(mApple);
EnableItem(menu, 0);
EnableItem(menu, iAbout);
@ -497,7 +497,7 @@ static void mac_adjustmenus(void) {
DisableItem(menu, iClose);
EnableItem(menu, iQuit);
if (mac_wininfo(window)->adjustmenus != NULL)
if (window != NULL && mac_wininfo(window)->adjustmenus != NULL)
(*mac_wininfo(window)->adjustmenus)(window);
else {
DisableItem(menu, iSave);

Просмотреть файл

@ -112,10 +112,16 @@ extern Session *sesslist;
/* PuTTYgen per-window state */
typedef struct KeyState {
DialogPtr box;
int collecting_entropy;
int entropy_got, entropy_required, entropy_size;
unsigned *entropy;
ControlHandle progress;
} KeyState;
#define mac_windowkey(w) (((WinInfo *)GetWRefCon(w))->ks)
/* from macmisc.c */
extern WindowPtr mac_frontwindow(void);
/* from macdlg.c */
extern void mac_newsession(void);
extern void mac_dupsession(void);

Просмотреть файл

@ -1,4 +1,4 @@
/* $Id: macmisc.c,v 1.1 2003/02/12 23:53:15 ben Exp $ */
/* $Id: macmisc.c,v 1.2 2003/02/20 22:31:52 ben Exp $ */
/*
* Copyright (c) 1999, 2003 Ben Harris
* All rights reserved.
@ -28,6 +28,8 @@
#include <MacTypes.h>
#include <Dialogs.h>
#include <Files.h>
#include <MacWindows.h>
#include <Processes.h>
#include <Quickdraw.h>
#include <TextUtils.h>
@ -35,6 +37,7 @@
#include <stdio.h>
#include "putty.h"
#include "mac.h"
#if TARGET_API_MAC_CARBON
/*
@ -48,6 +51,22 @@ const CFAllocatorRef kCFAllocatorDefault = NULL;
QDGlobals qd;
#endif
/*
* Like FrontWindow(), but return NULL if we aren't the front process
* (i.e. the front window isn't one of ours).
*/
WindowPtr mac_frontwindow(void)
{
ProcessSerialNumber frontpsn;
ProcessSerialNumber curpsn = { 0, kCurrentProcess };
Boolean result;
GetFrontProcess(&frontpsn);
if (SameProcess(&frontpsn, &curpsn, &result) == noErr && result)
return FrontWindow();
return NULL;
}
void fatalbox(char *fmt, ...) {
va_list ap;
Str255 stuff;