1 /* $Id: macterm.c,v 1.1.2.30 1999/03/28 02:06:10 ben Exp $ */
3 * Copyright (c) 1999 Ben Harris
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * macterm.c -- Macintosh terminal front-end
36 #include <MacMemory.h>
37 #include <MacWindows.h>
38 #include <MixedMode.h>
40 #include <Quickdraw.h>
41 #include <QuickdrawText.h>
42 #include <Resources.h>
46 #include <ToolUtils.h>
58 #define DEFAULT_FG_BOLD 17
60 #define DEFAULT_BG_BOLD 19
62 #define CURSOR_FG_BOLD 21
64 #define CURSOR_BG_BOLD 23
66 #define PTOCC(x) ((x) < 0 ? -(-(x - font_width - 1) / font_width) : \
68 #define PTOCR(y) ((y) < 0 ? -(-(y - font_height - 1) / font_height) : \
76 PaletteHandle palette;
77 ControlHandle scrollbar;
81 static void mac_initfont(struct mac_session *);
82 static void mac_initpalette(struct mac_session *);
83 static void mac_adjustwinbg(struct mac_session *);
84 static void mac_adjustsize(struct mac_session *, int, int);
85 static void mac_drawgrowicon(struct mac_session *s);
86 static pascal void mac_scrolltracker(ControlHandle, short);
87 static pascal void do_text_for_device(short, short, GDHandle, long);
88 static pascal void mac_set_attr_mask(short, short, GDHandle, long);
89 static int mac_keytrans(struct mac_session *, EventRecord *, unsigned char *);
90 static void text_click(struct mac_session *, EventRecord *);
93 static RoutineDescriptor mac_scrolltracker_upp =
94 BUILD_ROUTINE_DESCRIPTOR(uppControlActionProcInfo,
95 (ProcPtr)mac_scrolltracker);
96 static RoutineDescriptor do_text_for_device_upp =
97 BUILD_ROUTINE_DESCRIPTOR(uppDeviceLoopDrawingProcInfo,
98 (ProcPtr)do_text_for_device);
99 static RoutineDescriptor mac_set_attr_mask_upp =
100 BUILD_ROUTINE_DESCRIPTOR(uppDeviceLoopDrawingProcInfo,
101 (ProcPtr)mac_set_attr_mask);
102 #else /* not TARGET_RT_MAC_CFM */
103 #define mac_scrolltracker_upp mac_scrolltracker
104 #define do_text_for_device_upp do_text_for_device
105 #define mac_set_attr_mask_upp mac_set_attr_mask
106 #endif /* not TARGET_RT_MAC_CFM */
109 * Temporary hack till I get the terminal emulator supporting multiple
113 static struct mac_session *onlysession;
115 static void inbuf_putc(int c) {
116 inbuf[inbuf_head] = c;
117 inbuf_head = (inbuf_head+1) & INBUF_MASK;
120 static void inbuf_putstr(const char *c) {
125 static void display_resource(unsigned long type, short id) {
130 h = GetResource(type, id);
132 fatalbox("Can't get test resource");
133 SetResAttrs(h, GetResAttrs(h) | resLocked);
135 len = GetResourceSizeOnDisk(h);
136 for (i = 0; i < len; i++) {
140 SetResAttrs(h, GetResAttrs(h) & ~resLocked);
145 void mac_newsession(void) {
146 struct mac_session *s;
150 /* This should obviously be initialised by other means */
151 mac_loadconfig(&cfg);
152 back = &loop_backend;
153 s = smalloc(sizeof(*s));
154 memset(s, 0, sizeof(*s));
157 /* XXX: Own storage management? */
158 if (mac_gestalts.qdvers == gestaltOriginalQD)
159 s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
161 s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1);
162 SetWRefCon(s->window, (long)s);
163 s->scrollbar = GetNewControl(cVScroll, s->window);
165 term_size(cfg.height, cfg.width, cfg.savelines);
168 attr_mask = ATTR_MASK;
169 /* Set to FALSE to not get palette updates in the background. */
170 SetPalette(s->window, s->palette, TRUE);
171 ActivatePalette(s->window);
172 ShowWindow(s->window);
173 starttime = TickCount();
174 display_resource('pTST', 128);
175 sprintf(msg, "Elapsed ticks: %d\015\012", TickCount() - starttime);
180 static void mac_initfont(struct mac_session *s) {
185 macfont[0] = sprintf((char *)&macfont[1], "%s", cfg.font);
186 GetFNum(macfont, &s->fontnum);
187 TextFont(s->fontnum);
188 TextFace(cfg.fontisbold ? bold : 0);
189 TextSize(cfg.fontheight);
191 font_width = CharWidth('W'); /* Well, it's what NCSA uses. */
192 s->font_ascent = fi.ascent;
193 s->font_leading = fi.leading;
194 font_height = s->font_ascent + fi.descent + s->font_leading;
195 mac_adjustsize(s, rows, cols);
199 * To be called whenever the window size changes.
200 * rows and cols should be desired values.
201 * It's assumed the terminal emulator will be informed, and will set rows
204 static void mac_adjustsize(struct mac_session *s, int newrows, int newcols) {
205 int winwidth, winheight;
207 winwidth = newcols * font_width + 15;
208 winheight = newrows * font_height;
209 SizeWindow(s->window, winwidth, winheight, true);
210 HideControl(s->scrollbar);
211 MoveControl(s->scrollbar, winwidth - 15, -1);
212 SizeControl(s->scrollbar, 16, winheight - 13);
213 ShowControl(s->scrollbar);
216 static void mac_initpalette(struct mac_session *s) {
218 if (mac_gestalts.qdvers == gestaltOriginalQD)
220 s->palette = NewPalette((*cfg.colours)->pmEntries, NULL, pmCourteous, 0);
221 if (s->palette == NULL)
222 fatalbox("Unable to create palette");
223 CopyPalette(cfg.colours, s->palette, 0, 0, (*cfg.colours)->pmEntries);
228 * Set the background colour of the window correctly. Should be
229 * called whenever the default background changes.
231 static void mac_adjustwinbg(struct mac_session *s) {
233 #if 0 /* XXX doesn't link (at least for 68k) */
234 if (mac_gestalts.windattr & gestaltWindowMgrPresent)
235 SetWindowContentColor(s->window,
236 &(*s->palette)->pmInfo[DEFAULT_BG].ciRGB);
240 if (s->wctab == NULL)
241 s->wctab = (WCTabHandle)NewHandle(sizeof(**s->wctab));
242 if (s->wctab == NULL)
243 return; /* do without */
244 (*s->wctab)->wCSeed = 0;
245 (*s->wctab)->wCReserved = 0;
246 (*s->wctab)->ctSize = 0;
247 (*s->wctab)->ctTable[0].value = wContentColor;
248 (*s->wctab)->ctTable[0].rgb = (*s->palette)->pmInfo[DEFAULT_BG].ciRGB;
249 SetWinColor(s->window, s->wctab);
254 * Set the cursor shape correctly
256 void mac_adjusttermcursor(WindowPtr window, Point mouse, RgnHandle cursrgn) {
257 struct mac_session *s;
258 ControlHandle control;
263 s = (struct mac_session *)GetWRefCon(window);
264 GlobalToLocal(&mouse);
265 part = FindControl(mouse, window, &control);
266 if (control == s->scrollbar) {
267 SetCursor(&qd.arrow);
268 RectRgn(cursrgn, &(*s->scrollbar)->contrlRect);
269 SectRgn(cursrgn, window->visRgn, cursrgn);
271 x = mouse.h / font_width;
272 y = mouse.v / font_height;
273 SetCursor(*GetCursor(iBeamCursor));
274 /* Ask for shape changes if we leave this character cell. */
275 SetRectRgn(cursrgn, x * font_width, y * font_height,
276 (x + 1) * font_width, (y + 1) * font_height);
277 SectRgn(cursrgn, window->visRgn, cursrgn);
282 * Enable/disable menu items based on the active terminal window.
284 void mac_adjusttermmenus(WindowPtr window) {
285 struct mac_session *s;
289 s = (struct mac_session *)GetWRefCon(window);
290 menu = GetMenuHandle(mEdit);
292 DisableItem(menu, iUndo);
293 DisableItem(menu, iCut);
294 if (term_hasselection())
295 EnableItem(menu, iCopy);
297 DisableItem(menu, iCopy);
298 if (GetScrap(NULL, 'TEXT', &offset) == noTypeErr)
299 DisableItem(menu, iPaste);
301 EnableItem(menu, iPaste);
302 DisableItem(menu, iClear);
303 EnableItem(menu, iSelectAll);
306 void mac_menuterm(WindowPtr window, short menu, short item) {
307 struct mac_session *s;
309 s = (struct mac_session *)GetWRefCon(window);
323 void mac_clickterm(WindowPtr window, EventRecord *event) {
324 struct mac_session *s;
326 ControlHandle control;
329 s = (struct mac_session *)GetWRefCon(window);
331 mouse = event->where;
332 GlobalToLocal(&mouse);
333 part = FindControl(mouse, window, &control);
334 if (control == s->scrollbar) {
336 case kControlIndicatorPart:
337 if (TrackControl(control, mouse, NULL) == kControlIndicatorPart)
338 term_scroll(+1, GetControlValue(control));
340 case kControlUpButtonPart:
341 case kControlDownButtonPart:
342 case kControlPageUpPart:
343 case kControlPageDownPart:
344 TrackControl(control, mouse, &mac_scrolltracker_upp);
348 text_click(s, event);
352 static void text_click(struct mac_session *s, EventRecord *event) {
355 static UInt32 lastwhen = 0;
356 static struct mac_session *lastsess = NULL;
357 static int lastrow = -1, lastcol = -1;
358 static Mouse_Action lastact = MA_NOTHING;
361 localwhere = event->where;
362 GlobalToLocal(&localwhere);
364 col = PTOCC(localwhere.h);
365 row = PTOCR(localwhere.v);
366 if (event->when - lastwhen < GetDblTime() &&
367 row == lastrow && col == lastcol && s == lastsess)
368 lastact = (lastact == MA_CLICK ? MA_2CLK :
369 lastact == MA_2CLK ? MA_3CLK :
370 lastact == MA_3CLK ? MA_CLICK : MA_NOTHING);
373 term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT, lastact,
378 while (StillDown()) {
379 GetMouse(&localwhere);
380 col = PTOCC(localwhere.h);
381 row = PTOCR(localwhere.v);
382 term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT,
385 term_scroll(0, row - (rows - 1));
389 term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT, MA_RELEASE,
391 lastwhen = TickCount();
394 void write_clip(void *data, int len) {
396 if (ZeroScrap() != noErr)
398 PutScrap(len, 'TEXT', data);
401 void get_clip(void **p, int *lenp) {
402 static Handle h = NULL;
411 if (GetScrap(NULL, 'TEXT', &offset) > 0) {
413 *lenp = GetScrap(h, 'TEXT', &offset);
416 if (*p == NULL || *lenp <= 0)
417 fatalbox("Empty scrap");
424 static pascal void mac_scrolltracker(ControlHandle control, short part) {
425 struct mac_session *s;
427 s = (struct mac_session *)GetWRefCon((*control)->contrlOwner);
429 case kControlUpButtonPart:
432 case kControlDownButtonPart:
435 case kControlPageUpPart:
436 term_scroll(0, -(rows - 1));
438 case kControlPageDownPart:
439 term_scroll(0, +(rows - 1));
444 #define K_SPACE 0x3100
458 #define K_INSERT 0x7200
459 #define K_HOME 0x7300
460 #define K_PRIOR 0x7400
461 #define K_DELETE 0x7500
463 #define K_NEXT 0x7900
464 #define K_LEFT 0x7b00
465 #define K_RIGHT 0x7c00
466 #define K_DOWN 0x7d00
478 #define KP_CLEAR 0x4700
479 #define KP_EQUAL 0x5100
480 #define KP_SLASH 0x4b00
481 #define KP_STAR 0x4300
482 #define KP_PLUS 0x4500
483 #define KP_MINUS 0x4e00
484 #define KP_DOT 0x4100
485 #define KP_ENTER 0x4c00
487 void mac_keyterm(WindowPtr window, EventRecord *event) {
488 unsigned char buf[20];
490 struct mac_session *s;
492 s = (struct mac_session *)GetWRefCon(window);
493 len = mac_keytrans(s, event, buf);
494 back->send((char *)buf, len);
497 static UInt32 mac_rekey(EventModifiers newmodifiers, UInt32 oldmessage) {
498 UInt32 transresult, state;
502 kchr = (Ptr)GetScriptManagerVariable(smKCHRCache);
503 transresult = KeyTranslate(kchr,
504 (oldmessage & keyCodeMask) >> 8 |
505 newmodifiers & 0xff00,
508 * KeyTranslate returns two character codes. We only worry about
509 * one. Yes, this is slightly bogus, but it makes life less
512 return oldmessage & ~charCodeMask | transresult & 0xff;
516 static int mac_keytrans(struct mac_session *s, EventRecord *event,
517 unsigned char *output) {
518 unsigned char *p = output;
521 /* No meta key yet -- that'll be rather fun. */
523 /* Check if the meta "key" was held down */
525 if ((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers) {
527 event->modifiers &= ~cfg.meta_modifiers;
528 event->message = mac_rekey(event->modifiers, event->message);
531 /* Keys that we handle locally */
532 if (event->modifiers & shiftKey) {
533 switch (event->message & keyCodeMask) {
534 case K_PRIOR: /* shift-pageup */
535 term_scroll(0, -(rows - 1));
537 case K_NEXT: /* shift-pagedown */
538 term_scroll(0, +(rows - 1));
544 * Control-2 should return ^@ (0x00), Control-6 should return
545 * ^^ (0x1E), and Control-Minus should return ^_ (0x1F). Since
546 * the DOS keyboard handling did it, and we have nothing better
547 * to do with the key combo in question, we'll also map
548 * Control-Backquote to ^\ (0x1C).
551 if (event->modifiers & controlKey) {
552 switch (event->message & charCodeMask) {
569 * First, all the keys that do tilde codes. (ESC '[' nn '~',
570 * for integer decimal nn.)
572 * We also deal with the weird ones here. Linux VCs replace F1
573 * to F5 by ESC [ [ A to ESC [ [ E. rxvt doesn't do _that_, but
574 * does replace Home and End (1~ and 4~) by ESC [ H and ESC O w
578 switch (event->message & keyCodeMask) {
579 case K_F1: code = (event->modifiers & shiftKey ? 23 : 11); break;
580 case K_F2: code = (event->modifiers & shiftKey ? 24 : 12); break;
581 case K_F3: code = (event->modifiers & shiftKey ? 25 : 13); break;
582 case K_F4: code = (event->modifiers & shiftKey ? 26 : 14); break;
583 case K_F5: code = (event->modifiers & shiftKey ? 28 : 15); break;
584 case K_F6: code = (event->modifiers & shiftKey ? 29 : 17); break;
585 case K_F7: code = (event->modifiers & shiftKey ? 31 : 18); break;
586 case K_F8: code = (event->modifiers & shiftKey ? 32 : 19); break;
587 case K_F9: code = (event->modifiers & shiftKey ? 33 : 20); break;
588 case K_F10: code = (event->modifiers & shiftKey ? 34 : 21); break;
589 case K_F11: code = 23; break;
590 case K_F12: code = 24; break;
591 case K_HOME: code = 1; break;
592 case K_INSERT: code = 2; break;
593 case K_DELETE: code = 3; break;
594 case K_END: code = 4; break;
595 case K_PRIOR: code = 5; break;
596 case K_NEXT: code = 6; break;
598 if (cfg.linux_funkeys && code >= 11 && code <= 15) {
599 p += sprintf((char *)p, "\x1B[[%c", code + 'A' - 11);
602 if (cfg.rxvt_homeend && (code == 1 || code == 4)) {
603 p += sprintf((char *)p, code == 1 ? "\x1B[H" : "\x1BOw");
607 p += sprintf((char *)p, "\x1B[%d~", code);
611 if (app_keypad_keys) {
612 switch (event->message & keyCodeMask) {
613 case KP_ENTER: p += sprintf((char *)p, "\x1BOM"); return p - output;
614 case KP_CLEAR: p += sprintf((char *)p, "\x1BOP"); return p - output;
615 case KP_EQUAL: p += sprintf((char *)p, "\x1BOQ"); return p - output;
616 case KP_SLASH: p += sprintf((char *)p, "\x1BOR"); return p - output;
617 case KP_STAR: p += sprintf((char *)p, "\x1BOS"); return p - output;
618 case KP_PLUS: p += sprintf((char *)p, "\x1BOl"); return p - output;
619 case KP_MINUS: p += sprintf((char *)p, "\x1BOm"); return p - output;
620 case KP_DOT: p += sprintf((char *)p, "\x1BOn"); return p - output;
621 case KP_0: p += sprintf((char *)p, "\x1BOp"); return p - output;
622 case KP_1: p += sprintf((char *)p, "\x1BOq"); return p - output;
623 case KP_2: p += sprintf((char *)p, "\x1BOr"); return p - output;
624 case KP_3: p += sprintf((char *)p, "\x1BOs"); return p - output;
625 case KP_4: p += sprintf((char *)p, "\x1BOt"); return p - output;
626 case KP_5: p += sprintf((char *)p, "\x1BOu"); return p - output;
627 case KP_6: p += sprintf((char *)p, "\x1BOv"); return p - output;
628 case KP_7: p += sprintf((char *)p, "\x1BOw"); return p - output;
629 case KP_8: p += sprintf((char *)p, "\x1BOx"); return p - output;
630 case KP_9: p += sprintf((char *)p, "\x1BOy"); return p - output;
634 switch (event->message & keyCodeMask) {
636 p += sprintf((char *)p, app_cursor_keys ? "\x1BOA" : "\x1B[A");
639 p += sprintf((char *)p, app_cursor_keys ? "\x1BOB" : "\x1B[B");
642 p += sprintf((char *)p, app_cursor_keys ? "\x1BOC" : "\x1B[C");
645 p += sprintf((char *)p, app_cursor_keys ? "\x1BOD" : "\x1B[D");
648 *p++ = (cfg.bksp_is_delete ? 0x7f : 0x08);
651 *p++ = event->message & charCodeMask;
656 void mac_growterm(WindowPtr window, EventRecord *event) {
659 int newrows, newcols;
660 struct mac_session *s;
662 s = (struct mac_session *)GetWRefCon(window);
663 SetRect(&limits, font_width + 15, font_height, SHRT_MAX, SHRT_MAX);
664 grow_result = GrowWindow(window, event->where, &limits);
665 if (grow_result != 0) {
666 newrows = HiWord(grow_result) / font_height;
667 newcols = (LoWord(grow_result) - 15) / font_width;
668 mac_adjustsize(s, newrows, newcols);
669 term_size(newrows, newcols, cfg.savelines);
673 void mac_activateterm(WindowPtr window, Boolean active) {
674 struct mac_session *s;
676 s = (struct mac_session *)GetWRefCon(window);
680 ShowControl(s->scrollbar);
682 PmBackColor(DEFAULT_BG); /* HideControl clears behind the control */
683 HideControl(s->scrollbar);
688 void mac_updateterm(WindowPtr window) {
689 struct mac_session *s;
691 s = (struct mac_session *)GetWRefCon(window);
695 (*window->visRgn)->rgnBBox.left,
696 (*window->visRgn)->rgnBBox.top,
697 (*window->visRgn)->rgnBBox.right,
698 (*window->visRgn)->rgnBBox.bottom);
699 /* Restore default colours in case the Window Manager uses them */
700 PmForeColor(DEFAULT_FG);
701 PmBackColor(DEFAULT_BG);
702 if (FrontWindow() != window)
703 EraseRect(&(*s->scrollbar)->contrlRect);
704 UpdateControls(window, window->visRgn);
710 static void mac_drawgrowicon(struct mac_session *s) {
714 /* Stop DrawGrowIcon giving us space for a horizontal scrollbar */
715 SetRect(&clip, s->window->portRect.right - 15, SHRT_MIN,
718 DrawGrowIcon(s->window);
719 clip.left = SHRT_MIN;
723 struct do_text_args {
724 struct mac_session *s;
733 * Call from the terminal emulator to draw a bit of text
735 * x and y are text row and column (zero-based)
737 void do_text(struct mac_session *s, int x, int y, char *text, int len,
738 unsigned long attr) {
740 struct do_text_args a;
745 /* First check this text is relevant */
746 a.textrect.top = y * font_height;
747 a.textrect.bottom = (y + 1) * font_height;
748 a.textrect.left = x * font_width;
749 a.textrect.right = (x + len) * font_width;
750 if (!RectInRgn(&a.textrect, s->window->visRgn))
757 if (s->font_leading > 0)
759 a.textrect.left, a.textrect.bottom - s->font_leading,
760 a.textrect.right, a.textrect.bottom);
762 SetRect(&a.leadrect, 0, 0, 0, 0);
764 TextFont(s->fontnum);
765 if (cfg.fontisbold || (attr & ATTR_BOLD) && !cfg.bold_colour)
767 if (attr & ATTR_UNDER)
770 TextSize(cfg.fontheight);
771 SetFractEnable(FALSE); /* We want characters on pixel boundaries */
773 RectRgn(textrgn, &a.textrect);
774 DeviceLoop(textrgn, &do_text_for_device_upp, (long)&a, 0);
776 /* Tell the window manager about it in case this isn't an update */
777 ValidRect(&a.textrect);
780 static pascal void do_text_for_device(short depth, short devflags,
781 GDHandle device, long cookie) {
782 struct do_text_args *a;
783 int bgcolour, fgcolour, bright;
785 a = (struct do_text_args *)cookie;
787 bright = (a->attr & ATTR_BOLD) && cfg.bold_colour;
789 TextMode(a->attr & ATTR_REVERSE ? notSrcCopy : srcCopy);
793 /* XXX This should be done with a _little_ more configurability */
794 ForeColor(whiteColor);
795 BackColor(blackColor);
796 if (a->attr & ATTR_ACTCURS)
797 TextMode(a->attr & ATTR_REVERSE ? srcCopy : notSrcCopy);
800 if (a->attr & ATTR_ACTCURS) {
801 PmForeColor(bright ? CURSOR_FG_BOLD : CURSOR_FG);
802 PmBackColor(CURSOR_BG);
805 PmForeColor(bright ? DEFAULT_FG_BOLD : DEFAULT_FG);
806 PmBackColor(DEFAULT_BG);
810 if (a->attr & ATTR_ACTCURS) {
811 fgcolour = bright ? CURSOR_FG_BOLD : CURSOR_FG;
812 bgcolour = CURSOR_BG;
815 fgcolour = ((a->attr & ATTR_FGMASK) >> ATTR_FGSHIFT) * 2;
816 bgcolour = ((a->attr & ATTR_BGMASK) >> ATTR_BGSHIFT) * 2;
818 if (a->attr & ATTR_REVERSE)
823 PmForeColor(fgcolour);
824 PmBackColor(bgcolour);
828 if (a->attr & ATTR_REVERSE)
829 PaintRect(&a->leadrect);
831 EraseRect(&a->leadrect);
832 MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent);
833 DrawText(a->text, 0, a->len);
835 if (a->attr & ATTR_PASCURS) {
842 PmForeColor(CURSOR_BG);
845 FrameRect(&a->textrect);
850 * Call from the terminal emulator to get its graphics context.
851 * Should probably be called start_redraw or something.
853 struct mac_session *get_ctx(void) {
854 struct mac_session *s = onlysession;
856 attr_mask = ATTR_INVALID;
857 DeviceLoop(s->window->visRgn, &mac_set_attr_mask_upp, (long)s, 0);
861 static pascal void mac_set_attr_mask(short depth, short devflags,
862 GDHandle device, long cookie) {
866 attr_mask |= ATTR_FGMASK | ATTR_BGMASK;
869 attr_mask |= ATTR_BOLD;
872 attr_mask |= ATTR_UNDER | ATTR_REVERSE | ATTR_ACTCURS |
873 ATTR_PASCURS | ATTR_ASCII | ATTR_GBCHR | ATTR_LINEDRW |
874 (cfg.bold_colour ? 0 : ATTR_BOLD);
880 * Presumably this does something in Windows
882 void free_ctx(struct mac_session *ctx) {
887 * Set the scroll bar position
889 * total is the line number of the bottom of the working screen
890 * start is the line number of the top of the display
891 * page is the length of the displayed page
893 void set_sbar(int total, int start, int page) {
894 struct mac_session *s = onlysession;
896 /* We don't redraw until we've set everything up, to avoid glitches */
897 (*s->scrollbar)->contrlMin = 0;
898 (*s->scrollbar)->contrlMax = total - page;
899 SetControlValue(s->scrollbar, start);
901 /* XXX: This doesn't link for me. */
902 if (mac_gestalts.cntlattr & gestaltControlMgrPresent)
903 SetControlViewSize(s->scrollbar, page);
914 * XXX We should indicate the relevant window and/or use the
915 * Notification Manager
920 * Set icon string -- a no-op here (Windowshade?)
922 void set_icon(char *icon) {
927 * Set the window title
929 void set_title(char *title) {
931 struct mac_session *s = onlysession;
933 mactitle[0] = sprintf((char *)&mactitle[1], "%s", title);
934 SetWTitle(s->window, mactitle);
938 * Resize the window at the emulator's request
940 void request_resize(int w, int h) {
944 mac_initfont(onlysession);
948 * Set the logical palette
950 void palette_set(int n, int r, int g, int b) {
952 struct mac_session *s = onlysession;
953 static const int first[21] = {
954 0, 2, 4, 6, 8, 10, 12, 14,
955 1, 3, 5, 7, 9, 11, 13, 15,
959 if (mac_gestalts.qdvers == gestaltOriginalQD)
961 col.red = r * 0x0101;
962 col.green = g * 0x0101;
963 col.blue = b * 0x0101;
964 SetEntryColor(s->palette, first[n], &col);
966 SetEntryColor(s->palette, first[n]+1, &col);
967 if (first[n] == DEFAULT_BG)
969 ActivatePalette(s->window);
973 * Reset to the default palette
975 void palette_reset(void) {
976 struct mac_session *s = onlysession;
978 if (mac_gestalts.qdvers == gestaltOriginalQD)
980 CopyPalette(cfg.colours, s->palette, 0, 0, (*cfg.colours)->pmEntries);
982 ActivatePalette(s->window);
983 /* Palette Manager will generate update events as required. */
987 * Scroll the screen. (`lines' is +ve for scrolling forward, -ve
990 void do_scroll(int topline, int botline, int lines) {
991 struct mac_session *s = onlysession;
996 PmBackColor(DEFAULT_BG);
998 SetRect(&r, 0, topline * font_height,
999 cols * font_width, (botline + 1) * font_height);
1000 ScrollRect(&r, 0, - lines * font_height, update);
1001 /* XXX: move update region? */
1009 * c-file-style: "simon"