1 /* $Id: macterm.c,v 1.67 2003/02/04 02:08:03 ben Exp $ */
3 * Copyright (c) 1999 Simon Tatham
4 * Copyright (c) 1999, 2002 Ben Harris
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * macterm.c -- Macintosh terminal front-end
35 #include <ControlDefinitions.h>
40 #include <MacMemory.h>
41 #include <MacWindows.h>
42 #include <MixedMode.h>
44 #include <Quickdraw.h>
45 #include <QuickdrawText.h>
46 #include <Resources.h>
50 #include <TextCommon.h>
51 #include <ToolUtils.h>
52 #include <UnicodeConverter.h>
66 #define NCOLOURS (lenof(((Config *)0)->colours))
69 #define DEFAULT_FG_BOLD 17
71 #define DEFAULT_BG_BOLD 19
75 #define PTOCC(x) ((x) < 0 ? -(-(x - s->font_width - 1) / s->font_width) : \
77 #define PTOCR(y) ((y) < 0 ? -(-(y - s->font_height - 1) / s->font_height) : \
80 static void mac_initfont(Session *);
81 static pascal OSStatus uni_to_font_fallback(UniChar *, ByteCount, ByteCount *,
82 TextPtr, ByteCount, ByteCount *,
84 ConstUnicodeMappingPtr);
85 static void mac_initpalette(Session *);
86 static void mac_adjustwinbg(Session *);
87 static void mac_adjustsize(Session *, int, int);
88 static void mac_drawgrowicon(Session *s);
89 static pascal void mac_growtermdraghook(void);
90 static pascal void mac_scrolltracker(ControlHandle, short);
91 static pascal void do_text_for_device(short, short, GDHandle, long);
92 static void text_click(Session *, EventRecord *);
94 void pre_paint(Session *s);
95 void post_paint(Session *s);
97 void mac_startsession(Session *s)
105 * Select protocol. This is farmed out into a table in a
106 * separate file to enable an ssh-free variant.
109 for (i = 0; backends[i].backend != NULL; i++)
110 if (backends[i].protocol == s->cfg.protocol) {
111 s->back = backends[i].backend;
115 fatalbox("Unsupported protocol number found");
117 /* XXX: Own storage management? */
119 s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1);
121 s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
122 SetWRefCon(s->window, (long)s);
123 s->scrollbar = GetNewControl(cVScroll, s->window);
124 s->term = term_init(&s->cfg, &s->ucsdata, s);
128 if (HAVE_COLOR_QD()) {
129 /* Set to FALSE to not get palette updates in the background. */
130 SetPalette(s->window, s->palette, TRUE);
131 ActivatePalette(s->window);
134 s->logctx = log_init(s, &s->cfg);
135 term_provide_logctx(s->term, s->logctx);
137 errmsg = s->back->init(s->term, &s->backhandle, &s->cfg, s->cfg.host,
138 s->cfg.port, &s->realhost, s->cfg.tcp_nodelay);
140 fatalbox("%s", errmsg);
141 s->back->provide_logctx(s->backhandle, s->logctx);
142 set_title(s, s->realhost);
144 term_provide_resize_fn(s->term, s->back->size, s->backhandle);
146 mac_adjustsize(s, s->cfg.height, s->cfg.width);
147 term_size(s->term, s->cfg.height, s->cfg.width, s->cfg.savelines);
149 s->ldisc = ldisc_create(&s->cfg, s->term, s->back, s->backhandle, s);
150 ldisc_send(s->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */
152 ShowWindow(s->window);
156 s->next->prev = &s->next;
161 * Try to work out a horizontal scaling factor for the current font
162 * that will give a chracter width of wantwidth. Return it in numer
163 * and denom (suitable for passing to StdText()).
165 static void mac_workoutfontscale(Session *s, int wantwidth,
166 Point *numerp, Point *denomp)
168 Point numer, denom, tmpnumer, tmpdenom;
170 const char text = 'W';
172 #if TARGET_API_MAC_CARBON
173 CQDProcsPtr gp = GetPortGrafProcs(GetWindowPort(s->window));;
175 QDProcsPtr gp = s->window->grafProcs;;
178 numer.v = denom.v = 1; /* always */
179 numer.h = denom.h = 1;
180 for (i = 0; i < 3; i++) {
184 gotwidth = InvokeQDTxMeasUPP(1, &text, &tmpnumer, &tmpdenom, &fi,
187 gotwidth = StdTxMeas(1, &text, &tmpnumer, &tmpdenom, &fi);
188 /* The result of StdTxMeas must be scaled by the factors it returns. */
189 gotwidth = FixRound(FixMul(gotwidth << 16,
190 FixRatio(tmpnumer.h, tmpdenom.h)));
191 if (gotwidth == wantwidth)
193 numer.h *= wantwidth;
200 static UnicodeToTextFallbackUPP uni_to_font_fallback_upp;
202 static void mac_initfont(Session *s) {
207 SetPort((GrafPtr)GetWindowPort(s->window));
208 GetFNum(s->cfg.font.name, &s->fontnum);
209 TextFont(s->fontnum);
210 TextFace(s->cfg.font.face);
211 TextSize(s->cfg.font.size);
213 s->font_width = CharWidth('W'); /* Well, it's what NCSA uses. */
214 s->font_ascent = fi.ascent;
215 s->font_leading = fi.leading;
216 s->font_height = s->font_ascent + fi.descent + s->font_leading;
217 mac_workoutfontscale(s, s->font_width,
218 &s->font_stdnumer, &s->font_stddenom);
219 mac_workoutfontscale(s, s->font_width * 2,
220 &s->font_widenumer, &s->font_widedenom);
221 TextSize(s->cfg.font.size * 2);
222 mac_workoutfontscale(s, s->font_width * 2,
223 &s->font_bignumer, &s->font_bigdenom);
224 TextSize(s->cfg.font.size);
225 if (!s->cfg.bold_colour) {
227 s->font_boldadjust = s->font_width - CharWidth('W');
229 s->font_boldadjust = 0;
231 if (s->uni_to_font != NULL)
232 DisposeUnicodeToTextInfo(&s->uni_to_font);
233 if (mac_gestalts.encvvers != 0 &&
234 UpgradeScriptInfoToTextEncoding(kTextScriptDontCare,
235 kTextLanguageDontCare,
236 kTextRegionDontCare, s->cfg.font.name,
238 CreateUnicodeToTextInfoByEncoding(enc, &s->uni_to_font) == noErr) {
239 if (uni_to_font_fallback_upp == NULL)
240 uni_to_font_fallback_upp =
241 NewUnicodeToTextFallbackUPP(&uni_to_font_fallback);
242 fbflags = kUnicodeFallbackCustomOnly;
243 if (mac_gestalts.uncvattr & kTECAddFallbackInterruptMask)
244 fbflags |= kUnicodeFallbackInterruptSafeMask;
245 if (SetFallbackUnicodeToText(s->uni_to_font,
246 uni_to_font_fallback_upp, fbflags, NULL) != noErr) {
247 DisposeUnicodeToTextInfo(&s->uni_to_font);
254 s->uni_to_font = NULL;
255 p2cstrcpy(cfontname, s->cfg.font.name);
257 charset_from_macenc(FontToScript(s->fontnum),
258 GetScriptManagerVariable(smRegionCode),
259 mac_gestalts.sysvers, cfontname);
262 mac_adjustsize(s, s->term->rows, s->term->cols);
265 static pascal OSStatus uni_to_font_fallback(UniChar *ucp,
266 ByteCount ilen, ByteCount *iusedp, TextPtr obuf, ByteCount olen,
267 ByteCount *ousedp, LogicalAddress cookie, ConstUnicodeMappingPtr mapping)
271 return kTECOutputBufferFullStatus;
273 * What I'd _like_ to do here is to somehow generate the
274 * missing-character glyph that every font is required to have.
275 * Unfortunately (and somewhat surprisingly), I can't find any way
276 * to actually ask for it explicitly. Bah.
285 * Called every time round the event loop.
287 void mac_pollterm(void)
291 for (s = sesslist; s != NULL; s = s->next) {
293 term_update(s->term);
298 * To be called whenever the window size changes.
299 * rows and cols should be desired values.
300 * It's assumed the terminal emulator will be informed, and will set rows
303 static void mac_adjustsize(Session *s, int newrows, int newcols) {
304 int winwidth, winheight;
306 winwidth = newcols * s->font_width + 15;
307 winheight = newrows * s->font_height;
308 SizeWindow(s->window, winwidth, winheight, true);
309 HideControl(s->scrollbar);
310 MoveControl(s->scrollbar, winwidth - 15, -1);
311 SizeControl(s->scrollbar, 16, winheight - 13);
312 ShowControl(s->scrollbar);
316 static void mac_initpalette(Session *s) {
318 if (!HAVE_COLOR_QD())
321 * Most colours should be inhibited on 2bpp displays.
322 * Palette manager documentation suggests inhibiting all tolerant colours
323 * on greyscale displays.
325 #define PM_NORMAL ( pmTolerant | pmInhibitC2 | \
326 pmInhibitG2 | pmInhibitG4 | pmInhibitG8 )
327 #define PM_TOLERANCE 0x2000
328 s->palette = NewPalette(22, NULL, PM_NORMAL, PM_TOLERANCE);
329 if (s->palette == NULL)
330 fatalbox("Unable to create palette");
331 /* In 2bpp, these are the colours we want most. */
332 SetEntryUsage(s->palette, DEFAULT_BG,
333 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
334 SetEntryUsage(s->palette, DEFAULT_FG,
335 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
336 SetEntryUsage(s->palette, DEFAULT_FG_BOLD,
337 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
338 SetEntryUsage(s->palette, CURSOR_BG,
339 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
344 * Set the background colour of the window correctly. Should be
345 * called whenever the default background changes.
347 static void mac_adjustwinbg(Session *s) {
349 if (!HAVE_COLOR_QD())
352 if (mac_gestalts.windattr & gestaltWindowMgrPresent)
353 SetWindowContentColor(s->window,
354 &(*s->palette)->pmInfo[DEFAULT_BG].ciRGB);
358 #if !TARGET_API_MAC_CARBON
359 if (s->wctab == NULL)
360 s->wctab = (WCTabHandle)NewHandle(sizeof(**s->wctab));
361 if (s->wctab == NULL)
362 return; /* do without */
363 (*s->wctab)->wCSeed = 0;
364 (*s->wctab)->wCReserved = 0;
365 (*s->wctab)->ctSize = 0;
366 (*s->wctab)->ctTable[0].value = wContentColor;
367 (*s->wctab)->ctTable[0].rgb = (*s->palette)->pmInfo[DEFAULT_BG].ciRGB;
368 SetWinColor(s->window, s->wctab);
374 * Set the cursor shape correctly
376 void mac_adjusttermcursor(WindowPtr window, Point mouse, RgnHandle cursrgn) {
378 ControlHandle control;
381 #if TARGET_API_MAC_CARBON
387 SetPort((GrafPtr)GetWindowPort(window));
388 s = (Session *)GetWRefCon(window);
389 GlobalToLocal(&mouse);
390 part = FindControl(mouse, window, &control);
391 if (control == s->scrollbar) {
392 #if TARGET_API_MAC_CARBON
393 SetCursor(GetQDGlobalsArrow(&arrow));
394 RectRgn(cursrgn, GetControlBounds(s->scrollbar, &rect));
396 SetCursor(&qd.arrow);
397 RectRgn(cursrgn, &(*s->scrollbar)->contrlRect);
400 x = mouse.h / s->font_width;
401 y = mouse.v / s->font_height;
403 #if TARGET_API_MAC_CARBON
404 SetCursor(GetQDGlobalsArrow(&arrow));
406 SetCursor(&qd.arrow);
409 SetCursor(*GetCursor(iBeamCursor));
410 /* Ask for shape changes if we leave this character cell. */
411 SetRectRgn(cursrgn, x * s->font_width, y * s->font_height,
412 (x + 1) * s->font_width, (y + 1) * s->font_height);
414 #if TARGET_API_MAC_CARBON
416 GetPortVisibleRegion(GetWindowPort(window), visrgn);
417 SectRgn(cursrgn, visrgn, cursrgn);
420 SectRgn(cursrgn, window->visRgn, cursrgn);
425 * Enable/disable menu items based on the active terminal window.
427 #if TARGET_API_MAC_CARBON
428 #define DisableItem DisableMenuItem
429 #define EnableItem EnableMenuItem
431 void mac_adjusttermmenus(WindowPtr window) {
434 #if !TARGET_API_MAC_CARBON
438 s = (Session *)GetWRefCon(window);
439 menu = GetMenuHandle(mFile);
440 DisableItem(menu, iSave); /* XXX enable if modified */
441 EnableItem(menu, iSaveAs);
442 EnableItem(menu, iDuplicate);
443 menu = GetMenuHandle(mEdit);
445 DisableItem(menu, iUndo);
446 DisableItem(menu, iCut);
447 if (1/*s->term->selstate == SELECTED*/)
448 EnableItem(menu, iCopy);
450 DisableItem(menu, iCopy);
451 #if TARGET_API_MAC_CARBON
454 if (GetScrap(NULL, kScrapFlavorTypeText, &offset) == noTypeErr)
456 DisableItem(menu, iPaste);
458 EnableItem(menu, iPaste);
459 DisableItem(menu, iClear);
460 EnableItem(menu, iSelectAll);
463 void mac_menuterm(WindowPtr window, short menu, short item) {
466 s = (Session *)GetWRefCon(window);
474 term_do_paste(s->term);
480 void mac_clickterm(WindowPtr window, EventRecord *event) {
483 ControlHandle control;
485 static ControlActionUPP mac_scrolltracker_upp = NULL;
487 s = (Session *)GetWRefCon(window);
488 SetPort((GrafPtr)GetWindowPort(window));
489 mouse = event->where;
490 GlobalToLocal(&mouse);
491 part = FindControl(mouse, window, &control);
492 if (control == s->scrollbar) {
494 case kControlIndicatorPart:
495 if (TrackControl(control, mouse, NULL) == kControlIndicatorPart)
496 term_scroll(s->term, +1, GetControlValue(control));
498 case kControlUpButtonPart:
499 case kControlDownButtonPart:
500 case kControlPageUpPart:
501 case kControlPageDownPart:
502 if (mac_scrolltracker_upp == NULL)
503 mac_scrolltracker_upp =
504 NewControlActionUPP(&mac_scrolltracker);
505 TrackControl(control, mouse, mac_scrolltracker_upp);
509 text_click(s, event);
513 static void text_click(Session *s, EventRecord *event) {
516 static UInt32 lastwhen = 0;
517 static Session *lastsess = NULL;
518 static int lastrow = -1, lastcol = -1;
519 static Mouse_Action lastact = MA_NOTHING;
521 SetPort((GrafPtr)GetWindowPort(s->window));
522 localwhere = event->where;
523 GlobalToLocal(&localwhere);
525 col = PTOCC(localwhere.h);
526 row = PTOCR(localwhere.v);
527 if (event->when - lastwhen < GetDblTime() &&
528 row == lastrow && col == lastcol && s == lastsess)
529 lastact = (lastact == MA_CLICK ? MA_2CLK :
530 lastact == MA_2CLK ? MA_3CLK :
531 lastact == MA_3CLK ? MA_CLICK : MA_NOTHING);
534 term_mouse(s->term, MBT_LEFT,
535 event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
536 lastact, col, row, event->modifiers & shiftKey,
537 event->modifiers & controlKey, event->modifiers & optionKey);
541 while (StillDown()) {
542 GetMouse(&localwhere);
543 col = PTOCC(localwhere.h);
544 row = PTOCR(localwhere.v);
545 term_mouse(s->term, MBT_LEFT,
546 event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
547 MA_DRAG, col, row, event->modifiers & shiftKey,
548 event->modifiers & controlKey,
549 event->modifiers & optionKey);
550 if (row > s->term->rows - 1)
551 term_scroll(s->term, 0, row - (s->term->rows - 1));
553 term_scroll(s->term, 0, row);
555 term_mouse(s->term, MBT_LEFT,
556 event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
557 MA_RELEASE, col, row, event->modifiers & shiftKey,
558 event->modifiers & controlKey, event->modifiers & optionKey);
559 lastwhen = TickCount();
562 void write_clip(void *cookie, wchar_t *data, int len, int must_deselect)
564 #if !TARGET_API_MAC_CARBON
567 ByteCount iread, olen;
575 * See "Programming with the Text Encoding Conversion Manager"
576 * Appendix E for Unicode scrap conventions.
578 * XXX Maybe PICT scrap too.
580 if (ZeroScrap() != noErr)
582 PutScrap(len * sizeof(*data), kScrapFlavorTypeUnicode, data);
584 /* Replace LINE SEPARATORs with CR for TEXT output. */
585 for (i = 0; i < len; i++)
586 if (data[i] == 0x2028)
589 mactextbuf = smalloc(len); /* XXX DBCS */
590 if (s->uni_to_font != NULL) {
591 err = ConvertFromUnicodeToText(s->uni_to_font, len * sizeof(UniChar),
593 kUnicodeUseFallbacksMask,
595 len, &iread, &olen, mactextbuf);
596 if (err != noErr && err != kTECUsedFallbacksStatus)
598 } else if (s->font_charset != CS_NONE) {
600 olen = charset_from_unicode(&unitextptr, &len, mactextbuf, 1024,
601 s->font_charset, NULL, ".", 1);
604 PutScrap(olen, kScrapFlavorTypeText, mactextbuf);
607 stsz = offsetof(StScrpRec, scrpStyleTab) + sizeof(ScrpSTElement);
608 stsc = smalloc(stsz);
609 stsc->scrpNStyles = 1;
610 stsc->scrpStyleTab[0].scrpStartChar = 0;
611 stsc->scrpStyleTab[0].scrpHeight = s->font_height;
612 stsc->scrpStyleTab[0].scrpAscent = s->font_ascent;
613 stsc->scrpStyleTab[0].scrpFont = s->fontnum;
614 stsc->scrpStyleTab[0].scrpFace = 0;
615 stsc->scrpStyleTab[0].scrpSize = s->cfg.font.size;
616 stsc->scrpStyleTab[0].scrpColor.red = 0;
617 stsc->scrpStyleTab[0].scrpColor.green = 0;
618 stsc->scrpStyleTab[0].scrpColor.blue = 0;
619 PutScrap(stsz, kScrapFlavorTypeTextStyle, stsc);
624 void get_clip(void *frontend, wchar_t **p, int *lenp) {
625 #if TARGET_API_MAC_CARBON
628 Session *s = frontend;
629 static Handle h = NULL;
630 static wchar_t *data = NULL;
635 TextToUnicodeInfo scrap_to_uni;
636 ByteCount iread, olen;
650 if (GetScrap(NULL, kScrapFlavorTypeUnicode, &offset) > 0) {
654 GetScrap(h, kScrapFlavorTypeUnicode, &offset) / sizeof(**p);
657 } else if (GetScrap(NULL, kScrapFlavorTypeText, &offset) > 0) {
658 texth = NewHandle(0);
659 textlen = GetScrap(texth, kScrapFlavorTypeText, &offset);
661 data = smalloc(textlen * 2);
662 /* XXX should use 'styl' scrap if it's there. */
663 if (mac_gestalts.encvvers != 0 &&
664 UpgradeScriptInfoToTextEncoding(smSystemScript,
665 kTextLanguageDontCare,
666 kTextRegionDontCare, NULL,
668 CreateTextToUnicodeInfoByEncoding(enc, &scrap_to_uni) ==
670 err = ConvertFromTextToUnicode(scrap_to_uni, textlen,
671 *texth, 0, 0, NULL, NULL, NULL,
673 &iread, &olen, data);
674 DisposeTextToUnicodeInfo(&scrap_to_uni);
677 *lenp = olen / sizeof(**p);
684 charset_from_macenc(GetScriptManagerVariable(smSysScript),
685 GetScriptManagerVariable(smRegionCode),
686 mac_gestalts.sysvers, NULL);
687 if (charset != CS_NONE) {
689 *lenp = charset_to_unicode(&tptr, &textlen, data,
690 textlen * 2, charset, NULL,
695 DisposeHandle(texth);
704 static pascal void mac_scrolltracker(ControlHandle control, short part) {
707 #if TARGET_API_MAC_CARBON
708 s = (Session *)GetWRefCon(GetControlOwner(control));
710 s = (Session *)GetWRefCon((*control)->contrlOwner);
713 case kControlUpButtonPart:
714 term_scroll(s->term, 0, -1);
716 case kControlDownButtonPart:
717 term_scroll(s->term, 0, +1);
719 case kControlPageUpPart:
720 term_scroll(s->term, 0, -(s->term->rows - 1));
722 case kControlPageDownPart:
723 term_scroll(s->term, 0, +(s->term->rows - 1));
728 void mac_keyterm(WindowPtr window, EventRecord *event) {
729 Session *s = (Session *)GetWRefCon(window);
730 Key_Sym keysym = PK_NULL;
731 unsigned int mods = 0, flags = PKF_NUMLOCK;
735 ScriptCode key_script;
740 fprintf(stderr, "Got key event %08x\n", event->message);
743 /* No meta key yet -- that'll be rather fun. */
745 /* Keys that we handle locally */
746 if (event->modifiers & shiftKey) {
747 switch ((event->message & keyCodeMask) >> 8) {
748 case 0x74: /* shift-pageup */
749 term_scroll(s->term, 0, -(s->term->rows - 1));
751 case 0x79: /* shift-pagedown */
752 term_scroll(s->term, 0, +(s->term->rows - 1));
757 if (event->modifiers & shiftKey)
759 if (event->modifiers & controlKey)
761 if (event->what == autoKey)
764 /* Mac key events consist of a virtual key code and a character code. */
766 switch ((event->message & keyCodeMask) >> 8) {
767 case 0x24: keysym = PK_RETURN; break;
768 case 0x30: keysym = PK_TAB; break;
769 case 0x33: keysym = PK_BACKSPACE; break;
770 case 0x35: keysym = PK_ESCAPE; break;
772 case 0x7A: keysym = PK_F1; break;
773 case 0x78: keysym = PK_F2; break;
774 case 0x63: keysym = PK_F3; break;
775 case 0x76: keysym = PK_F4; break;
776 case 0x60: keysym = PK_F5; break;
777 case 0x61: keysym = PK_F6; break;
778 case 0x62: keysym = PK_F7; break;
779 case 0x64: keysym = PK_F8; break;
780 case 0x65: keysym = PK_F9; break;
781 case 0x6D: keysym = PK_F10; break;
782 case 0x67: keysym = PK_F11; break;
783 case 0x6F: keysym = PK_F12; break;
784 case 0x69: keysym = PK_F13; break;
785 case 0x6B: keysym = PK_F14; break;
786 case 0x71: keysym = PK_F15; break;
788 case 0x72: keysym = PK_INSERT; break;
789 case 0x73: keysym = PK_HOME; break;
790 case 0x74: keysym = PK_PAGEUP; break;
791 case 0x75: keysym = PK_DELETE; break;
792 case 0x77: keysym = PK_END; break;
793 case 0x79: keysym = PK_PAGEDOWN; break;
795 case 0x47: keysym = PK_PF1; break;
796 case 0x51: keysym = PK_PF2; break;
797 case 0x4B: keysym = PK_PF3; break;
798 case 0x43: keysym = PK_PF4; break;
799 case 0x4E: keysym = PK_KPMINUS; break;
800 case 0x45: keysym = PK_KPCOMMA; break;
801 case 0x41: keysym = PK_KPDECIMAL; break;
802 case 0x4C: keysym = PK_KPENTER; break;
803 case 0x52: keysym = PK_KP0; break;
804 case 0x53: keysym = PK_KP1; break;
805 case 0x54: keysym = PK_KP2; break;
806 case 0x55: keysym = PK_KP3; break;
807 case 0x56: keysym = PK_KP4; break;
808 case 0x57: keysym = PK_KP5; break;
809 case 0x58: keysym = PK_KP6; break;
810 case 0x59: keysym = PK_KP7; break;
811 case 0x5B: keysym = PK_KP8; break;
812 case 0x5C: keysym = PK_KP9; break;
814 case 0x7B: keysym = PK_LEFT; break;
815 case 0x7C: keysym = PK_RIGHT; break;
816 case 0x7D: keysym = PK_DOWN; break;
817 case 0x7E: keysym = PK_UP; break;
820 /* Map from key script to Unicode. */
821 txt[0] = event->message & charCodeMask;
822 key_script = GetScriptManagerVariable(smKeyScript);
824 if (mac_gestalts.encvvers != 0) {
825 static TextToUnicodeInfo key_to_uni = NULL;
826 static ScriptCode key_to_uni_script;
828 ByteCount iread, olen;
831 if (key_to_uni != NULL && key_to_uni_script != key_script)
832 DisposeTextToUnicodeInfo(&key_to_uni);
833 if (key_to_uni == NULL || key_to_uni_script != key_script) {
834 if (UpgradeScriptInfoToTextEncoding(key_script,
835 kTextLanguageDontCare,
836 kTextRegionDontCare, NULL,
838 CreateTextToUnicodeInfoByEncoding(enc, &key_to_uni) == noErr)
839 key_to_uni_script = key_script;
843 if (key_to_uni != NULL) {
844 err = ConvertFromTextToUnicode(key_to_uni, 1, txt,
845 (kUnicodeKeepInfoMask |
846 kUnicodeStringUnterminatedMask),
848 sizeof(utxt), &iread, &olen, utxt);
850 len = olen / sizeof(*utxt);
857 charset = charset_from_macenc(key_script,
858 GetScriptManagerVariable(smRegionCode),
859 mac_gestalts.sysvers, NULL);
860 if (charset != CS_NONE) {
861 len = charset_to_unicode(&tptr, &tlen, utxt, sizeof(utxt), charset,
865 term_key(s->term, keysym, utxt, len, mods, flags);
868 void request_paste(void *frontend)
870 Session *s = frontend;
873 * In the Mac OS, pasting is synchronous: we can read the
874 * clipboard with no difficulty, so request_paste() can just go
877 term_do_paste(s->term);
888 void mac_growterm(WindowPtr window, EventRecord *event) {
891 int newrows, newcols;
893 #if !TARGET_API_MAC_CARBON
894 DragGrayRgnUPP draghooksave;
899 s = (Session *)GetWRefCon(window);
901 #if !TARGET_API_MAC_CARBON
902 draghooksave = LMGetDragHook();
903 growterm_state.oldmsg[0] = '\0';
904 growterm_state.zeromouse = event->where;
905 growterm_state.zeromouse.h -= s->term->cols * s->font_width;
906 growterm_state.zeromouse.v -= s->term->rows * s->font_height;
907 growterm_state.s = s;
910 BackColor(whiteColor);
911 ForeColor(blackColor);
912 TextFont(systemFont);
916 SetRect(&growterm_state.msgrect, 0, 0,
917 StringWidth("\p99999x99999") + 4, fi.ascent + fi.descent + 4);
918 SetPt(&growterm_state.msgorigin, 2, fi.ascent + 2);
919 LMSetDragHook(NewDragGrayRgnUPP(mac_growtermdraghook));
922 SetRect(&limits, s->font_width + 15, s->font_height, SHRT_MAX, SHRT_MAX);
923 grow_result = GrowWindow(window, event->where, &limits);
925 #if !TARGET_API_MAC_CARBON
926 DisposeDragGrayRgnUPP(LMGetDragHook());
927 LMSetDragHook(draghooksave);
928 InvalRect(&growterm_state.msgrect);
933 if (grow_result != 0) {
934 newrows = HiWord(grow_result) / s->font_height;
935 newcols = (LoWord(grow_result) - 15) / s->font_width;
936 mac_adjustsize(s, newrows, newcols);
937 term_size(s->term, newrows, newcols, s->cfg.savelines);
941 #if !TARGET_API_MAC_CARBON
942 static pascal void mac_growtermdraghook(void)
944 Session *s = growterm_state.s;
948 unsigned char pbuf[20];
949 int newrows, newcols;
952 newrows = (mouse.v - growterm_state.zeromouse.v) / s->font_height;
953 if (newrows < 1) newrows = 1;
954 newcols = (mouse.h - growterm_state.zeromouse.h) / s->font_width;
955 if (newcols < 1) newcols = 1;
956 sprintf(buf, "%dx%d", newcols, newrows);
957 if (strcmp(buf, growterm_state.oldmsg) == 0)
959 strcpy(growterm_state.oldmsg, buf);
960 c2pstrcpy(pbuf, buf);
963 SetPort(growterm_state.s->window);
964 EraseRect(&growterm_state.msgrect);
965 MoveTo(growterm_state.msgorigin.h, growterm_state.msgorigin.v);
971 void mac_closeterm(WindowPtr window)
973 Session *s = (Session *)GetWRefCon(window);
975 /* XXX warn on close */
976 HideWindow(s->window);
978 s->next->prev = s->prev;
979 ldisc_free(s->ldisc);
980 s->back->free(s->backhandle);
982 if (s->uni_to_font != NULL)
983 DisposeUnicodeToTextInfo(&s->uni_to_font);
985 DisposeWindow(s->window);
986 DisposePalette(s->palette);
990 void mac_activateterm(WindowPtr window, Boolean active) {
993 s = (Session *)GetWRefCon(window);
994 s->term->has_focus = active;
995 term_update(s->term);
997 ShowControl(s->scrollbar);
1000 PmBackColor(DEFAULT_BG);/* HideControl clears behind the control */
1002 BackColor(blackColor);
1003 HideControl(s->scrollbar);
1005 mac_drawgrowicon(s);
1008 void mac_updateterm(WindowPtr window) {
1011 #if TARGET_API_MAC_CARBON
1015 s = (Session *)GetWRefCon(window);
1016 SetPort((GrafPtr)GetWindowPort(window));
1017 BeginUpdate(window);
1019 #if TARGET_API_MAC_CARBON
1021 GetPortVisibleRegion(GetWindowPort(window), visrgn);
1022 GetRegionBounds(visrgn, &bbox);
1024 bbox = (*window->visRgn)->rgnBBox;
1026 term_paint(s->term, s, PTOCC(bbox.left), PTOCR(bbox.top),
1027 PTOCC(bbox.right), PTOCR(bbox.bottom), 1);
1028 /* Restore default colours in case the Window Manager uses them */
1029 if (HAVE_COLOR_QD()) {
1030 PmForeColor(DEFAULT_FG);
1031 PmBackColor(DEFAULT_BG);
1033 ForeColor(whiteColor);
1034 BackColor(blackColor);
1036 if (FrontWindow() != window)
1037 #if TARGET_API_MAC_CARBON
1038 EraseRect(GetControlBounds(s->scrollbar, &bbox));
1039 UpdateControls(window, visrgn);
1042 EraseRect(&(*s->scrollbar)->contrlRect);
1043 UpdateControls(window, window->visRgn);
1045 mac_drawgrowicon(s);
1050 static void mac_drawgrowicon(Session *s) {
1054 SetPort((GrafPtr)GetWindowPort(s->window));
1056 * Stop DrawGrowIcon giving us space for a horizontal scrollbar
1057 * See Tech Note TB575 for details.
1059 #if TARGET_API_MAC_CARBON
1060 GetPortBounds(GetWindowPort(s->window), &clip);
1062 clip = s->window->portRect;
1064 clip.left = clip.right - 15;
1068 DrawGrowIcon(s->window);
1070 DisposeRgn(savergn);
1073 struct do_text_args {
1084 * Call from the terminal emulator to draw a bit of text
1086 * x and y are text row and column (zero-based)
1088 void do_text(Context ctx, int x, int y, char *text, int len,
1089 unsigned long attr, int lattr) {
1092 struct do_text_args a;
1093 RgnHandle textrgn, saveclip;
1094 #if TARGET_API_MAC_CARBON
1097 char mactextbuf[1024];
1098 UniChar unitextbuf[1024];
1099 wchar_t *unitextptr;
1101 ByteCount iread, olen;
1103 static DeviceLoopDrawingUPP do_text_for_device_upp = NULL;
1105 assert(len <= 1024);
1107 SetPort((GrafPtr)GetWindowPort(s->window));
1109 fontwidth = s->font_width;
1110 if ((lattr & LATTR_MODE) != LATTR_NORM)
1113 /* First check this text is relevant */
1114 a.textrect.top = y * s->font_height;
1115 a.textrect.bottom = (y + 1) * s->font_height;
1116 a.textrect.left = x * fontwidth;
1117 a.textrect.right = (x + len) * fontwidth;
1118 if (a.textrect.right > s->term->cols * s->font_width)
1119 a.textrect.right = s->term->cols * s->font_width;
1120 #if TARGET_API_MAC_CARBON
1122 GetPortVisibleRegion(GetWindowPort(s->window), visrgn);
1123 if (!RectInRgn(&a.textrect, visrgn)) {
1129 if (!RectInRgn(&a.textrect, s->window->visRgn))
1133 /* Unpack Unicode from the mad format we get passed */
1134 for (i = 0; i < len; i++)
1135 unitextbuf[i] = (unsigned char)text[i] | (attr & CSET_MASK);
1137 if (s->uni_to_font != NULL) {
1138 err = ConvertFromUnicodeToText(s->uni_to_font, len * sizeof(UniChar),
1139 unitextbuf, kUnicodeUseFallbacksMask,
1140 0, NULL, NULL, NULL,
1141 1024, &iread, &olen, mactextbuf);
1142 if (err != noErr && err != kTECUsedFallbacksStatus)
1144 } else if (s->font_charset != CS_NONE) {
1145 /* XXX this is bogus if wchar_t and UniChar are different sizes. */
1146 unitextptr = (wchar_t *)unitextbuf;
1147 olen = charset_from_unicode(&unitextptr, &len, mactextbuf, 1024,
1148 s->font_charset, NULL, ".", 1);
1153 a.text = mactextbuf;
1157 switch (lattr & LATTR_MODE) {
1159 TextSize(s->cfg.font.size);
1160 a.numer = s->font_stdnumer;
1161 a.denom = s->font_stddenom;
1164 TextSize(s->cfg.font.size);
1165 a.numer = s->font_widenumer;
1166 a.denom = s->font_widedenom;
1170 TextSize(s->cfg.font.size * 2);
1171 a.numer = s->font_bignumer;
1172 a.denom = s->font_bigdenom;
1175 SetPort((GrafPtr)GetWindowPort(s->window));
1176 TextFont(s->fontnum);
1177 style = s->cfg.font.face;
1178 if ((attr & ATTR_BOLD) && !s->cfg.bold_colour)
1180 if (attr & ATTR_UNDER)
1184 if (HAVE_COLOR_QD())
1186 SpaceExtra(s->font_boldadjust << 16);
1187 CharExtra(s->font_boldadjust << 16);
1192 saveclip = NewRgn();
1194 ClipRect(&a.textrect);
1196 RectRgn(textrgn, &a.textrect);
1197 if (HAVE_COLOR_QD()) {
1198 if (do_text_for_device_upp == NULL)
1199 do_text_for_device_upp =
1200 NewDeviceLoopDrawingUPP(&do_text_for_device);
1201 DeviceLoop(textrgn, do_text_for_device_upp, (long)&a, 0);
1203 do_text_for_device(1, 0, NULL, (long)&a);
1205 DisposeRgn(saveclip);
1206 DisposeRgn(textrgn);
1207 /* Tell the window manager about it in case this isn't an update */
1208 #if TARGET_API_MAC_CARBON
1209 ValidWindowRect(s->window, &a.textrect);
1211 ValidRect(&a.textrect);
1215 static pascal void do_text_for_device(short depth, short devflags,
1216 GDHandle device, long cookie) {
1217 struct do_text_args *a = (struct do_text_args *)cookie;
1218 int bgcolour, fgcolour, bright, reverse, tmp;
1219 #if TARGET_API_MAC_CARBON
1220 CQDProcsPtr gp = GetPortGrafProcs(GetWindowPort(a->s->window));
1222 QDProcsPtr gp = a->s->window->grafProcs;
1225 bright = (a->attr & ATTR_BOLD) && a->s->cfg.bold_colour;
1226 reverse = a->attr & ATTR_REVERSE;
1228 if (depth == 1 && (a->attr & TATTR_ACTCURS))
1231 if (HAVE_COLOR_QD()) {
1233 fgcolour = ((a->attr & ATTR_FGMASK) >> ATTR_FGSHIFT);
1234 fgcolour = (fgcolour & 0xF) * 2 + (fgcolour & 0x10 ? 1 : 0);
1235 bgcolour = ((a->attr & ATTR_BGMASK) >> ATTR_BGSHIFT);
1236 bgcolour = (bgcolour & 0xF) * 2 + (bgcolour & 0x10 ? 1 : 0);
1239 * NB: bold reverse in 2bpp breaks with the usual PuTTY model and
1240 * boldens the background, because that's all we can do.
1242 fgcolour = bright ? DEFAULT_FG_BOLD : DEFAULT_FG;
1243 bgcolour = DEFAULT_BG;
1247 fgcolour = bgcolour;
1250 if (bright && depth > 2)
1252 if ((a->attr & TATTR_ACTCURS) && depth > 1) {
1253 fgcolour = CURSOR_FG;
1254 bgcolour = CURSOR_BG;
1256 PmForeColor(fgcolour);
1257 PmBackColor(bgcolour);
1258 } else { /* No Color Quickdraw */
1259 /* XXX This should be done with a _little_ more configurability */
1261 ForeColor(blackColor);
1262 BackColor(whiteColor);
1264 ForeColor(whiteColor);
1265 BackColor(blackColor);
1269 EraseRect(&a->textrect);
1270 switch (a->lattr & LATTR_MODE) {
1273 MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent);
1276 MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent * 2);
1279 MoveTo(a->textrect.left,
1280 a->textrect.top - a->s->font_height + a->s->font_ascent * 2);
1283 /* FIXME: Sort out bold width adjustments on Original QuickDraw. */
1285 InvokeQDTextUPP(a->len, a->text, a->numer, a->denom, gp->textProc);
1287 StdText(a->len, a->text, a->numer, a->denom);
1289 if (a->attr & TATTR_PASCURS) {
1296 PmForeColor(CURSOR_BG);
1299 FrameRect(&a->textrect);
1303 void do_cursor(Context ctx, int x, int y, char *text, int len,
1304 unsigned long attr, int lattr)
1307 do_text(ctx, x, y, text, len, attr, lattr);
1311 * Call from the terminal emulator to get its graphics context.
1312 * Should probably be called start_redraw or something.
1314 void pre_paint(Session *s) {
1316 Rect myrect, tmprect;
1317 #if TARGET_API_MAC_CARBON
1321 if (HAVE_COLOR_QD()) {
1322 s->term->attr_mask = 0;
1323 SetPort((GrafPtr)GetWindowPort(s->window));
1324 #if TARGET_API_MAC_CARBON
1326 GetPortVisibleRegion(GetWindowPort(s->window), visrgn);
1327 GetRegionBounds(visrgn, &myrect);
1330 myrect = (*s->window->visRgn)->rgnBBox;
1332 LocalToGlobal((Point *)&myrect.top);
1333 LocalToGlobal((Point *)&myrect.bottom);
1334 for (gdh = GetDeviceList();
1336 gdh = GetNextDevice(gdh)) {
1337 if (TestDeviceAttribute(gdh, screenDevice) &&
1338 TestDeviceAttribute(gdh, screenActive) &&
1339 SectRect(&(*gdh)->gdRect, &myrect, &tmprect)) {
1340 switch ((*(*gdh)->gdPMap)->pixelSize) {
1342 if (s->cfg.bold_colour)
1343 s->term->attr_mask |= ~(ATTR_COLOURS |
1344 (s->cfg.bold_colour ? ATTR_BOLD : 0));
1347 s->term->attr_mask |= ~ATTR_COLOURS;
1350 s->term->attr_mask = ~0;
1351 return; /* No point checking more screens. */
1356 s->term->attr_mask = ~(ATTR_COLOURS |
1357 (s->cfg.bold_colour ? ATTR_BOLD : 0));
1360 Context get_ctx(void *frontend) {
1361 Session *s = frontend;
1367 void free_ctx(Context ctx) {
1372 * Presumably this does something in Windows
1374 void post_paint(Session *s) {
1379 * Set the scroll bar position
1381 * total is the line number of the bottom of the working screen
1382 * start is the line number of the top of the display
1383 * page is the length of the displayed page
1385 void set_sbar(void *frontend, int total, int start, int page) {
1386 Session *s = frontend;
1388 /* We don't redraw until we've set everything up, to avoid glitches */
1389 SetControlMinimum(s->scrollbar, 0);
1390 SetControlMaximum(s->scrollbar, total - page);
1391 SetControlValue(s->scrollbar, start);
1393 if (mac_gestalts.cntlattr & gestaltControlMgrPresent)
1394 SetControlViewSize(s->scrollbar, page);
1398 void sys_cursor(void *frontend, int x, int y)
1401 * I think his is meaningless under Mac OS.
1406 * This is still called when mode==BELL_VISUAL, even though the
1407 * visual bell is handled entirely within terminal.c, because we
1408 * may want to perform additional actions on any kind of bell (for
1409 * example, taskbar flashing in Windows).
1411 void beep(void *frontend, int mode)
1413 if (mode != BELL_VISUAL)
1416 * XXX We should indicate the relevant window and/or use the
1417 * Notification Manager
1421 int char_width(Context ctx, int uc)
1424 * Until we support exciting character-set stuff, assume all chars are
1431 * Set icon string -- a no-op here (Windowshade?)
1433 void set_icon(void *frontend, char *icon) {
1434 Session *s = frontend;
1439 * Set the window title
1441 void set_title(void *frontend, char *title) {
1442 Session *s = frontend;
1445 c2pstrcpy(mactitle, title);
1446 SetWTitle(s->window, mactitle);
1450 * set or clear the "raw mouse message" mode
1452 void set_raw_mouse_mode(void *frontend, int activate)
1454 Session *s = frontend;
1456 s->raw_mouse = activate;
1457 /* FIXME: Should call mac_updatetermcursor as appropriate. */
1461 * Resize the window at the emulator's request
1463 void request_resize(void *frontend, int w, int h) {
1464 Session *s = frontend;
1466 term_size(s->term, h, w, s->cfg.savelines);
1471 * Iconify (actually collapse) the window at the emulator's request.
1473 void set_iconic(void *frontend, int iconic)
1475 Session *s = frontend;
1478 if (mac_gestalts.apprvers >= 0x0100 &&
1479 GetWindowFeatures(s->window, &features) == noErr &&
1480 (features & kWindowCanCollapse))
1481 CollapseWindow(s->window, iconic);
1485 * Move the window in response to a server-side request.
1487 void move_window(void *frontend, int x, int y)
1489 Session *s = frontend;
1491 MoveWindow(s->window, x, y, FALSE);
1495 * Move the window to the top or bottom of the z-order in response
1496 * to a server-side request.
1498 void set_zorder(void *frontend, int top)
1500 Session *s = frontend;
1503 * We also change the input focus to point to the topmost window,
1504 * since that's probably what the Human Interface Guidelines would
1508 SelectWindow(s->window);
1510 SendBehind(s->window, NULL);
1514 * Refresh the window in response to a server-side request.
1516 void refresh_window(void *frontend)
1518 Session *s = frontend;
1520 term_invalidate(s->term);
1524 * Maximise or restore the window in response to a server-side
1527 void set_zoomed(void *frontend, int zoomed)
1529 Session *s = frontend;
1531 ZoomWindow(s->window, zoomed ? inZoomOut : inZoomIn, FALSE);
1535 * Report whether the window is iconic, for terminal reports.
1537 int is_iconic(void *frontend)
1539 Session *s = frontend;
1542 if (mac_gestalts.apprvers >= 0x0100 &&
1543 GetWindowFeatures(s->window, &features) == noErr &&
1544 (features & kWindowCanCollapse))
1545 return IsWindowCollapsed(s->window);
1550 * Report the window's position, for terminal reports.
1552 void get_window_pos(void *frontend, int *x, int *y)
1554 Session *s = frontend;
1557 #if TARGET_API_MAC_CARBON
1558 GetPortBounds(GetWindowPort(s->window), &rect);
1560 rect = s->window->portRect;
1567 * Report the window's pixel size, for terminal reports.
1569 void get_window_pixels(void *frontend, int *x, int *y)
1571 Session *s = frontend;
1574 #if TARGET_API_MAC_CARBON
1575 GetPortBounds(GetWindowPort(s->window), &rect);
1577 rect = s->window->portRect;
1579 *x = rect.right - rect.left;
1580 *y = rect.bottom - rect.top;
1584 * Return the window or icon title.
1586 char *get_window_title(void *frontend, int icon)
1588 Session *s = frontend;
1590 static char title[256];
1592 GetWTitle(s->window, ptitle);
1593 p2cstrcpy(title, ptitle);
1598 * real_palette_set(): This does the actual palette-changing work on behalf
1599 * of palette_set(). Does _not_ call ActivatePalette() in case the caller
1600 * is doing a batch of updates.
1602 static void real_palette_set(Session *s, int n, int r, int g, int b)
1606 if (!HAVE_COLOR_QD())
1608 col.red = r * 0x0101;
1609 col.green = g * 0x0101;
1610 col.blue = b * 0x0101;
1611 SetEntryColor(s->palette, n, &col);
1615 * Set the logical palette. Called by the terminal emulator.
1617 void palette_set(void *frontend, int n, int r, int g, int b) {
1618 Session *s = frontend;
1619 static const int first[21] = {
1620 0, 2, 4, 6, 8, 10, 12, 14,
1621 1, 3, 5, 7, 9, 11, 13, 15,
1625 if (!HAVE_COLOR_QD())
1627 real_palette_set(s, first[n], r, g, b);
1629 real_palette_set(s, first[n]+1, r, g, b);
1630 if (first[n] == DEFAULT_BG)
1632 ActivatePalette(s->window);
1636 * Reset to the default palette
1638 void palette_reset(void *frontend) {
1639 Session *s = frontend;
1640 /* This maps colour indices in cfg to those used in our palette. */
1641 static const int ww[] = {
1642 6, 7, 8, 9, 10, 11, 12, 13,
1643 14, 15, 16, 17, 18, 19, 20, 21,
1648 if (!HAVE_COLOR_QD())
1651 assert(lenof(ww) == NCOLOURS);
1653 for (i = 0; i < NCOLOURS; i++) {
1654 real_palette_set(s, i,
1655 s->cfg.colours[ww[i]][0],
1656 s->cfg.colours[ww[i]][1],
1657 s->cfg.colours[ww[i]][2]);
1660 ActivatePalette(s->window);
1661 /* Palette Manager will generate update events as required. */
1665 * Scroll the screen. (`lines' is +ve for scrolling forward, -ve
1668 void do_scroll(Context ctx, int topline, int botline, int lines) {
1671 RgnHandle scrollrgn = NewRgn();
1672 RgnHandle movedupdate = NewRgn();
1673 RgnHandle update = NewRgn();
1674 Point g2l = { 0, 0 };
1676 SetPort((GrafPtr)GetWindowPort(s->window));
1679 * Work out the part of the update region that will scrolled by
1683 SetRectRgn(scrollrgn, 0, (topline + lines) * s->font_height,
1684 s->term->cols * s->font_width,
1685 (botline + 1) * s->font_height);
1687 SetRectRgn(scrollrgn, 0, topline * s->font_height,
1688 s->term->cols * s->font_width,
1689 (botline - lines + 1) * s->font_height);
1690 #if TARGET_API_MAC_CARBON
1691 GetWindowRegion(s->window, kWindowUpdateRgn, movedupdate);
1693 GetWindowUpdateRgn(s->window, movedupdate);
1695 GlobalToLocal(&g2l);
1696 OffsetRgn(movedupdate, g2l.h, g2l.v); /* Convert to local co-ords. */
1697 SectRgn(scrollrgn, movedupdate, movedupdate); /* Clip scrolled section. */
1698 #if TARGET_API_MAC_CARBON
1699 ValidWindowRgn(s->window, movedupdate);
1701 ValidRgn(movedupdate);
1703 OffsetRgn(movedupdate, 0, -lines * s->font_height); /* Scroll it. */
1706 if (HAVE_COLOR_QD())
1707 PmBackColor(DEFAULT_BG);
1709 BackColor(blackColor); /* XXX make configurable */
1710 SetRect(&r, 0, topline * s->font_height,
1711 s->term->cols * s->font_width, (botline + 1) * s->font_height);
1712 ScrollRect(&r, 0, - lines * s->font_height, update);
1714 #if TARGET_API_MAC_CARBON
1715 InvalWindowRgn(s->window, update);
1716 InvalWindowRgn(s->window, movedupdate);
1719 InvalRgn(movedupdate);
1722 DisposeRgn(scrollrgn);
1723 DisposeRgn(movedupdate);
1727 void logevent(void *frontend, char *str) {
1729 fprintf(stderr, "%s\n", str);
1732 /* Dummy routine, only required in plink. */
1733 void ldisc_update(void *frontend, int echo, int edit)
1738 * Mac PuTTY doesn't support printing yet.
1740 printer_job *printer_start_job(char *printer)
1746 void printer_job_data(printer_job *pj, void *data, int len)
1750 void printer_finish_job(printer_job *pj)
1754 void frontend_keypress(void *handle)
1757 * Keypress termination in non-Close-On-Exit mode is not
1758 * currently supported in PuTTY proper, because the window
1759 * always has a perfectly good Close button anyway. So we do
1766 * Ask whether to wipe a session log file before writing to it.
1767 * Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
1769 int askappend(void *frontend, Filename filename)
1772 /* FIXME: not implemented yet. */
1779 * c-file-style: "simon"