1 /* $Id: macterm.c,v 1.1.2.31 1999/03/28 15:27:03 ben Exp $ */
3 * Copyright (c) 1999 Simon Tatham
4 * Copyright (c) 1999 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
37 #include <MacMemory.h>
38 #include <MacWindows.h>
39 #include <MixedMode.h>
41 #include <Quickdraw.h>
42 #include <QuickdrawText.h>
43 #include <Resources.h>
47 #include <ToolUtils.h>
59 #define DEFAULT_FG_BOLD 17
61 #define DEFAULT_BG_BOLD 19
63 #define CURSOR_FG_BOLD 21
65 #define CURSOR_BG_BOLD 23
67 #define PTOCC(x) ((x) < 0 ? -(-(x - font_width - 1) / font_width) : \
69 #define PTOCR(y) ((y) < 0 ? -(-(y - font_height - 1) / font_height) : \
77 PaletteHandle palette;
78 ControlHandle scrollbar;
82 static void mac_initfont(struct mac_session *);
83 static void mac_initpalette(struct mac_session *);
84 static void mac_adjustwinbg(struct mac_session *);
85 static void mac_adjustsize(struct mac_session *, int, int);
86 static void mac_drawgrowicon(struct mac_session *s);
87 static pascal void mac_scrolltracker(ControlHandle, short);
88 static pascal void do_text_for_device(short, short, GDHandle, long);
89 static pascal void mac_set_attr_mask(short, short, GDHandle, long);
90 static int mac_keytrans(struct mac_session *, EventRecord *, unsigned char *);
91 static void text_click(struct mac_session *, EventRecord *);
94 static RoutineDescriptor mac_scrolltracker_upp =
95 BUILD_ROUTINE_DESCRIPTOR(uppControlActionProcInfo,
96 (ProcPtr)mac_scrolltracker);
97 static RoutineDescriptor do_text_for_device_upp =
98 BUILD_ROUTINE_DESCRIPTOR(uppDeviceLoopDrawingProcInfo,
99 (ProcPtr)do_text_for_device);
100 static RoutineDescriptor mac_set_attr_mask_upp =
101 BUILD_ROUTINE_DESCRIPTOR(uppDeviceLoopDrawingProcInfo,
102 (ProcPtr)mac_set_attr_mask);
103 #else /* not TARGET_RT_MAC_CFM */
104 #define mac_scrolltracker_upp mac_scrolltracker
105 #define do_text_for_device_upp do_text_for_device
106 #define mac_set_attr_mask_upp mac_set_attr_mask
107 #endif /* not TARGET_RT_MAC_CFM */
110 * Temporary hack till I get the terminal emulator supporting multiple
114 static struct mac_session *onlysession;
116 static void inbuf_putc(int c) {
117 inbuf[inbuf_head] = c;
118 inbuf_head = (inbuf_head+1) & INBUF_MASK;
121 static void inbuf_putstr(const char *c) {
126 static void display_resource(unsigned long type, short id) {
131 h = GetResource(type, id);
133 fatalbox("Can't get test resource");
134 SetResAttrs(h, GetResAttrs(h) | resLocked);
136 len = GetResourceSizeOnDisk(h);
137 for (i = 0; i < len; i++) {
141 SetResAttrs(h, GetResAttrs(h) & ~resLocked);
146 void mac_newsession(void) {
147 struct mac_session *s;
151 /* This should obviously be initialised by other means */
152 mac_loadconfig(&cfg);
153 back = &hexdump_backend;
154 s = smalloc(sizeof(*s));
155 memset(s, 0, sizeof(*s));
158 /* XXX: Own storage management? */
159 if (mac_gestalts.qdvers == gestaltOriginalQD)
160 s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
162 s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1);
163 SetWRefCon(s->window, (long)s);
164 s->scrollbar = GetNewControl(cVScroll, s->window);
166 term_size(cfg.height, cfg.width, cfg.savelines);
169 attr_mask = ATTR_MASK;
170 /* Set to FALSE to not get palette updates in the background. */
171 SetPalette(s->window, s->palette, TRUE);
172 ActivatePalette(s->window);
173 ShowWindow(s->window);
174 starttime = TickCount();
175 display_resource('pTST', 128);
176 sprintf(msg, "Elapsed ticks: %d\015\012", TickCount() - starttime);
181 static void mac_initfont(struct mac_session *s) {
186 macfont[0] = sprintf((char *)&macfont[1], "%s", cfg.font);
187 GetFNum(macfont, &s->fontnum);
188 TextFont(s->fontnum);
189 TextFace(cfg.fontisbold ? bold : 0);
190 TextSize(cfg.fontheight);
192 font_width = CharWidth('W'); /* Well, it's what NCSA uses. */
193 s->font_ascent = fi.ascent;
194 s->font_leading = fi.leading;
195 font_height = s->font_ascent + fi.descent + s->font_leading;
196 mac_adjustsize(s, rows, cols);
200 * To be called whenever the window size changes.
201 * rows and cols should be desired values.
202 * It's assumed the terminal emulator will be informed, and will set rows
205 static void mac_adjustsize(struct mac_session *s, int newrows, int newcols) {
206 int winwidth, winheight;
208 winwidth = newcols * font_width + 15;
209 winheight = newrows * font_height;
210 SizeWindow(s->window, winwidth, winheight, true);
211 HideControl(s->scrollbar);
212 MoveControl(s->scrollbar, winwidth - 15, -1);
213 SizeControl(s->scrollbar, 16, winheight - 13);
214 ShowControl(s->scrollbar);
217 static void mac_initpalette(struct mac_session *s) {
219 if (mac_gestalts.qdvers == gestaltOriginalQD)
221 s->palette = NewPalette((*cfg.colours)->pmEntries, NULL, pmCourteous, 0);
222 if (s->palette == NULL)
223 fatalbox("Unable to create palette");
224 CopyPalette(cfg.colours, s->palette, 0, 0, (*cfg.colours)->pmEntries);
229 * Set the background colour of the window correctly. Should be
230 * called whenever the default background changes.
232 static void mac_adjustwinbg(struct mac_session *s) {
234 #if 0 /* XXX doesn't link (at least for 68k) */
235 if (mac_gestalts.windattr & gestaltWindowMgrPresent)
236 SetWindowContentColor(s->window,
237 &(*s->palette)->pmInfo[DEFAULT_BG].ciRGB);
241 if (s->wctab == NULL)
242 s->wctab = (WCTabHandle)NewHandle(sizeof(**s->wctab));
243 if (s->wctab == NULL)
244 return; /* do without */
245 (*s->wctab)->wCSeed = 0;
246 (*s->wctab)->wCReserved = 0;
247 (*s->wctab)->ctSize = 0;
248 (*s->wctab)->ctTable[0].value = wContentColor;
249 (*s->wctab)->ctTable[0].rgb = (*s->palette)->pmInfo[DEFAULT_BG].ciRGB;
250 SetWinColor(s->window, s->wctab);
255 * Set the cursor shape correctly
257 void mac_adjusttermcursor(WindowPtr window, Point mouse, RgnHandle cursrgn) {
258 struct mac_session *s;
259 ControlHandle control;
264 s = (struct mac_session *)GetWRefCon(window);
265 GlobalToLocal(&mouse);
266 part = FindControl(mouse, window, &control);
267 if (control == s->scrollbar) {
268 SetCursor(&qd.arrow);
269 RectRgn(cursrgn, &(*s->scrollbar)->contrlRect);
270 SectRgn(cursrgn, window->visRgn, cursrgn);
272 x = mouse.h / font_width;
273 y = mouse.v / font_height;
274 SetCursor(*GetCursor(iBeamCursor));
275 /* Ask for shape changes if we leave this character cell. */
276 SetRectRgn(cursrgn, x * font_width, y * font_height,
277 (x + 1) * font_width, (y + 1) * font_height);
278 SectRgn(cursrgn, window->visRgn, cursrgn);
283 * Enable/disable menu items based on the active terminal window.
285 void mac_adjusttermmenus(WindowPtr window) {
286 struct mac_session *s;
290 s = (struct mac_session *)GetWRefCon(window);
291 menu = GetMenuHandle(mEdit);
293 DisableItem(menu, iUndo);
294 DisableItem(menu, iCut);
295 if (term_hasselection())
296 EnableItem(menu, iCopy);
298 DisableItem(menu, iCopy);
299 if (GetScrap(NULL, 'TEXT', &offset) == noTypeErr)
300 DisableItem(menu, iPaste);
302 EnableItem(menu, iPaste);
303 DisableItem(menu, iClear);
304 EnableItem(menu, iSelectAll);
307 void mac_menuterm(WindowPtr window, short menu, short item) {
308 struct mac_session *s;
310 s = (struct mac_session *)GetWRefCon(window);
324 void mac_clickterm(WindowPtr window, EventRecord *event) {
325 struct mac_session *s;
327 ControlHandle control;
330 s = (struct mac_session *)GetWRefCon(window);
332 mouse = event->where;
333 GlobalToLocal(&mouse);
334 part = FindControl(mouse, window, &control);
335 if (control == s->scrollbar) {
337 case kControlIndicatorPart:
338 if (TrackControl(control, mouse, NULL) == kControlIndicatorPart)
339 term_scroll(+1, GetControlValue(control));
341 case kControlUpButtonPart:
342 case kControlDownButtonPart:
343 case kControlPageUpPart:
344 case kControlPageDownPart:
345 TrackControl(control, mouse, &mac_scrolltracker_upp);
349 text_click(s, event);
353 static void text_click(struct mac_session *s, EventRecord *event) {
356 static UInt32 lastwhen = 0;
357 static struct mac_session *lastsess = NULL;
358 static int lastrow = -1, lastcol = -1;
359 static Mouse_Action lastact = MA_NOTHING;
362 localwhere = event->where;
363 GlobalToLocal(&localwhere);
365 col = PTOCC(localwhere.h);
366 row = PTOCR(localwhere.v);
367 if (event->when - lastwhen < GetDblTime() &&
368 row == lastrow && col == lastcol && s == lastsess)
369 lastact = (lastact == MA_CLICK ? MA_2CLK :
370 lastact == MA_2CLK ? MA_3CLK :
371 lastact == MA_3CLK ? MA_CLICK : MA_NOTHING);
374 term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT, lastact,
379 while (StillDown()) {
380 GetMouse(&localwhere);
381 col = PTOCC(localwhere.h);
382 row = PTOCR(localwhere.v);
383 term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT,
386 term_scroll(0, row - (rows - 1));
390 term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT, MA_RELEASE,
392 lastwhen = TickCount();
395 void write_clip(void *data, int len) {
397 if (ZeroScrap() != noErr)
399 PutScrap(len, 'TEXT', data);
402 void get_clip(void **p, int *lenp) {
403 static Handle h = NULL;
412 if (GetScrap(NULL, 'TEXT', &offset) > 0) {
414 *lenp = GetScrap(h, 'TEXT', &offset);
417 if (*p == NULL || *lenp <= 0)
418 fatalbox("Empty scrap");
425 static pascal void mac_scrolltracker(ControlHandle control, short part) {
426 struct mac_session *s;
428 s = (struct mac_session *)GetWRefCon((*control)->contrlOwner);
430 case kControlUpButtonPart:
433 case kControlDownButtonPart:
436 case kControlPageUpPart:
437 term_scroll(0, -(rows - 1));
439 case kControlPageDownPart:
440 term_scroll(0, +(rows - 1));
461 #define K_INSERT 0x7200
462 #define K_HOME 0x7300
463 #define K_PRIOR 0x7400
464 #define K_DELETE 0x7500
466 #define K_NEXT 0x7900
467 #define K_LEFT 0x7b00
468 #define K_RIGHT 0x7c00
469 #define K_DOWN 0x7d00
481 #define KP_CLEAR 0x4700
482 #define KP_EQUAL 0x5100
483 #define KP_SLASH 0x4b00
484 #define KP_STAR 0x4300
485 #define KP_PLUS 0x4500
486 #define KP_MINUS 0x4e00
487 #define KP_DOT 0x4100
488 #define KP_ENTER 0x4c00
490 void mac_keyterm(WindowPtr window, EventRecord *event) {
491 unsigned char buf[20];
493 struct mac_session *s;
495 s = (struct mac_session *)GetWRefCon(window);
496 len = mac_keytrans(s, event, buf);
497 back->send((char *)buf, len);
500 static UInt32 mac_rekey(EventModifiers newmodifiers, UInt32 oldmessage) {
501 UInt32 transresult, state;
505 kchr = (Ptr)GetScriptManagerVariable(smKCHRCache);
506 transresult = KeyTranslate(kchr,
507 (oldmessage & keyCodeMask) >> 8 |
508 newmodifiers & 0xff00,
511 * KeyTranslate returns two character codes. We only worry about
512 * one. Yes, this is slightly bogus, but it makes life less
515 return oldmessage & ~charCodeMask | transresult & 0xff;
519 static int mac_keytrans(struct mac_session *s, EventRecord *event,
520 unsigned char *output) {
521 unsigned char *p = output;
524 /* No meta key yet -- that'll be rather fun. */
526 /* Check if the meta "key" was held down */
528 if ((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers) {
530 event->modifiers &= ~cfg.meta_modifiers;
531 event->message = mac_rekey(event->modifiers, event->message);
534 /* Keys that we handle locally */
535 if (event->modifiers & shiftKey) {
536 switch (event->message & keyCodeMask) {
537 case K_PRIOR: /* shift-pageup */
538 term_scroll(0, -(rows - 1));
540 case K_NEXT: /* shift-pagedown */
541 term_scroll(0, +(rows - 1));
547 * Control-2 should return ^@ (0x00), Control-6 should return
548 * ^^ (0x1E), and Control-Minus should return ^_ (0x1F). Since
549 * the DOS keyboard handling did it, and we have nothing better
550 * to do with the key combo in question, we'll also map
551 * Control-Backquote to ^\ (0x1C).
554 if (event->modifiers & controlKey) {
555 switch (event->message & charCodeMask) {
572 * First, all the keys that do tilde codes. (ESC '[' nn '~',
573 * for integer decimal nn.)
575 * We also deal with the weird ones here. Linux VCs replace F1
576 * to F5 by ESC [ [ A to ESC [ [ E. rxvt doesn't do _that_, but
577 * does replace Home and End (1~ and 4~) by ESC [ H and ESC O w
581 switch (event->message & keyCodeMask) {
582 case K_F1: code = (event->modifiers & shiftKey ? 23 : 11); break;
583 case K_F2: code = (event->modifiers & shiftKey ? 24 : 12); break;
584 case K_F3: code = (event->modifiers & shiftKey ? 25 : 13); break;
585 case K_F4: code = (event->modifiers & shiftKey ? 26 : 14); break;
586 case K_F5: code = (event->modifiers & shiftKey ? 28 : 15); break;
587 case K_F6: code = (event->modifiers & shiftKey ? 29 : 17); break;
588 case K_F7: code = (event->modifiers & shiftKey ? 31 : 18); break;
589 case K_F8: code = (event->modifiers & shiftKey ? 32 : 19); break;
590 case K_F9: code = (event->modifiers & shiftKey ? 33 : 20); break;
591 case K_F10: code = (event->modifiers & shiftKey ? 34 : 21); break;
592 case K_F11: code = 23; break;
593 case K_F12: code = 24; break;
594 case K_HOME: code = 1; break;
595 case K_INSERT: code = 2; break;
596 case K_DELETE: code = 3; break;
597 case K_END: code = 4; break;
598 case K_PRIOR: code = 5; break;
599 case K_NEXT: code = 6; break;
601 if (cfg.linux_funkeys && code >= 11 && code <= 15) {
602 p += sprintf((char *)p, "\x1B[[%c", code + 'A' - 11);
605 if (cfg.rxvt_homeend && (code == 1 || code == 4)) {
606 p += sprintf((char *)p, code == 1 ? "\x1B[H" : "\x1BOw");
610 p += sprintf((char *)p, "\x1B[%d~", code);
614 if (app_keypad_keys) {
615 switch (event->message & keyCodeMask) {
616 case KP_ENTER: p += sprintf((char *)p, "\x1BOM"); return p - output;
617 case KP_CLEAR: p += sprintf((char *)p, "\x1BOP"); return p - output;
618 case KP_EQUAL: p += sprintf((char *)p, "\x1BOQ"); return p - output;
619 case KP_SLASH: p += sprintf((char *)p, "\x1BOR"); return p - output;
620 case KP_STAR: p += sprintf((char *)p, "\x1BOS"); return p - output;
621 case KP_PLUS: p += sprintf((char *)p, "\x1BOl"); return p - output;
622 case KP_MINUS: p += sprintf((char *)p, "\x1BOm"); return p - output;
623 case KP_DOT: p += sprintf((char *)p, "\x1BOn"); return p - output;
624 case KP_0: p += sprintf((char *)p, "\x1BOp"); return p - output;
625 case KP_1: p += sprintf((char *)p, "\x1BOq"); return p - output;
626 case KP_2: p += sprintf((char *)p, "\x1BOr"); return p - output;
627 case KP_3: p += sprintf((char *)p, "\x1BOs"); return p - output;
628 case KP_4: p += sprintf((char *)p, "\x1BOt"); return p - output;
629 case KP_5: p += sprintf((char *)p, "\x1BOu"); return p - output;
630 case KP_6: p += sprintf((char *)p, "\x1BOv"); return p - output;
631 case KP_7: p += sprintf((char *)p, "\x1BOw"); return p - output;
632 case KP_8: p += sprintf((char *)p, "\x1BOx"); return p - output;
633 case KP_9: p += sprintf((char *)p, "\x1BOy"); return p - output;
637 switch (event->message & keyCodeMask) {
639 p += sprintf((char *)p, app_cursor_keys ? "\x1BOA" : "\x1B[A");
642 p += sprintf((char *)p, app_cursor_keys ? "\x1BOB" : "\x1B[B");
645 p += sprintf((char *)p, app_cursor_keys ? "\x1BOC" : "\x1B[C");
648 p += sprintf((char *)p, app_cursor_keys ? "\x1BOD" : "\x1B[D");
654 *p++ = (cfg.bksp_is_delete ? 0x7f : 0x08);
657 *p++ = event->message & charCodeMask;
662 void mac_growterm(WindowPtr window, EventRecord *event) {
665 int newrows, newcols;
666 struct mac_session *s;
668 s = (struct mac_session *)GetWRefCon(window);
669 SetRect(&limits, font_width + 15, font_height, SHRT_MAX, SHRT_MAX);
670 grow_result = GrowWindow(window, event->where, &limits);
671 if (grow_result != 0) {
672 newrows = HiWord(grow_result) / font_height;
673 newcols = (LoWord(grow_result) - 15) / font_width;
674 mac_adjustsize(s, newrows, newcols);
675 term_size(newrows, newcols, cfg.savelines);
679 void mac_activateterm(WindowPtr window, Boolean active) {
680 struct mac_session *s;
682 s = (struct mac_session *)GetWRefCon(window);
686 ShowControl(s->scrollbar);
688 PmBackColor(DEFAULT_BG); /* HideControl clears behind the control */
689 HideControl(s->scrollbar);
694 void mac_updateterm(WindowPtr window) {
695 struct mac_session *s;
697 s = (struct mac_session *)GetWRefCon(window);
701 (*window->visRgn)->rgnBBox.left,
702 (*window->visRgn)->rgnBBox.top,
703 (*window->visRgn)->rgnBBox.right,
704 (*window->visRgn)->rgnBBox.bottom);
705 /* Restore default colours in case the Window Manager uses them */
706 PmForeColor(DEFAULT_FG);
707 PmBackColor(DEFAULT_BG);
708 if (FrontWindow() != window)
709 EraseRect(&(*s->scrollbar)->contrlRect);
710 UpdateControls(window, window->visRgn);
716 static void mac_drawgrowicon(struct mac_session *s) {
720 /* Stop DrawGrowIcon giving us space for a horizontal scrollbar */
721 SetRect(&clip, s->window->portRect.right - 15, SHRT_MIN,
724 DrawGrowIcon(s->window);
725 clip.left = SHRT_MIN;
729 struct do_text_args {
730 struct mac_session *s;
739 * Call from the terminal emulator to draw a bit of text
741 * x and y are text row and column (zero-based)
743 void do_text(struct mac_session *s, int x, int y, char *text, int len,
744 unsigned long attr) {
746 struct do_text_args a;
751 /* First check this text is relevant */
752 a.textrect.top = y * font_height;
753 a.textrect.bottom = (y + 1) * font_height;
754 a.textrect.left = x * font_width;
755 a.textrect.right = (x + len) * font_width;
756 if (!RectInRgn(&a.textrect, s->window->visRgn))
763 if (s->font_leading > 0)
765 a.textrect.left, a.textrect.bottom - s->font_leading,
766 a.textrect.right, a.textrect.bottom);
768 SetRect(&a.leadrect, 0, 0, 0, 0);
770 TextFont(s->fontnum);
771 if (cfg.fontisbold || (attr & ATTR_BOLD) && !cfg.bold_colour)
773 if (attr & ATTR_UNDER)
776 TextSize(cfg.fontheight);
777 SetFractEnable(FALSE); /* We want characters on pixel boundaries */
779 RectRgn(textrgn, &a.textrect);
780 DeviceLoop(textrgn, &do_text_for_device_upp, (long)&a, 0);
782 /* Tell the window manager about it in case this isn't an update */
783 ValidRect(&a.textrect);
786 static pascal void do_text_for_device(short depth, short devflags,
787 GDHandle device, long cookie) {
788 struct do_text_args *a;
789 int bgcolour, fgcolour, bright;
791 a = (struct do_text_args *)cookie;
793 bright = (a->attr & ATTR_BOLD) && cfg.bold_colour;
795 TextMode(a->attr & ATTR_REVERSE ? notSrcCopy : srcCopy);
799 /* XXX This should be done with a _little_ more configurability */
800 ForeColor(whiteColor);
801 BackColor(blackColor);
802 if (a->attr & ATTR_ACTCURS)
803 TextMode(a->attr & ATTR_REVERSE ? srcCopy : notSrcCopy);
806 if (a->attr & ATTR_ACTCURS) {
807 PmForeColor(bright ? CURSOR_FG_BOLD : CURSOR_FG);
808 PmBackColor(CURSOR_BG);
811 PmForeColor(bright ? DEFAULT_FG_BOLD : DEFAULT_FG);
812 PmBackColor(DEFAULT_BG);
816 if (a->attr & ATTR_ACTCURS) {
817 fgcolour = bright ? CURSOR_FG_BOLD : CURSOR_FG;
818 bgcolour = CURSOR_BG;
821 fgcolour = ((a->attr & ATTR_FGMASK) >> ATTR_FGSHIFT) * 2;
822 bgcolour = ((a->attr & ATTR_BGMASK) >> ATTR_BGSHIFT) * 2;
824 if (a->attr & ATTR_REVERSE)
829 PmForeColor(fgcolour);
830 PmBackColor(bgcolour);
834 if (a->attr & ATTR_REVERSE)
835 PaintRect(&a->leadrect);
837 EraseRect(&a->leadrect);
838 MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent);
839 DrawText(a->text, 0, a->len);
841 if (a->attr & ATTR_PASCURS) {
848 PmForeColor(CURSOR_BG);
851 FrameRect(&a->textrect);
856 * Call from the terminal emulator to get its graphics context.
857 * Should probably be called start_redraw or something.
859 struct mac_session *get_ctx(void) {
860 struct mac_session *s = onlysession;
862 attr_mask = ATTR_INVALID;
863 DeviceLoop(s->window->visRgn, &mac_set_attr_mask_upp, (long)s, 0);
867 static pascal void mac_set_attr_mask(short depth, short devflags,
868 GDHandle device, long cookie) {
872 attr_mask |= ATTR_FGMASK | ATTR_BGMASK;
875 attr_mask |= ATTR_BOLD;
878 attr_mask |= ATTR_UNDER | ATTR_REVERSE | ATTR_ACTCURS |
879 ATTR_PASCURS | ATTR_ASCII | ATTR_GBCHR | ATTR_LINEDRW |
880 (cfg.bold_colour ? 0 : ATTR_BOLD);
886 * Presumably this does something in Windows
888 void free_ctx(struct mac_session *ctx) {
893 * Set the scroll bar position
895 * total is the line number of the bottom of the working screen
896 * start is the line number of the top of the display
897 * page is the length of the displayed page
899 void set_sbar(int total, int start, int page) {
900 struct mac_session *s = onlysession;
902 /* We don't redraw until we've set everything up, to avoid glitches */
903 (*s->scrollbar)->contrlMin = 0;
904 (*s->scrollbar)->contrlMax = total - page;
905 SetControlValue(s->scrollbar, start);
907 /* XXX: This doesn't link for me. */
908 if (mac_gestalts.cntlattr & gestaltControlMgrPresent)
909 SetControlViewSize(s->scrollbar, page);
920 * XXX We should indicate the relevant window and/or use the
921 * Notification Manager
926 * Set icon string -- a no-op here (Windowshade?)
928 void set_icon(char *icon) {
933 * Set the window title
935 void set_title(char *title) {
937 struct mac_session *s = onlysession;
939 mactitle[0] = sprintf((char *)&mactitle[1], "%s", title);
940 SetWTitle(s->window, mactitle);
944 * Resize the window at the emulator's request
946 void request_resize(int w, int h) {
950 mac_initfont(onlysession);
954 * Set the logical palette
956 void palette_set(int n, int r, int g, int b) {
958 struct mac_session *s = onlysession;
959 static const int first[21] = {
960 0, 2, 4, 6, 8, 10, 12, 14,
961 1, 3, 5, 7, 9, 11, 13, 15,
965 if (mac_gestalts.qdvers == gestaltOriginalQD)
967 col.red = r * 0x0101;
968 col.green = g * 0x0101;
969 col.blue = b * 0x0101;
970 SetEntryColor(s->palette, first[n], &col);
972 SetEntryColor(s->palette, first[n]+1, &col);
973 if (first[n] == DEFAULT_BG)
975 ActivatePalette(s->window);
979 * Reset to the default palette
981 void palette_reset(void) {
982 struct mac_session *s = onlysession;
984 if (mac_gestalts.qdvers == gestaltOriginalQD)
986 CopyPalette(cfg.colours, s->palette, 0, 0, (*cfg.colours)->pmEntries);
988 ActivatePalette(s->window);
989 /* Palette Manager will generate update events as required. */
993 * Scroll the screen. (`lines' is +ve for scrolling forward, -ve
996 void do_scroll(int topline, int botline, int lines) {
997 struct mac_session *s = onlysession;
1002 PmBackColor(DEFAULT_BG);
1004 SetRect(&r, 0, topline * font_height,
1005 cols * font_width, (botline + 1) * font_height);
1006 ScrollRect(&r, 0, - lines * font_height, update);
1007 /* XXX: move update region? */
1015 * c-file-style: "simon"