📄 mac.c
字号:
static void mac_menucommand(long result) {
short menu, item;
WindowPtr window;
#if !TARGET_API_MAC_CARBON
Str255 da;
#endif
menu = HiWord(result);
item = LoWord(result);
window = mac_frontwindow();
/* Things which do the same whatever window we're in. */
switch (menu) {
case mApple:
switch (item) {
case iAbout:
mac_openabout();
goto done;
#if !TARGET_API_MAC_CARBON
default:
GetMenuItemText(GetMenuHandle(mApple), item, da);
OpenDeskAcc(da);
goto done;
#endif
}
break;
case mFile:
switch (item) {
case iNew:
mac_newsession();
goto done;
case iOpen:
mac_opensession();
goto done;
case iChange:
mac_reconfig();
goto done;
case iClose:
mac_closewindow(window);
goto done;
case iSave:
mac_savesession();
goto done;
case iSaveAs:
mac_savesessionas();
goto done;
case iDuplicate:
mac_dupsession();
goto done;
case iQuit:
cleanup_exit(0);
goto done;
}
break;
}
/* If we get here, handling is up to window-specific code. */
if (window != NULL && mac_wininfo(window)->menu != NULL)
(*mac_wininfo(window)->menu)(window, menu, item);
done:
HiliteMenu(0);
}
static void mac_closewindow(WindowPtr window) {
switch (mac_windowtype(window)) {
#if !TARGET_API_MAC_CARBON
case wDA:
CloseDeskAcc(GetWindowKind(window));
break;
#endif
default:
if (mac_wininfo(window)->close != NULL)
(*mac_wininfo(window)->close)(window);
break;
}
}
static void mac_suspendresume(EventRecord *event)
{
WindowPtr front;
EventRecord fakeevent;
/*
* We're called either before we're suspended or after we're
* resumed, so we're the front application at this point.
*/
front = FrontWindow();
if (front != NULL) {
fakeevent.what = activateEvt;
fakeevent.message = (UInt32)front;
fakeevent.when = event->when;
fakeevent.where = event->where;
fakeevent.modifiers =
(event->message & resumeFlag) ? activeFlag : 0;
mac_activatewindow(front, &fakeevent);
}
}
static void mac_zoomwindow(WindowPtr window, short part) {
/* FIXME: do something */
}
/*
* Make the menus look right before the user gets to see them.
*/
#if TARGET_API_MAC_CARBON
#define EnableItem EnableMenuItem
#define DisableItem DisableMenuItem
#endif
static void mac_adjustmenus(void) {
WindowPtr window;
MenuHandle menu;
window = mac_frontwindow();
menu = GetMenuHandle(mApple);
EnableItem(menu, 0);
EnableItem(menu, iAbout);
menu = GetMenuHandle(mFile);
EnableItem(menu, 0);
EnableItem(menu, iNew);
if (window != NULL)
EnableItem(menu, iClose);
else
DisableItem(menu, iClose);
EnableItem(menu, iQuit);
if (window != NULL && mac_wininfo(window)->adjustmenus != NULL)
(*mac_wininfo(window)->adjustmenus)(window);
else {
DisableItem(menu, iChange);
DisableItem(menu, iSave);
DisableItem(menu, iSaveAs);
DisableItem(menu, iDuplicate);
menu = GetMenuHandle(mEdit);
DisableItem(menu, 0);
menu = GetMenuHandle(mWindow);
DisableItem(menu, 0); /* Until we get more than 1 item on it. */
}
DrawMenuBar();
}
/*
* Make sure the right cursor's being displayed.
*/
static void mac_adjustcursor(RgnHandle cursrgn) {
Point mouse;
WindowPtr window, front;
short part;
#if TARGET_API_MAC_CARBON
Cursor arrow;
RgnHandle visrgn;
#endif
GetMouse(&mouse);
LocalToGlobal(&mouse);
part = FindWindow(mouse, &window);
front = FrontWindow();
if (part != inContent || window == NULL || window != front) {
/* Cursor isn't in the front window, so switch to arrow */
#if TARGET_API_MAC_CARBON
GetQDGlobalsArrow(&arrow);
SetCursor(&arrow);
#else
SetCursor(&qd.arrow);
#endif
SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX);
if (front != NULL) {
#if TARGET_API_MAC_CARBON
visrgn = NewRgn();
GetPortVisibleRegion(GetWindowPort(front), visrgn);
DiffRgn(cursrgn, visrgn, cursrgn);
DisposeRgn(visrgn);
#else
DiffRgn(cursrgn, front->visRgn, cursrgn);
#endif
}
} else {
if (mac_wininfo(window)->adjustcursor != NULL)
(*mac_wininfo(window)->adjustcursor)(window, mouse, cursrgn);
else {
#if TARGET_API_MAC_CARBON
GetQDGlobalsArrow(&arrow);
SetCursor(&arrow);
GetPortVisibleRegion(GetWindowPort(window), cursrgn);
#else
SetCursor(&qd.arrow);
CopyRgn(window->visRgn, cursrgn);
#endif
}
}
}
pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply,
long refcon)
{
DescType type;
Size size;
if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard,
&type, NULL, 0, &size) == noErr)
return errAEParamMissed;
borednow = 1;
return noErr;
}
void cleanup_exit(int status)
{
#if !TARGET_RT_MAC_CFM
if (mac_gestalts.encvvers != 0)
TerminateUnicodeConverter();
#endif
sk_cleanup();
exit(status);
}
/* This should only kill the current session, not the whole application. */
void connection_fatal(void *frontend, char *fmt, ...) {
va_list ap;
Str255 stuff;
Session *s = frontend;
va_start(ap, fmt);
/* We'd like stuff to be a Pascal string */
stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
va_end(ap);
ParamText(stuff, NULL, NULL, NULL);
StopAlert(128, NULL);
s->session_closed = TRUE;
if (s->cfg.close_on_exit == FORCE_ON)
mac_closewindow(s->window);
}
/* Null SSH agent client -- never finds an agent. */
int agent_exists(void)
{
return FALSE;
}
int agent_query(void *in, int inlen, void **out, int *outlen,
void (*callback)(void *, void *, int), void *callback_ctx)
{
*out = NULL;
*outlen = 0;
return 1;
}
/* Temporary null routines for testing. */
int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
char *keystr, char *fingerprint,
void (*callback)(void *ctx, int result), void *ctx)
{
Str255 pappname;
Str255 pfingerprint;
Str255 pkeytype;
Session *s = frontend;
int ret, alertret;
c2pstrcpy(pappname, appname);
c2pstrcpy(pkeytype, keytype);
c2pstrcpy(pfingerprint, fingerprint);
/*
* The alert shouldn't be modal, it should be movable modal, or
* a sheet in Aqua. Also, PuTTY might be in the background, in
* which case we should use the Notification Manager to wake up
* the user. In any case, we shouldn't hold up processing of
* other connections' data just because this one's waiting for
* the user.
*/
/* Verify the key against the cache */
ret = verify_host_key(host, port, keytype, keystr);
if (ret == 0) { /* success - key matched OK */
return 1;
} else if (ret == 2) { /* key was different */
ParamText(pappname, pkeytype, pfingerprint, NULL);
alertret=CautionAlert(wWrong, NULL);
if (alertret == 8) {
/* Cancel */
return 0;
} else if (alertret == 9) {
/* Connect Just Once */
return 1;
} else {
/* Update Key */
store_host_key(host, port, keytype, keystr);
return 1;
}
} else /* ret == 1 */ { /* key was absent */
ParamText(pkeytype, pfingerprint, pappname, NULL);
alertret=CautionAlert(wAbsent, NULL);
if (alertret == 7) {
/* Cancel */
return 0;
} else if (alertret == 8) {
/* Connect Just Once */
return 1;
} else {
/* Update Key */
store_host_key(host, port, keytype, keystr);
return 1;
}
}
}
int askalg(void *frontend, const char *algtype, const char *algname,
void (*callback)(void *ctx, int result), void *ctx)
{
return 0;
}
void old_keyfile_warning(void)
{
}
FontSpec platform_default_fontspec(char const *name)
{
FontSpec ret;
long smfs;
if (!strcmp(name, "Font")) {
smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize);
if (smfs == 0)
smfs = GetScriptVariable(smRoman, smScriptMonoFondSize);
if (smfs != 0) {
GetFontName(HiWord(smfs), ret.name);
if (ret.name[0] == 0)
memcpy(ret.name, "\pMonaco", 7);
ret.size = LoWord(smfs);
} else {
memcpy(ret.name, "\pMonaco", 7);
ret.size = 9;
}
ret.face = 0;
} else {
ret.name[0] = 0;
}
return ret;
}
Filename platform_default_filename(const char *name)
{
Filename ret;
if (!strcmp(name, "LogFileName"))
FSMakeFSSpec(0, 0, "\pputty.log", &ret.fss);
else
memset(&ret, 0, sizeof(ret));
return ret;
}
char *platform_default_s(char const *name)
{
return NULL;
}
int platform_default_i(char const *name, int def)
{
/* Non-raw cut and paste of line-drawing chars works badly on the
* current Unix stub implementation of the Unicode functions.
* So I'm going to temporarily set the default to raw mode so
* that the failure mode isn't quite so drastically horrid.
* When Unicode comes in, this can all be put right. */
if (!strcmp(name, "RawCNP"))
return 1;
return def;
}
void platform_get_x11_auth(char *display, int *proto,
unsigned char *data, int *datalen)
{
/* SGT: I have no idea whether Mac X servers need anything here. */
}
void update_specials_menu(void *frontend)
{
Session *s = frontend;
WindowPtr front;
front = mac_frontwindow();
if (front != NULL && mac_windowsession(front) == s)
mac_adjustmenus();
}
void notify_remote_exit(void *frontend)
{
Session *s = frontend;
int exitcode;
if (!s->session_closed &&
(exitcode = s->back->exitcode(s->backhandle)) >=0) {
s->session_closed = TRUE;
if (s->cfg.close_on_exit == FORCE_ON ||
(s->cfg.close_on_exit == AUTO && exitcode == 0)) {
mac_closewindow(s->window);
return;
}
/* The session's dead */
if (s->ldisc) {
ldisc_free(s->ldisc);
s->ldisc = NULL;
}
if (s->back) {
s->back->free(s->backhandle);
s->backhandle = NULL;
s->back = NULL;
update_specials_menu(s);
}
{
char title[100];
sprintf(title, "%.70s (inactive)", appname);
set_title(s, title);
}
}
}
/*
* Local Variables:
* c-file-style: "simon"
* End:
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -