X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/1ddda1ca78c0458141b45197544597c566184b6f..12745e35f6aa5ba7b1a89afe6d5249d8ca46dd37:/macosx/osxwin.m diff --git a/macosx/osxwin.m b/macosx/osxwin.m index a54f771f..59cc4bf9 100644 --- a/macosx/osxwin.m +++ b/macosx/osxwin.m @@ -207,6 +207,8 @@ { NSRect rect = { {0,0}, {0,0} }; + alert_ctx = NULL; + cfg = aCfg; /* structure copy */ init_ucs(&ucsdata, cfg.line_codepage, cfg.utf8_override, @@ -252,6 +254,7 @@ if (realhost) sfree(realhost); /* FIXME: do something with this */ } + back->provide_logctx(backhandle, logctx); /* * Create a line discipline. (This must be done after creating @@ -297,6 +300,8 @@ */ [self center]; /* :-) */ + exited = FALSE; + return self; } @@ -307,6 +312,17 @@ * terminal, the backend, the ldisc, the logctx, you name it. * Do so. */ + sfree(alert_ctx); + if (back) + back->free(backhandle); + if (ldisc) + ldisc_free(ldisc); + /* ldisc must be freed before term, since ldisc_free expects term + * still to be around. */ + if (logctx) + log_free(logctx); + if (term) + term_free(term); [super dealloc]; } @@ -342,7 +358,7 @@ char coutput[32]; int use_coutput = FALSE, special = FALSE, start, end; -printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m); +//printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m); /* * FIXME: Alt+numberpad codes. @@ -778,6 +794,97 @@ printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m); return term_data(term, is_stderr, data, len); } +- (void)startAlert:(NSAlert *)alert + withCallback:(void (*)(void *, int))callback andCtx:(void *)ctx +{ + if (alert_ctx || alert_qhead) { + /* + * Queue this alert to be shown later. + */ + struct alert_queue *qitem = snew(struct alert_queue); + qitem->next = NULL; + qitem->alert = alert; + qitem->callback = callback; + qitem->ctx = ctx; + if (alert_qtail) + alert_qtail->next = qitem; + else + alert_qhead = qitem; + alert_qtail = qitem; + } else { + alert_callback = callback; + alert_ctx = ctx; /* NB this is assumed to need freeing! */ + [alert beginSheetModalForWindow:self modalDelegate:self + didEndSelector:@selector(alertSheetDidEnd:returnCode:contextInfo:) + contextInfo:NULL]; + } +} + +- (void)alertSheetDidEnd:(NSAlert *)alert returnCode:(int)returnCode + contextInfo:(void *)contextInfo +{ + [self performSelectorOnMainThread: + @selector(alertSheetDidFinishEnding:) + withObject:[NSNumber numberWithInt:returnCode] + waitUntilDone:NO]; +} + +- (void)alertSheetDidFinishEnding:(id)object +{ + int returnCode = [object intValue]; + + alert_callback(alert_ctx, returnCode); /* transfers ownership of ctx */ + + /* + * If there's an alert in our queue (either already or because + * the callback just queued it), start it. + */ + if (alert_qhead) { + struct alert_queue *qnext; + + alert_callback = alert_qhead->callback; + alert_ctx = alert_qhead->ctx; + [alert_qhead->alert beginSheetModalForWindow:self modalDelegate:self + didEndSelector:@selector(alertSheetDidEnd:returnCode:contextInfo:) + contextInfo:NULL]; + + qnext = alert_qhead->next; + sfree(alert_qhead); + alert_qhead = qnext; + if (!qnext) + alert_qtail = NULL; + } else { + alert_ctx = NULL; + } +} + +- (void)notifyRemoteExit +{ + int exitcode; + + if (!exited && (exitcode = back->exitcode(backhandle)) >= 0) + [self endSession:(exitcode == 0)]; +} + +- (void)endSession:(int)clean +{ + exited = TRUE; + if (ldisc) { + ldisc_free(ldisc); + ldisc = NULL; + } + if (back) { + back->free(backhandle); + backhandle = NULL; + back = NULL; + //FIXME: update specials menu; + } + if (cfg.close_on_exit == FORCE_ON || + (cfg.close_on_exit == AUTO && clean)) + [self close]; + // FIXME: else show restart menu item +} + @end int from_backend(void *frontend, int is_stderr, const char *data, int len) @@ -791,23 +898,11 @@ void frontend_keypress(void *handle) /* FIXME */ } -void connection_fatal(void *frontend, char *p, ...) -{ - //SessionWindow *win = (SessionWindow *)frontend; - /* FIXME: proper OS X GUI stuff */ - va_list ap; - fprintf(stderr, "FATAL ERROR: "); - va_start(ap, p); - vfprintf(stderr, p, ap); - va_end(ap); - fputc('\n', stderr); - exit(1); -} - void notify_remote_exit(void *frontend) { - //SessionWindow *win = (SessionWindow *)frontend; - /* FIXME */ + SessionWindow *win = (SessionWindow *)frontend; + + [win notifyRemoteExit]; } void ldisc_update(void *frontend, int echo, int edit)