1 /* $Id: macterm.c,v 1.76 2004/06/20 17:07:37 jacob 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 *);
93 static void mac_activateterm(WindowPtr, EventRecord *);
94 static void mac_adjusttermcursor(WindowPtr, Point, RgnHandle);
95 static void mac_adjusttermmenus(WindowPtr);
96 static void mac_updateterm(WindowPtr);
97 static void mac_clickterm(WindowPtr, EventRecord *);
98 static void mac_growterm(WindowPtr, EventRecord *);
99 static void mac_keyterm(WindowPtr, EventRecord *);
100 static void mac_menuterm(WindowPtr, short, short);
101 static void mac_closeterm(WindowPtr);
103 void pre_paint(Session *s);
104 void post_paint(Session *s);
106 void mac_startsession(Session *s)
115 * Select protocol. This is farmed out into a table in a
116 * separate file to enable an ssh-free variant.
119 for (i = 0; backends[i].backend != NULL; i++)
120 if (backends[i].protocol == s->cfg.protocol) {
121 s->back = backends[i].backend;
125 fatalbox("Unsupported protocol number found");
127 /* XXX: Own storage management? */
129 s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1);
131 s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
133 memset(wi, 0, sizeof(*wi));
135 wi->wtype = wTerminal;
136 wi->activate = &mac_activateterm;
137 wi->adjustcursor = &mac_adjusttermcursor;
138 wi->adjustmenus = &mac_adjusttermmenus;
139 wi->update = &mac_updateterm;
140 wi->click = &mac_clickterm;
141 wi->grow = &mac_growterm;
142 wi->key = &mac_keyterm;
143 wi->menu = &mac_menuterm;
144 wi->close = &mac_closeterm;
145 SetWRefCon(s->window, (long)wi);
146 s->scrollbar = GetNewControl(cVScroll, s->window);
147 s->term = term_init(&s->cfg, &s->ucsdata, s);
151 if (HAVE_COLOR_QD()) {
152 /* Set to FALSE to not get palette updates in the background. */
153 SetPalette(s->window, s->palette, TRUE);
154 ActivatePalette(s->window);
157 s->logctx = log_init(s->term, &s->cfg);
158 term_provide_logctx(s->term, s->logctx);
160 errmsg = s->back->init(s, &s->backhandle, &s->cfg, s->cfg.host,
161 s->cfg.port, &s->realhost, s->cfg.tcp_nodelay,
162 s->cfg.tcp_keepalives);
164 fatalbox("%s", errmsg);
165 s->back->provide_logctx(s->backhandle, s->logctx);
166 set_title(s, s->realhost);
168 term_provide_resize_fn(s->term, s->back->size, s->backhandle);
170 mac_adjustsize(s, s->cfg.height, s->cfg.width);
171 term_size(s->term, s->cfg.height, s->cfg.width, s->cfg.savelines);
173 s->ldisc = ldisc_create(&s->cfg, s->term, s->back, s->backhandle, s);
174 ldisc_send(s->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */
176 ShowWindow(s->window);
180 s->next->prev = &s->next;
185 * Try to work out a horizontal scaling factor for the current font
186 * that will give a chracter width of wantwidth. Return it in numer
187 * and denom (suitable for passing to StdText()).
189 static void mac_workoutfontscale(Session *s, int wantwidth,
190 Point *numerp, Point *denomp)
192 Point numer, denom, tmpnumer, tmpdenom;
194 const char text = 'W';
196 #if TARGET_API_MAC_CARBON
197 CQDProcsPtr gp = GetPortGrafProcs(GetWindowPort(s->window));
199 QDProcsPtr gp = s->window->grafProcs;
202 numer.v = denom.v = 1; /* always */
203 numer.h = denom.h = 1;
204 for (i = 0; i < 3; i++) {
208 gotwidth = InvokeQDTxMeasUPP(1, &text, &tmpnumer, &tmpdenom, &fi,
211 gotwidth = StdTxMeas(1, &text, &tmpnumer, &tmpdenom, &fi);
212 /* The result of StdTxMeas must be scaled by the factors it returns. */
213 gotwidth = FixRound(FixMul(gotwidth << 16,
214 FixRatio(tmpnumer.h, tmpdenom.h)));
215 if (gotwidth == wantwidth)
217 numer.h *= wantwidth;
224 static UnicodeToTextFallbackUPP uni_to_font_fallback_upp;
226 static void mac_initfont(Session *s)
232 SetPort((GrafPtr)GetWindowPort(s->window));
233 GetFNum(s->cfg.font.name, &s->fontnum);
234 TextFont(s->fontnum);
235 TextFace(s->cfg.font.face);
236 TextSize(s->cfg.font.size);
238 s->font_width = CharWidth('W'); /* Well, it's what NCSA uses. */
239 s->font_ascent = fi.ascent;
240 s->font_leading = fi.leading;
241 s->font_height = s->font_ascent + fi.descent + s->font_leading;
242 mac_workoutfontscale(s, s->font_width,
243 &s->font_stdnumer, &s->font_stddenom);
244 mac_workoutfontscale(s, s->font_width * 2,
245 &s->font_widenumer, &s->font_widedenom);
246 TextSize(s->cfg.font.size * 2);
247 mac_workoutfontscale(s, s->font_width * 2,
248 &s->font_bignumer, &s->font_bigdenom);
249 TextSize(s->cfg.font.size);
250 if (!s->cfg.bold_colour) {
252 s->font_boldadjust = s->font_width - CharWidth('W');
254 s->font_boldadjust = 0;
256 if (s->uni_to_font != NULL)
257 DisposeUnicodeToTextInfo(&s->uni_to_font);
258 if (mac_gestalts.encvvers != 0 &&
259 UpgradeScriptInfoToTextEncoding(kTextScriptDontCare,
260 kTextLanguageDontCare,
261 kTextRegionDontCare, s->cfg.font.name,
263 CreateUnicodeToTextInfoByEncoding(enc, &s->uni_to_font) == noErr) {
264 if (uni_to_font_fallback_upp == NULL)
265 uni_to_font_fallback_upp =
266 NewUnicodeToTextFallbackUPP(&uni_to_font_fallback);
267 fbflags = kUnicodeFallbackCustomOnly;
268 if (mac_gestalts.uncvattr & kTECAddFallbackInterruptMask)
269 fbflags |= kUnicodeFallbackInterruptSafeMask;
270 if (SetFallbackUnicodeToText(s->uni_to_font,
271 uni_to_font_fallback_upp, fbflags, NULL) != noErr) {
272 DisposeUnicodeToTextInfo(&s->uni_to_font);
279 s->uni_to_font = NULL;
280 p2cstrcpy(cfontname, s->cfg.font.name);
282 charset_from_macenc(FontToScript(s->fontnum),
283 GetScriptManagerVariable(smRegionCode),
284 mac_gestalts.sysvers, cfontname);
287 mac_adjustsize(s, s->term->rows, s->term->cols);
290 static pascal OSStatus uni_to_font_fallback(UniChar *ucp,
291 ByteCount ilen, ByteCount *iusedp, TextPtr obuf, ByteCount olen,
292 ByteCount *ousedp, LogicalAddress cookie, ConstUnicodeMappingPtr mapping)
296 return kTECOutputBufferFullStatus;
298 * What I'd _like_ to do here is to somehow generate the
299 * missing-character glyph that every font is required to have.
300 * Unfortunately (and somewhat surprisingly), I can't find any way
301 * to actually ask for it explicitly. Bah.
310 * Called every time round the event loop.
312 void mac_pollterm(void)
316 for (s = sesslist; s != NULL; s = s->next) {
318 term_update(s->term);
323 * To be called whenever the window size changes.
324 * rows and cols should be desired values.
325 * It's assumed the terminal emulator will be informed, and will set rows
328 static void mac_adjustsize(Session *s, int newrows, int newcols) {
329 int winwidth, winheight;
331 winwidth = newcols * s->font_width + 15;
332 winheight = newrows * s->font_height;
333 SizeWindow(s->window, winwidth, winheight, true);
334 HideControl(s->scrollbar);
335 MoveControl(s->scrollbar, winwidth - 15, -1);
336 SizeControl(s->scrollbar, 16, winheight - 13);
337 ShowControl(s->scrollbar);
341 static void mac_initpalette(Session *s)
344 if (!HAVE_COLOR_QD())
347 * Most colours should be inhibited on 2bpp displays.
348 * Palette manager documentation suggests inhibiting all tolerant colours
349 * on greyscale displays.
351 #define PM_NORMAL ( pmTolerant | pmInhibitC2 | \
352 pmInhibitG2 | pmInhibitG4 | pmInhibitG8 )
353 #define PM_TOLERANCE 0x2000
354 s->palette = NewPalette(22, NULL, PM_NORMAL, PM_TOLERANCE);
355 if (s->palette == NULL)
356 fatalbox("Unable to create palette");
357 /* In 2bpp, these are the colours we want most. */
358 SetEntryUsage(s->palette, DEFAULT_BG,
359 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
360 SetEntryUsage(s->palette, DEFAULT_FG,
361 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
362 SetEntryUsage(s->palette, DEFAULT_FG_BOLD,
363 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
364 SetEntryUsage(s->palette, CURSOR_BG,
365 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
370 * Set the background colour of the window correctly. Should be
371 * called whenever the default background changes.
373 static void mac_adjustwinbg(Session *s)
376 if (!HAVE_COLOR_QD())
379 if (mac_gestalts.windattr & gestaltWindowMgrPresent)
380 SetWindowContentColor(s->window,
381 &(*s->palette)->pmInfo[DEFAULT_BG].ciRGB);
385 #if !TARGET_API_MAC_CARBON
386 if (s->wctab == NULL)
387 s->wctab = (WCTabHandle)NewHandle(sizeof(**s->wctab));
388 if (s->wctab == NULL)
389 return; /* do without */
390 (*s->wctab)->wCSeed = 0;
391 (*s->wctab)->wCReserved = 0;
392 (*s->wctab)->ctSize = 0;
393 (*s->wctab)->ctTable[0].value = wContentColor;
394 (*s->wctab)->ctTable[0].rgb = (*s->palette)->pmInfo[DEFAULT_BG].ciRGB;
395 SetWinColor(s->window, s->wctab);
401 * Set the cursor shape correctly
403 static void mac_adjusttermcursor(WindowPtr window, Point mouse,
407 ControlHandle control;
410 #if TARGET_API_MAC_CARBON
416 SetPort((GrafPtr)GetWindowPort(window));
417 s = mac_windowsession(window);
418 GlobalToLocal(&mouse);
419 part = FindControl(mouse, window, &control);
420 if (control == s->scrollbar) {
421 #if TARGET_API_MAC_CARBON
422 SetCursor(GetQDGlobalsArrow(&arrow));
423 RectRgn(cursrgn, GetControlBounds(s->scrollbar, &rect));
425 SetCursor(&qd.arrow);
426 RectRgn(cursrgn, &(*s->scrollbar)->contrlRect);
429 x = mouse.h / s->font_width;
430 y = mouse.v / s->font_height;
432 #if TARGET_API_MAC_CARBON
433 SetCursor(GetQDGlobalsArrow(&arrow));
435 SetCursor(&qd.arrow);
438 SetCursor(*GetCursor(iBeamCursor));
439 /* Ask for shape changes if we leave this character cell. */
440 SetRectRgn(cursrgn, x * s->font_width, y * s->font_height,
441 (x + 1) * s->font_width, (y + 1) * s->font_height);
443 #if TARGET_API_MAC_CARBON
445 GetPortVisibleRegion(GetWindowPort(window), visrgn);
446 SectRgn(cursrgn, visrgn, cursrgn);
449 SectRgn(cursrgn, window->visRgn, cursrgn);
454 * Enable/disable menu items based on the active terminal window.
456 #if TARGET_API_MAC_CARBON
457 #define DisableItem DisableMenuItem
458 #define EnableItem EnableMenuItem
460 static void mac_adjusttermmenus(WindowPtr window)
464 #if !TARGET_API_MAC_CARBON
468 s = mac_windowsession(window);
469 menu = GetMenuHandle(mFile);
470 DisableItem(menu, iSave); /* XXX enable if modified */
471 EnableItem(menu, iSaveAs);
472 EnableItem(menu, iDuplicate);
473 menu = GetMenuHandle(mEdit);
475 DisableItem(menu, iUndo);
476 DisableItem(menu, iCut);
477 if (1/*s->term->selstate == SELECTED*/)
478 EnableItem(menu, iCopy);
480 DisableItem(menu, iCopy);
481 #if TARGET_API_MAC_CARBON
484 if (GetScrap(NULL, kScrapFlavorTypeText, &offset) == noTypeErr)
486 DisableItem(menu, iPaste);
488 EnableItem(menu, iPaste);
489 DisableItem(menu, iClear);
490 EnableItem(menu, iSelectAll);
491 menu = GetMenuHandle(mWindow);
493 EnableItem(menu, iShowEventLog);
496 static void mac_menuterm(WindowPtr window, short menu, short item)
500 s = mac_windowsession(window);
508 term_do_paste(s->term);
522 static void mac_clickterm(WindowPtr window, EventRecord *event)
526 ControlHandle control;
528 static ControlActionUPP mac_scrolltracker_upp = NULL;
530 s = mac_windowsession(window);
531 SetPort((GrafPtr)GetWindowPort(window));
532 mouse = event->where;
533 GlobalToLocal(&mouse);
534 part = FindControl(mouse, window, &control);
535 if (control == s->scrollbar) {
537 case kControlIndicatorPart:
538 if (TrackControl(control, mouse, NULL) == kControlIndicatorPart)
539 term_scroll(s->term, +1, GetControlValue(control));
541 case kControlUpButtonPart:
542 case kControlDownButtonPart:
543 case kControlPageUpPart:
544 case kControlPageDownPart:
545 if (mac_scrolltracker_upp == NULL)
546 mac_scrolltracker_upp =
547 NewControlActionUPP(&mac_scrolltracker);
548 TrackControl(control, mouse, mac_scrolltracker_upp);
552 text_click(s, event);
556 static void text_click(Session *s, EventRecord *event)
560 static UInt32 lastwhen = 0;
561 static Session *lastsess = NULL;
562 static int lastrow = -1, lastcol = -1;
563 static Mouse_Action lastact = MA_NOTHING;
565 SetPort((GrafPtr)GetWindowPort(s->window));
566 localwhere = event->where;
567 GlobalToLocal(&localwhere);
569 col = PTOCC(localwhere.h);
570 row = PTOCR(localwhere.v);
571 if (event->when - lastwhen < GetDblTime() &&
572 row == lastrow && col == lastcol && s == lastsess)
573 lastact = (lastact == MA_CLICK ? MA_2CLK :
574 lastact == MA_2CLK ? MA_3CLK :
575 lastact == MA_3CLK ? MA_CLICK : MA_NOTHING);
578 term_mouse(s->term, MBT_LEFT,
579 event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
580 lastact, col, row, event->modifiers & shiftKey,
581 event->modifiers & controlKey, event->modifiers & optionKey);
585 while (StillDown()) {
586 GetMouse(&localwhere);
587 col = PTOCC(localwhere.h);
588 row = PTOCR(localwhere.v);
589 term_mouse(s->term, MBT_LEFT,
590 event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
591 MA_DRAG, col, row, event->modifiers & shiftKey,
592 event->modifiers & controlKey,
593 event->modifiers & optionKey);
594 if (row > s->term->rows - 1)
595 term_scroll(s->term, 0, row - (s->term->rows - 1));
597 term_scroll(s->term, 0, row);
599 term_mouse(s->term, MBT_LEFT,
600 event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
601 MA_RELEASE, col, row, event->modifiers & shiftKey,
602 event->modifiers & controlKey, event->modifiers & optionKey);
603 lastwhen = TickCount();
606 void write_clip(void *cookie, wchar_t *data, int len, int must_deselect)
608 #if !TARGET_API_MAC_CARBON
611 ByteCount iread, olen;
619 * See "Programming with the Text Encoding Conversion Manager"
620 * Appendix E for Unicode scrap conventions.
622 * XXX Maybe PICT scrap too.
624 if (ZeroScrap() != noErr)
626 PutScrap(len * sizeof(*data), kScrapFlavorTypeUnicode, data);
628 /* Replace LINE SEPARATORs with CR for TEXT output. */
629 for (i = 0; i < len; i++)
630 if (data[i] == 0x2028)
633 mactextbuf = snewn(len, char); /* XXX DBCS */
634 if (s->uni_to_font != NULL) {
635 err = ConvertFromUnicodeToText(s->uni_to_font, len * sizeof(UniChar),
637 kUnicodeUseFallbacksMask,
639 len, &iread, &olen, mactextbuf);
640 if (err != noErr && err != kTECUsedFallbacksStatus)
642 } else if (s->font_charset != CS_NONE) {
644 olen = charset_from_unicode(&unitextptr, &len, mactextbuf, 1024,
645 s->font_charset, NULL, ".", 1);
648 PutScrap(olen, kScrapFlavorTypeText, mactextbuf);
651 stsz = offsetof(StScrpRec, scrpStyleTab) + sizeof(ScrpSTElement);
652 stsc = smalloc(stsz);
653 stsc->scrpNStyles = 1;
654 stsc->scrpStyleTab[0].scrpStartChar = 0;
655 stsc->scrpStyleTab[0].scrpHeight = s->font_height;
656 stsc->scrpStyleTab[0].scrpAscent = s->font_ascent;
657 stsc->scrpStyleTab[0].scrpFont = s->fontnum;
658 stsc->scrpStyleTab[0].scrpFace = 0;
659 stsc->scrpStyleTab[0].scrpSize = s->cfg.font.size;
660 stsc->scrpStyleTab[0].scrpColor.red = 0;
661 stsc->scrpStyleTab[0].scrpColor.green = 0;
662 stsc->scrpStyleTab[0].scrpColor.blue = 0;
663 PutScrap(stsz, kScrapFlavorTypeTextStyle, stsc);
668 void get_clip(void *frontend, wchar_t **p, int *lenp)
670 #if TARGET_API_MAC_CARBON
673 Session *s = frontend;
674 static Handle h = NULL;
675 static wchar_t *data = NULL;
680 TextToUnicodeInfo scrap_to_uni;
681 ByteCount iread, olen;
695 if (GetScrap(NULL, kScrapFlavorTypeUnicode, &offset) > 0) {
699 GetScrap(h, kScrapFlavorTypeUnicode, &offset) / sizeof(**p);
702 } else if (GetScrap(NULL, kScrapFlavorTypeText, &offset) > 0) {
703 texth = NewHandle(0);
704 textlen = GetScrap(texth, kScrapFlavorTypeText, &offset);
706 data = snewn(textlen, wchar_t);
707 /* XXX should use 'styl' scrap if it's there. */
708 if (mac_gestalts.encvvers != 0 &&
709 UpgradeScriptInfoToTextEncoding(smSystemScript,
710 kTextLanguageDontCare,
711 kTextRegionDontCare, NULL,
713 CreateTextToUnicodeInfoByEncoding(enc, &scrap_to_uni) ==
715 err = ConvertFromTextToUnicode(scrap_to_uni, textlen,
716 *texth, 0, 0, NULL, NULL, NULL,
718 &iread, &olen, data);
719 DisposeTextToUnicodeInfo(&scrap_to_uni);
722 *lenp = olen / sizeof(**p);
729 charset_from_macenc(GetScriptManagerVariable(smSysScript),
730 GetScriptManagerVariable(smRegionCode),
731 mac_gestalts.sysvers, NULL);
732 if (charset != CS_NONE) {
734 *lenp = charset_to_unicode(&tptr, &textlen, data,
735 textlen * 2, charset, NULL,
740 DisposeHandle(texth);
749 static pascal void mac_scrolltracker(ControlHandle control, short part)
753 #if TARGET_API_MAC_CARBON
754 s = mac_windowsession(GetControlOwner(control));
756 s = mac_windowsession((*control)->contrlOwner);
759 case kControlUpButtonPart:
760 term_scroll(s->term, 0, -1);
762 case kControlDownButtonPart:
763 term_scroll(s->term, 0, +1);
765 case kControlPageUpPart:
766 term_scroll(s->term, 0, -(s->term->rows - 1));
768 case kControlPageDownPart:
769 term_scroll(s->term, 0, +(s->term->rows - 1));
774 static void mac_keyterm(WindowPtr window, EventRecord *event)
776 Session *s = mac_windowsession(window);
777 Key_Sym keysym = PK_NULL;
778 unsigned int mods = 0, flags = PKF_NUMLOCK;
782 ScriptCode key_script;
787 fprintf(stderr, "Got key event %08x\n", event->message);
790 /* No meta key yet -- that'll be rather fun. */
792 /* Keys that we handle locally */
793 if (event->modifiers & shiftKey) {
794 switch ((event->message & keyCodeMask) >> 8) {
795 case 0x74: /* shift-pageup */
796 term_scroll(s->term, 0, -(s->term->rows - 1));
798 case 0x79: /* shift-pagedown */
799 term_scroll(s->term, 0, +(s->term->rows - 1));
804 if (event->modifiers & shiftKey)
806 if (event->modifiers & controlKey)
808 if (event->what == autoKey)
811 /* Mac key events consist of a virtual key code and a character code. */
813 switch ((event->message & keyCodeMask) >> 8) {
814 case 0x24: keysym = PK_RETURN; break;
815 case 0x30: keysym = PK_TAB; break;
816 case 0x33: keysym = PK_BACKSPACE; break;
817 case 0x35: keysym = PK_ESCAPE; break;
819 case 0x7A: keysym = PK_F1; break;
820 case 0x78: keysym = PK_F2; break;
821 case 0x63: keysym = PK_F3; break;
822 case 0x76: keysym = PK_F4; break;
823 case 0x60: keysym = PK_F5; break;
824 case 0x61: keysym = PK_F6; break;
825 case 0x62: keysym = PK_F7; break;
826 case 0x64: keysym = PK_F8; break;
827 case 0x65: keysym = PK_F9; break;
828 case 0x6D: keysym = PK_F10; break;
829 case 0x67: keysym = PK_F11; break;
830 case 0x6F: keysym = PK_F12; break;
831 case 0x69: keysym = PK_F13; break;
832 case 0x6B: keysym = PK_F14; break;
833 case 0x71: keysym = PK_F15; break;
835 case 0x72: keysym = PK_INSERT; break;
836 case 0x73: keysym = PK_HOME; break;
837 case 0x74: keysym = PK_PAGEUP; break;
838 case 0x75: keysym = PK_DELETE; break;
839 case 0x77: keysym = PK_END; break;
840 case 0x79: keysym = PK_PAGEDOWN; break;
842 case 0x47: keysym = PK_PF1; break;
843 case 0x51: keysym = PK_PF2; break;
844 case 0x4B: keysym = PK_PF3; break;
845 case 0x43: keysym = PK_PF4; break;
846 case 0x4E: keysym = PK_KPMINUS; break;
847 case 0x45: keysym = PK_KPCOMMA; break;
848 case 0x41: keysym = PK_KPDECIMAL; break;
849 case 0x4C: keysym = PK_KPENTER; break;
850 case 0x52: keysym = PK_KP0; break;
851 case 0x53: keysym = PK_KP1; break;
852 case 0x54: keysym = PK_KP2; break;
853 case 0x55: keysym = PK_KP3; break;
854 case 0x56: keysym = PK_KP4; break;
855 case 0x57: keysym = PK_KP5; break;
856 case 0x58: keysym = PK_KP6; break;
857 case 0x59: keysym = PK_KP7; break;
858 case 0x5B: keysym = PK_KP8; break;
859 case 0x5C: keysym = PK_KP9; break;
861 case 0x7B: keysym = PK_LEFT; break;
862 case 0x7C: keysym = PK_RIGHT; break;
863 case 0x7D: keysym = PK_DOWN; break;
864 case 0x7E: keysym = PK_UP; break;
867 /* Map from key script to Unicode. */
868 txt[0] = event->message & charCodeMask;
869 key_script = GetScriptManagerVariable(smKeyScript);
871 if (mac_gestalts.encvvers != 0) {
872 static TextToUnicodeInfo key_to_uni = NULL;
873 static ScriptCode key_to_uni_script;
875 ByteCount iread, olen;
878 if (key_to_uni != NULL && key_to_uni_script != key_script)
879 DisposeTextToUnicodeInfo(&key_to_uni);
880 if (key_to_uni == NULL || key_to_uni_script != key_script) {
881 if (UpgradeScriptInfoToTextEncoding(key_script,
882 kTextLanguageDontCare,
883 kTextRegionDontCare, NULL,
885 CreateTextToUnicodeInfoByEncoding(enc, &key_to_uni) == noErr)
886 key_to_uni_script = key_script;
890 if (key_to_uni != NULL) {
891 err = ConvertFromTextToUnicode(key_to_uni, 1, txt,
892 (kUnicodeKeepInfoMask |
893 kUnicodeStringUnterminatedMask),
895 sizeof(utxt), &iread, &olen, utxt);
897 len = olen / sizeof(*utxt);
904 charset = charset_from_macenc(key_script,
905 GetScriptManagerVariable(smRegionCode),
906 mac_gestalts.sysvers, NULL);
907 if (charset != CS_NONE) {
908 len = charset_to_unicode(&tptr, &tlen, utxt, sizeof(utxt), charset,
912 term_key(s->term, keysym, utxt, len, mods, flags);
915 void request_paste(void *frontend)
917 Session *s = frontend;
920 * In the Mac OS, pasting is synchronous: we can read the
921 * clipboard with no difficulty, so request_paste() can just go
924 term_do_paste(s->term);
935 static void mac_growterm(WindowPtr window, EventRecord *event)
939 int newrows, newcols;
941 #if !TARGET_API_MAC_CARBON
942 DragGrayRgnUPP draghooksave;
947 s = mac_windowsession(window);
949 #if !TARGET_API_MAC_CARBON
950 draghooksave = LMGetDragHook();
951 growterm_state.oldmsg[0] = '\0';
952 growterm_state.zeromouse = event->where;
953 growterm_state.zeromouse.h -= s->term->cols * s->font_width;
954 growterm_state.zeromouse.v -= s->term->rows * s->font_height;
955 growterm_state.s = s;
958 BackColor(whiteColor);
959 ForeColor(blackColor);
960 TextFont(systemFont);
964 SetRect(&growterm_state.msgrect, 0, 0,
965 StringWidth("\p99999x99999") + 4, fi.ascent + fi.descent + 4);
966 SetPt(&growterm_state.msgorigin, 2, fi.ascent + 2);
967 LMSetDragHook(NewDragGrayRgnUPP(mac_growtermdraghook));
970 SetRect(&limits, s->font_width + 15, s->font_height, SHRT_MAX, SHRT_MAX);
971 grow_result = GrowWindow(window, event->where, &limits);
973 #if !TARGET_API_MAC_CARBON
974 DisposeDragGrayRgnUPP(LMGetDragHook());
975 LMSetDragHook(draghooksave);
976 InvalRect(&growterm_state.msgrect);
981 if (grow_result != 0) {
982 newrows = HiWord(grow_result) / s->font_height;
983 newcols = (LoWord(grow_result) - 15) / s->font_width;
984 mac_adjustsize(s, newrows, newcols);
985 term_size(s->term, newrows, newcols, s->cfg.savelines);
989 #if !TARGET_API_MAC_CARBON
990 static pascal void mac_growtermdraghook(void)
992 Session *s = growterm_state.s;
996 unsigned char pbuf[20];
997 int newrows, newcols;
1000 newrows = (mouse.v - growterm_state.zeromouse.v) / s->font_height;
1001 if (newrows < 1) newrows = 1;
1002 newcols = (mouse.h - growterm_state.zeromouse.h) / s->font_width;
1003 if (newcols < 1) newcols = 1;
1004 sprintf(buf, "%dx%d", newcols, newrows);
1005 if (strcmp(buf, growterm_state.oldmsg) == 0)
1007 strcpy(growterm_state.oldmsg, buf);
1008 c2pstrcpy(pbuf, buf);
1011 SetPort(growterm_state.s->window);
1012 EraseRect(&growterm_state.msgrect);
1013 MoveTo(growterm_state.msgorigin.h, growterm_state.msgorigin.v);
1019 void mac_closeterm(WindowPtr window)
1021 Session *s = mac_windowsession(window);
1023 /* XXX warn on close */
1024 HideWindow(s->window);
1026 s->next->prev = s->prev;
1027 ldisc_free(s->ldisc);
1028 s->back->free(s->backhandle);
1029 log_free(s->logctx);
1030 if (s->uni_to_font != NULL)
1031 DisposeUnicodeToTextInfo(&s->uni_to_font);
1033 mac_freeeventlog(s);
1034 sfree((WinInfo *)GetWRefCon(s->window));
1035 DisposeWindow(s->window);
1036 DisposePalette(s->palette);
1040 static void mac_activateterm(WindowPtr window, EventRecord *event)
1043 Boolean active = (event->modifiers & activeFlag) != 0;
1045 s = mac_windowsession(window);
1046 s->term->has_focus = active;
1047 term_update(s->term);
1049 ShowControl(s->scrollbar);
1051 if (HAVE_COLOR_QD())
1052 PmBackColor(DEFAULT_BG);/* HideControl clears behind the control */
1054 BackColor(blackColor);
1055 HideControl(s->scrollbar);
1057 mac_drawgrowicon(s);
1060 static void mac_updateterm(WindowPtr window)
1064 #if TARGET_API_MAC_CARBON
1068 s = mac_windowsession(window);
1069 SetPort((GrafPtr)GetWindowPort(window));
1070 BeginUpdate(window);
1072 #if TARGET_API_MAC_CARBON
1074 GetPortVisibleRegion(GetWindowPort(window), visrgn);
1075 GetRegionBounds(visrgn, &bbox);
1077 bbox = (*window->visRgn)->rgnBBox;
1079 term_paint(s->term, s, PTOCC(bbox.left), PTOCR(bbox.top),
1080 PTOCC(bbox.right), PTOCR(bbox.bottom), 1);
1081 /* Restore default colours in case the Window Manager uses them */
1082 if (HAVE_COLOR_QD()) {
1083 PmForeColor(DEFAULT_FG);
1084 PmBackColor(DEFAULT_BG);
1086 ForeColor(whiteColor);
1087 BackColor(blackColor);
1089 if (FrontWindow() != window)
1090 #if TARGET_API_MAC_CARBON
1091 EraseRect(GetControlBounds(s->scrollbar, &bbox));
1092 UpdateControls(window, visrgn);
1095 EraseRect(&(*s->scrollbar)->contrlRect);
1096 UpdateControls(window, window->visRgn);
1098 mac_drawgrowicon(s);
1103 static void mac_drawgrowicon(Session *s)
1108 SetPort((GrafPtr)GetWindowPort(s->window));
1110 * Stop DrawGrowIcon giving us space for a horizontal scrollbar
1111 * See Tech Note TB575 for details.
1113 #if TARGET_API_MAC_CARBON
1114 GetPortBounds(GetWindowPort(s->window), &clip);
1116 clip = s->window->portRect;
1118 clip.left = clip.right - 15;
1122 DrawGrowIcon(s->window);
1124 DisposeRgn(savergn);
1127 struct do_text_args {
1138 * Call from the terminal emulator to draw a bit of text
1140 * x and y are text row and column (zero-based)
1142 void do_text(Context ctx, int x, int y, char *text, int len,
1143 unsigned long attr, int lattr)
1147 struct do_text_args a;
1148 RgnHandle textrgn, saveclip;
1149 #if TARGET_API_MAC_CARBON
1152 char mactextbuf[1024];
1153 UniChar unitextbuf[1024];
1154 wchar_t *unitextptr;
1156 ByteCount iread, olen;
1158 static DeviceLoopDrawingUPP do_text_for_device_upp = NULL;
1160 assert(len <= 1024);
1162 SetPort((GrafPtr)GetWindowPort(s->window));
1164 fontwidth = s->font_width;
1165 if ((lattr & LATTR_MODE) != LATTR_NORM)
1168 /* First check this text is relevant */
1169 a.textrect.top = y * s->font_height;
1170 a.textrect.bottom = (y + 1) * s->font_height;
1171 a.textrect.left = x * fontwidth;
1172 a.textrect.right = (x + len) * fontwidth;
1173 if (a.textrect.right > s->term->cols * s->font_width)
1174 a.textrect.right = s->term->cols * s->font_width;
1175 #if TARGET_API_MAC_CARBON
1177 GetPortVisibleRegion(GetWindowPort(s->window), visrgn);
1178 if (!RectInRgn(&a.textrect, visrgn)) {
1184 if (!RectInRgn(&a.textrect, s->window->visRgn))
1188 /* Unpack Unicode from the mad format we get passed */
1189 for (i = 0; i < len; i++)
1190 unitextbuf[i] = (unsigned char)text[i] | (attr & CSET_MASK);
1192 if (s->uni_to_font != NULL) {
1193 err = ConvertFromUnicodeToText(s->uni_to_font, len * sizeof(UniChar),
1194 unitextbuf, kUnicodeUseFallbacksMask,
1195 0, NULL, NULL, NULL,
1196 1024, &iread, &olen, mactextbuf);
1197 if (err != noErr && err != kTECUsedFallbacksStatus)
1199 } else if (s->font_charset != CS_NONE) {
1200 /* XXX this is bogus if wchar_t and UniChar are different sizes. */
1201 unitextptr = (wchar_t *)unitextbuf;
1202 olen = charset_from_unicode(&unitextptr, &len, mactextbuf, 1024,
1203 s->font_charset, NULL, ".", 1);
1208 a.text = mactextbuf;
1212 switch (lattr & LATTR_MODE) {
1214 TextSize(s->cfg.font.size);
1215 a.numer = s->font_stdnumer;
1216 a.denom = s->font_stddenom;
1219 TextSize(s->cfg.font.size);
1220 a.numer = s->font_widenumer;
1221 a.denom = s->font_widedenom;
1225 TextSize(s->cfg.font.size * 2);
1226 a.numer = s->font_bignumer;
1227 a.denom = s->font_bigdenom;
1230 SetPort((GrafPtr)GetWindowPort(s->window));
1231 TextFont(s->fontnum);
1232 style = s->cfg.font.face;
1233 if ((attr & ATTR_BOLD) && !s->cfg.bold_colour)
1235 if (attr & ATTR_UNDER)
1239 if (HAVE_COLOR_QD())
1241 SpaceExtra(s->font_boldadjust << 16);
1242 CharExtra(s->font_boldadjust << 16);
1247 saveclip = NewRgn();
1249 ClipRect(&a.textrect);
1251 RectRgn(textrgn, &a.textrect);
1252 if (HAVE_COLOR_QD()) {
1253 if (do_text_for_device_upp == NULL)
1254 do_text_for_device_upp =
1255 NewDeviceLoopDrawingUPP(&do_text_for_device);
1256 DeviceLoop(textrgn, do_text_for_device_upp, (long)&a, 0);
1258 do_text_for_device(1, 0, NULL, (long)&a);
1260 DisposeRgn(saveclip);
1261 DisposeRgn(textrgn);
1262 /* Tell the window manager about it in case this isn't an update */
1263 #if TARGET_API_MAC_CARBON
1264 ValidWindowRect(s->window, &a.textrect);
1266 ValidRect(&a.textrect);
1270 static pascal void do_text_for_device(short depth, short devflags,
1271 GDHandle device, long cookie)
1273 struct do_text_args *a = (struct do_text_args *)cookie;
1274 int bgcolour, fgcolour, bright, reverse, tmp;
1275 #if TARGET_API_MAC_CARBON
1276 CQDProcsPtr gp = GetPortGrafProcs(GetWindowPort(a->s->window));
1278 QDProcsPtr gp = a->s->window->grafProcs;
1281 bright = (a->attr & ATTR_BOLD) && a->s->cfg.bold_colour;
1282 reverse = a->attr & ATTR_REVERSE;
1284 if (depth == 1 && (a->attr & TATTR_ACTCURS))
1287 if (HAVE_COLOR_QD()) {
1289 fgcolour = ((a->attr & ATTR_FGMASK) >> ATTR_FGSHIFT);
1290 fgcolour = (fgcolour & 0xF) * 2 + (fgcolour & 0x10 ? 1 : 0);
1291 bgcolour = ((a->attr & ATTR_BGMASK) >> ATTR_BGSHIFT);
1292 bgcolour = (bgcolour & 0xF) * 2 + (bgcolour & 0x10 ? 1 : 0);
1295 * NB: bold reverse in 2bpp breaks with the usual PuTTY model and
1296 * boldens the background, because that's all we can do.
1298 fgcolour = bright ? DEFAULT_FG_BOLD : DEFAULT_FG;
1299 bgcolour = DEFAULT_BG;
1303 fgcolour = bgcolour;
1306 if (bright && depth > 2)
1308 if ((a->attr & TATTR_ACTCURS) && depth > 1) {
1309 fgcolour = CURSOR_FG;
1310 bgcolour = CURSOR_BG;
1312 PmForeColor(fgcolour);
1313 PmBackColor(bgcolour);
1314 } else { /* No Color Quickdraw */
1315 /* XXX This should be done with a _little_ more configurability */
1317 ForeColor(blackColor);
1318 BackColor(whiteColor);
1320 ForeColor(whiteColor);
1321 BackColor(blackColor);
1325 EraseRect(&a->textrect);
1326 switch (a->lattr & LATTR_MODE) {
1329 MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent);
1332 MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent * 2);
1335 MoveTo(a->textrect.left,
1336 a->textrect.top - a->s->font_height + a->s->font_ascent * 2);
1339 /* FIXME: Sort out bold width adjustments on Original QuickDraw. */
1341 InvokeQDTextUPP(a->len, a->text, a->numer, a->denom, gp->textProc);
1343 StdText(a->len, a->text, a->numer, a->denom);
1345 if (a->attr & TATTR_PASCURS) {
1352 PmForeColor(CURSOR_BG);
1355 FrameRect(&a->textrect);
1359 void do_cursor(Context ctx, int x, int y, char *text, int len,
1360 unsigned long attr, int lattr)
1363 do_text(ctx, x, y, text, len, attr, lattr);
1367 * Call from the terminal emulator to get its graphics context.
1368 * Should probably be called start_redraw or something.
1370 void pre_paint(Session *s)
1373 Rect myrect, tmprect;
1374 #if TARGET_API_MAC_CARBON
1378 if (HAVE_COLOR_QD()) {
1379 s->term->attr_mask = 0;
1380 SetPort((GrafPtr)GetWindowPort(s->window));
1381 #if TARGET_API_MAC_CARBON
1383 GetPortVisibleRegion(GetWindowPort(s->window), visrgn);
1384 GetRegionBounds(visrgn, &myrect);
1387 myrect = (*s->window->visRgn)->rgnBBox;
1389 LocalToGlobal((Point *)&myrect.top);
1390 LocalToGlobal((Point *)&myrect.bottom);
1391 for (gdh = GetDeviceList();
1393 gdh = GetNextDevice(gdh)) {
1394 if (TestDeviceAttribute(gdh, screenDevice) &&
1395 TestDeviceAttribute(gdh, screenActive) &&
1396 SectRect(&(*gdh)->gdRect, &myrect, &tmprect)) {
1397 switch ((*(*gdh)->gdPMap)->pixelSize) {
1399 if (s->cfg.bold_colour)
1400 s->term->attr_mask |= ~(ATTR_COLOURS |
1401 (s->cfg.bold_colour ? ATTR_BOLD : 0));
1404 s->term->attr_mask |= ~ATTR_COLOURS;
1407 s->term->attr_mask = ~0;
1408 return; /* No point checking more screens. */
1413 s->term->attr_mask = ~(ATTR_COLOURS |
1414 (s->cfg.bold_colour ? ATTR_BOLD : 0));
1417 Context get_ctx(void *frontend)
1419 Session *s = frontend;
1425 void free_ctx(Context ctx)
1431 * Presumably this does something in Windows
1433 void post_paint(Session *s)
1439 * Set the scroll bar position
1441 * total is the line number of the bottom of the working screen
1442 * start is the line number of the top of the display
1443 * page is the length of the displayed page
1445 void set_sbar(void *frontend, int total, int start, int page)
1447 Session *s = frontend;
1449 /* We don't redraw until we've set everything up, to avoid glitches */
1450 SetControlMinimum(s->scrollbar, 0);
1451 SetControlMaximum(s->scrollbar, total - page);
1452 SetControlValue(s->scrollbar, start);
1454 if (mac_gestalts.cntlattr & gestaltControlMgrPresent)
1455 SetControlViewSize(s->scrollbar, page);
1459 void sys_cursor(void *frontend, int x, int y)
1462 * I think his is meaningless under Mac OS.
1467 * This is still called when mode==BELL_VISUAL, even though the
1468 * visual bell is handled entirely within terminal.c, because we
1469 * may want to perform additional actions on any kind of bell (for
1470 * example, taskbar flashing in Windows).
1472 void beep(void *frontend, int mode)
1474 if (mode != BELL_VISUAL)
1477 * XXX We should indicate the relevant window and/or use the
1478 * Notification Manager
1482 int char_width(Context ctx, int uc)
1485 * Until we support exciting character-set stuff, assume all chars are
1492 * Set icon string -- a no-op here (Windowshade?)
1494 void set_icon(void *frontend, char *icon) {
1495 Session *s = frontend;
1500 * Set the window title
1502 void set_title(void *frontend, char *title)
1504 Session *s = frontend;
1507 c2pstrcpy(mactitle, title);
1508 SetWTitle(s->window, mactitle);
1512 * set or clear the "raw mouse message" mode
1514 void set_raw_mouse_mode(void *frontend, int activate)
1516 Session *s = frontend;
1518 s->raw_mouse = activate;
1519 /* FIXME: Should call mac_updatetermcursor as appropriate. */
1523 * Resize the window at the emulator's request
1525 void request_resize(void *frontend, int w, int h)
1527 Session *s = frontend;
1532 /* Arbitrarily clip to the size of the desktop. */
1533 grayrgn = GetGrayRgn();
1534 #if TARGET_API_MAC_CARBON
1535 GetRegionBounds(grayrgn, &graybox);
1537 graybox = (*grayrgn)->rgnBBox;
1539 wlim = (graybox.right - graybox.left) / s->font_width;
1540 hlim = (graybox.bottom - graybox.top) / s->font_height;
1541 if (w > wlim) w = wlim;
1542 if (h > hlim) h = hlim;
1543 term_size(s->term, h, w, s->cfg.savelines);
1548 * Iconify (actually collapse) the window at the emulator's request.
1550 void set_iconic(void *frontend, int iconic)
1552 Session *s = frontend;
1555 if (mac_gestalts.apprvers >= 0x0100 &&
1556 GetWindowFeatures(s->window, &features) == noErr &&
1557 (features & kWindowCanCollapse))
1558 CollapseWindow(s->window, iconic);
1562 * Move the window in response to a server-side request.
1564 void move_window(void *frontend, int x, int y)
1566 Session *s = frontend;
1568 MoveWindow(s->window, x, y, FALSE);
1572 * Move the window to the top or bottom of the z-order in response
1573 * to a server-side request.
1575 void set_zorder(void *frontend, int top)
1577 Session *s = frontend;
1580 * We also change the input focus to point to the topmost window,
1581 * since that's probably what the Human Interface Guidelines would
1585 SelectWindow(s->window);
1587 SendBehind(s->window, NULL);
1591 * Refresh the window in response to a server-side request.
1593 void refresh_window(void *frontend)
1595 Session *s = frontend;
1597 term_invalidate(s->term);
1601 * Maximise or restore the window in response to a server-side
1604 void set_zoomed(void *frontend, int zoomed)
1606 Session *s = frontend;
1608 ZoomWindow(s->window, zoomed ? inZoomOut : inZoomIn, FALSE);
1612 * Report whether the window is iconic, for terminal reports.
1614 int is_iconic(void *frontend)
1616 Session *s = frontend;
1619 if (mac_gestalts.apprvers >= 0x0100 &&
1620 GetWindowFeatures(s->window, &features) == noErr &&
1621 (features & kWindowCanCollapse))
1622 return IsWindowCollapsed(s->window);
1627 * Report the window's position, for terminal reports.
1629 void get_window_pos(void *frontend, int *x, int *y)
1631 Session *s = frontend;
1634 #if TARGET_API_MAC_CARBON
1635 GetPortBounds(GetWindowPort(s->window), &rect);
1637 rect = s->window->portRect;
1644 * Report the window's pixel size, for terminal reports.
1646 void get_window_pixels(void *frontend, int *x, int *y)
1648 Session *s = frontend;
1651 #if TARGET_API_MAC_CARBON
1652 GetPortBounds(GetWindowPort(s->window), &rect);
1654 rect = s->window->portRect;
1656 *x = rect.right - rect.left;
1657 *y = rect.bottom - rect.top;
1661 * Return the window or icon title.
1663 char *get_window_title(void *frontend, int icon)
1665 Session *s = frontend;
1667 static char title[256];
1669 GetWTitle(s->window, ptitle);
1670 p2cstrcpy(title, ptitle);
1675 * real_palette_set(): This does the actual palette-changing work on behalf
1676 * of palette_set(). Does _not_ call ActivatePalette() in case the caller
1677 * is doing a batch of updates.
1679 static void real_palette_set(Session *s, int n, int r, int g, int b)
1683 if (!HAVE_COLOR_QD())
1685 col.red = r * 0x0101;
1686 col.green = g * 0x0101;
1687 col.blue = b * 0x0101;
1688 SetEntryColor(s->palette, n, &col);
1692 * Set the logical palette. Called by the terminal emulator.
1694 void palette_set(void *frontend, int n, int r, int g, int b)
1696 Session *s = frontend;
1697 static const int first[21] = {
1698 0, 2, 4, 6, 8, 10, 12, 14,
1699 1, 3, 5, 7, 9, 11, 13, 15,
1703 if (!HAVE_COLOR_QD())
1705 real_palette_set(s, first[n], r, g, b);
1707 real_palette_set(s, first[n]+1, r, g, b);
1708 if (first[n] == DEFAULT_BG)
1710 ActivatePalette(s->window);
1714 * Reset to the default palette
1716 void palette_reset(void *frontend)
1718 Session *s = frontend;
1719 /* This maps colour indices in cfg to those used in our palette. */
1720 static const int ww[] = {
1721 6, 7, 8, 9, 10, 11, 12, 13,
1722 14, 15, 16, 17, 18, 19, 20, 21,
1727 if (!HAVE_COLOR_QD())
1730 assert(lenof(ww) == NCOLOURS);
1732 for (i = 0; i < NCOLOURS; i++) {
1733 real_palette_set(s, i,
1734 s->cfg.colours[ww[i]][0],
1735 s->cfg.colours[ww[i]][1],
1736 s->cfg.colours[ww[i]][2]);
1739 ActivatePalette(s->window);
1740 /* Palette Manager will generate update events as required. */
1744 * Scroll the screen. (`lines' is +ve for scrolling forward, -ve
1747 void do_scroll(Context ctx, int topline, int botline, int lines)
1751 RgnHandle scrollrgn = NewRgn();
1752 RgnHandle movedupdate = NewRgn();
1753 RgnHandle update = NewRgn();
1754 Point g2l = { 0, 0 };
1756 SetPort((GrafPtr)GetWindowPort(s->window));
1759 * Work out the part of the update region that will scrolled by
1763 SetRectRgn(scrollrgn, 0, (topline + lines) * s->font_height,
1764 s->term->cols * s->font_width,
1765 (botline + 1) * s->font_height);
1767 SetRectRgn(scrollrgn, 0, topline * s->font_height,
1768 s->term->cols * s->font_width,
1769 (botline - lines + 1) * s->font_height);
1770 #if TARGET_API_MAC_CARBON
1771 GetWindowRegion(s->window, kWindowUpdateRgn, movedupdate);
1773 GetWindowUpdateRgn(s->window, movedupdate);
1775 GlobalToLocal(&g2l);
1776 OffsetRgn(movedupdate, g2l.h, g2l.v); /* Convert to local co-ords. */
1777 SectRgn(scrollrgn, movedupdate, movedupdate); /* Clip scrolled section. */
1778 #if TARGET_API_MAC_CARBON
1779 ValidWindowRgn(s->window, movedupdate);
1781 ValidRgn(movedupdate);
1783 OffsetRgn(movedupdate, 0, -lines * s->font_height); /* Scroll it. */
1786 if (HAVE_COLOR_QD())
1787 PmBackColor(DEFAULT_BG);
1789 BackColor(blackColor); /* XXX make configurable */
1790 SetRect(&r, 0, topline * s->font_height,
1791 s->term->cols * s->font_width, (botline + 1) * s->font_height);
1792 ScrollRect(&r, 0, - lines * s->font_height, update);
1794 #if TARGET_API_MAC_CARBON
1795 InvalWindowRgn(s->window, update);
1796 InvalWindowRgn(s->window, movedupdate);
1799 InvalRgn(movedupdate);
1802 DisposeRgn(scrollrgn);
1803 DisposeRgn(movedupdate);
1807 /* Dummy routine, only required in plink. */
1808 void ldisc_update(void *frontend, int echo, int edit)
1813 * Mac PuTTY doesn't support printing yet.
1815 printer_job *printer_start_job(char *printer)
1821 void printer_job_data(printer_job *pj, void *data, int len)
1825 void printer_finish_job(printer_job *pj)
1829 void frontend_keypress(void *handle)
1832 * Keypress termination in non-Close-On-Exit mode is not
1833 * currently supported in PuTTY proper, because the window
1834 * always has a perfectly good Close button anyway. So we do
1841 * Ask whether to wipe a session log file before writing to it.
1842 * Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
1844 int askappend(void *frontend, Filename filename)
1847 /* FIXME: not implemented yet. */
1851 int from_backend(void *frontend, int is_stderr, const char *data, int len)
1853 Session *s = frontend;
1855 return term_data(s->term, is_stderr, data, len);
1861 * c-file-style: "simon"