-/* $Id: macterm.c,v 1.2 2002/11/19 22:05:48 ben Exp $ */
+/* $Id: macterm.c,v 1.16 2002/11/29 00:32:03 ben Exp $ */
/*
* Copyright (c) 1999 Simon Tatham
* Copyright (c) 1999, 2002 Ben Harris
#define DEFAULT_BG 18
#define DEFAULT_BG_BOLD 19
#define CURSOR_FG 20
-#define CURSOR_FG_BOLD 21
-#define CURSOR_BG 22
-#define CURSOR_BG_BOLD 23
+#define CURSOR_BG 21
#define PTOCC(x) ((x) < 0 ? -(-(x - s->font_width - 1) / s->font_width) : \
(x) / s->font_width)
static RoutineDescriptor do_text_for_device_upp =
BUILD_ROUTINE_DESCRIPTOR(uppDeviceLoopDrawingProcInfo,
(ProcPtr)do_text_for_device);
-static RoutineDescriptor mac_set_attr_mask_upp =
- BUILD_ROUTINE_DESCRIPTOR(uppDeviceLoopDrawingProcInfo,
- (ProcPtr)mac_set_attr_mask);
#else /* not TARGET_RT_MAC_CFM */
#define mac_scrolltracker_upp mac_scrolltracker
#define do_text_for_device_upp do_text_for_device
-#define mac_set_attr_mask_upp mac_set_attr_mask
#endif /* not TARGET_RT_MAC_CFM */
static void inbuf_putc(Session *s, int c) {
s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
SetWRefCon(s->window, (long)s);
s->scrollbar = GetNewControl(cVScroll, s->window);
- s->term = term_init(s);
+ s->term = term_init(&s->cfg, s);
s->logctx = log_init(s);
term_provide_logctx(s->term, s->logctx);
mac_adjustsize(s, s->cfg.height, s->cfg.width);
term_size(s->term, s->cfg.height, s->cfg.width, s->cfg.savelines);
- s->ldisc = ldisc_create(s->term, s->back, s->backhandle, s);
+ s->ldisc = ldisc_create(&s->cfg, s->term, s->back, s->backhandle, s);
ldisc_send(s->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */
mac_initfont(s);
mac_initpalette(s);
- s->attr_mask = ATTR_MASK;
if (HAVE_COLOR_QD()) {
/* Set to FALSE to not get palette updates in the background. */
SetPalette(s->window, s->palette, TRUE);
static void mac_initpalette(Session *s) {
int i;
+ if (!HAVE_COLOR_QD())
+ return;
/*
* Most colours should be inhibited on 2bpp displays.
* Palette manager documentation suggests inhibiting all tolerant colours
* on greyscale displays.
*/
-#define PM_NORMAL pmTolerant | pmInhibitC2 | \
- pmInhibitG2 | pmInhibitG4 | pmInhibitG8 | pmInhibitC2
+#define PM_NORMAL ( pmTolerant | pmInhibitC2 | \
+ pmInhibitG2 | pmInhibitG4 | pmInhibitG8 )
#define PM_TOLERANCE 0x2000
s->palette = NewPalette(22, NULL, PM_NORMAL, PM_TOLERANCE);
if (s->palette == NULL)
PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
SetEntryUsage(s->palette, DEFAULT_FG_BOLD,
PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
- SetEntryUsage(s->palette, CURSOR_FG,
+ SetEntryUsage(s->palette, CURSOR_BG,
PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
palette_reset(s);
}
s = (Session *)GetWRefCon(window);
len = mac_keytrans(s, event, buf);
- s->back->send(s, (char *)buf, len);
+ ldisc_send(s->ldisc, (char *)buf, len, 1);
+ ObscureCursor();
+ term_seen_key_event(s->term);
+ term_out(s->term);
+ term_update(s->term);
}
static int mac_keytrans(Session *s, EventRecord *event,
Session *s;
s = (Session *)GetWRefCon(window);
- s->has_focus = active;
+ s->term->has_focus = active;
term_update(s->term);
if (active)
ShowControl(s->scrollbar);
static void mac_drawgrowicon(Session *s) {
Rect clip;
+ RgnHandle savergn;
SetPort(s->window);
- /* Stop DrawGrowIcon giving us space for a horizontal scrollbar */
- SetRect(&clip, s->window->portRect.right - 15, SHRT_MIN,
- SHRT_MAX, SHRT_MAX);
+ /*
+ * Stop DrawGrowIcon giving us space for a horizontal scrollbar
+ * See Tech Note TB575 for details.
+ */
+ clip = s->window->portRect;
+ clip.left = clip.right - 15;
+ savergn = NewRgn();
+ GetClip(savergn);
ClipRect(&clip);
DrawGrowIcon(s->window);
- clip.left = SHRT_MIN;
- ClipRect(&clip);
+ SetClip(savergn);
+ DisposeRgn(savergn);
}
struct do_text_args {
Session *s;
Rect textrect;
- Rect leadrect;
char *text;
int len;
unsigned long attr;
int lattr;
+ Point numer, denom;
};
/*
int style = 0;
struct do_text_args a;
RgnHandle textrgn;
-#if 0
- int i;
-#endif
SetPort(s->window);
-#if 0
- fprintf(stderr, "printing at (%d,%d) %d chars (attr=%x, lattr=%x):\n",
- x, y, len, attr, lattr);
- for (i = 0; i < len; i++)
- fprintf(stderr, "%c", text[i]);
- fprintf(stderr, "\n");
-#endif
-
/* First check this text is relevant */
a.textrect.top = y * s->font_height;
a.textrect.bottom = (y + 1) * s->font_height;
a.len = len;
a.attr = attr;
a.lattr = lattr;
- if (s->font_leading > 0)
- SetRect(&a.leadrect,
- a.textrect.left, a.textrect.bottom - s->font_leading,
- a.textrect.right, a.textrect.bottom);
- else
- SetRect(&a.leadrect, 0, 0, 0, 0);
+ a.numer.h = a.numer.v = a.denom.h = a.denom.v = 1;
SetPort(s->window);
TextFont(s->fontnum);
if (s->cfg.fontisbold || (attr & ATTR_BOLD) && !s->cfg.bold_colour)
style |= underline;
TextFace(style);
TextSize(s->cfg.fontheight);
- SetFractEnable(FALSE); /* We want characters on pixel boundaries */
+ TextMode(srcOr);
if (HAVE_COLOR_QD())
if (style & bold) {
SpaceExtra(s->font_boldadjust << 16);
static pascal void do_text_for_device(short depth, short devflags,
GDHandle device, long cookie) {
struct do_text_args *a;
- int bgcolour, fgcolour, bright;
+ int bgcolour, fgcolour, bright, reverse, tmp;
a = (struct do_text_args *)cookie;
bright = (a->attr & ATTR_BOLD) && a->s->cfg.bold_colour;
+ reverse = a->attr & ATTR_REVERSE;
- TextMode(a->attr & ATTR_REVERSE ? notSrcCopy : srcCopy);
+ if (depth == 1 && (a->attr & TATTR_ACTCURS))
+ reverse = !reverse;
- switch (depth) {
- case 1:
- /* XXX This should be done with a _little_ more configurability */
- ForeColor(whiteColor);
- BackColor(blackColor);
- if (a->attr & TATTR_ACTCURS)
- TextMode(a->attr & ATTR_REVERSE ? srcCopy : notSrcCopy);
- break;
- case 2:
- if (a->attr & TATTR_ACTCURS) {
- PmForeColor(bright ? CURSOR_FG_BOLD : CURSOR_FG);
- PmBackColor(CURSOR_BG);
- TextMode(srcCopy);
+ if (HAVE_COLOR_QD()) {
+ if (depth > 2) {
+ fgcolour = ((a->attr & ATTR_FGMASK) >> ATTR_FGSHIFT) * 2;
+ bgcolour = ((a->attr & ATTR_BGMASK) >> ATTR_BGSHIFT) * 2;
} else {
- PmForeColor(bright ? DEFAULT_FG_BOLD : DEFAULT_FG);
- PmBackColor(DEFAULT_BG);
+ /*
+ * NB: bold reverse in 2bpp breaks with the usual PuTTY model and
+ * boldens the background, because that's all we can do.
+ */
+ fgcolour = bright ? DEFAULT_FG_BOLD : DEFAULT_FG;
+ bgcolour = DEFAULT_BG;
}
- break;
- default:
- if (a->attr & TATTR_ACTCURS) {
- fgcolour = bright ? CURSOR_FG_BOLD : CURSOR_FG;
+ if (reverse) {
+ tmp = fgcolour;
+ fgcolour = bgcolour;
+ bgcolour = tmp;
+ }
+ if (bright && depth > 2)
+ fgcolour++;
+ if ((a->attr & TATTR_ACTCURS) && depth > 1) {
+ fgcolour = CURSOR_FG;
bgcolour = CURSOR_BG;
- TextMode(srcCopy);
- } else {
- fgcolour = ((a->attr & ATTR_FGMASK) >> ATTR_FGSHIFT) * 2;
- bgcolour = ((a->attr & ATTR_BGMASK) >> ATTR_BGSHIFT) * 2;
- if (bright)
- if (a->attr & ATTR_REVERSE)
- bgcolour++;
- else
- fgcolour++;
}
PmForeColor(fgcolour);
PmBackColor(bgcolour);
- break;
+ } else { /* No Color Quickdraw */
+ /* XXX This should be done with a _little_ more configurability */
+ if (reverse) {
+ ForeColor(blackColor);
+ BackColor(whiteColor);
+ } else {
+ ForeColor(whiteColor);
+ BackColor(blackColor);
+ }
}
- if (a->attr & ATTR_REVERSE)
- PaintRect(&a->leadrect);
- else
- EraseRect(&a->leadrect);
+ EraseRect(&a->textrect);
MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent);
/* FIXME: Sort out bold width adjustments on Original QuickDraw. */
- DrawText(a->text, 0, a->len);
+ if (a->s->window->grafProcs != NULL)
+ InvokeQDTextUPP(a->len, a->text, a->numer, a->denom,
+ a->s->window->grafProcs->textProc);
+ else
+ StdText(a->len, a->text, a->numer, a->denom);
if (a->attr & TATTR_PASCURS) {
PenNormal();
unsigned long attr, int lattr)
{
- /* FIXME: Should do something here! */
+ do_text(ctx, x, y, text, len, attr, lattr);
}
/*
* Should probably be called start_redraw or something.
*/
void pre_paint(Session *s) {
+ GDHandle gdh;
+ Rect myrect, tmprect;
- s->attr_mask = ATTR_INVALID;
- if (HAVE_COLOR_QD())
- DeviceLoop(s->window->visRgn, &mac_set_attr_mask_upp, (long)s, 0);
- else
- mac_set_attr_mask(1, 0, NULL, (long)s);
+ s->term->attr_mask = 0xffffffff;
+ if (HAVE_COLOR_QD()) {
+ SetPort(s->window);
+ myrect = (*s->window->visRgn)->rgnBBox;
+ LocalToGlobal((Point *)&myrect.top);
+ LocalToGlobal((Point *)&myrect.bottom);
+ for (gdh = GetDeviceList();
+ gdh != NULL;
+ gdh = GetNextDevice(gdh)) {
+ if (TestDeviceAttribute(gdh, screenDevice) &&
+ TestDeviceAttribute(gdh, screenActive) &&
+ SectRect(&(*gdh)->gdRect, &myrect, &tmprect)) {
+ switch ((*(*gdh)->gdPMap)->pixelSize) {
+ case 1:
+ if (s->cfg.bold_colour)
+ s->term->attr_mask &= ~ATTR_BOLD;
+ /* FALLTHROUGH */
+ case 2:
+ s->term->attr_mask &= ~ATTR_COLOURS;
+ }
+ }
+ }
+ } else
+ s->term->attr_mask &= ~(ATTR_COLOURS |
+ (s->cfg.bold_colour ? ATTR_BOLD : 0));
}
Context get_ctx(void *frontend) {
}
-static pascal void mac_set_attr_mask(short depth, short devflags,
- GDHandle device, long cookie) {
-
- Session *s = (Session *)cookie;
-
- switch (depth) {
- default:
- s->attr_mask |= ATTR_FGMASK | ATTR_BGMASK;
- /* FALLTHROUGH */
- case 2:
- s->attr_mask |= ATTR_BOLD;
- /* FALLTHROUGH */
- case 1:
- s->attr_mask |= ATTR_UNDER | ATTR_REVERSE | TATTR_ACTCURS |
- TATTR_PASCURS | ATTR_ASCII | ATTR_GBCHR | ATTR_LINEDRW |
- (s->cfg.bold_colour ? 0 : ATTR_BOLD);
- break;
- }
-}
-
/*
* Presumably this does something in Windows
*/
col.red = r * 0x0101;
col.green = g * 0x0101;
col.blue = b * 0x0101;
- fprintf(stderr, "p%d <- (0x%x, 0x%x, 0x%x)\n", n, col.red, col.green,
- col.blue);
SetEntryColor(s->palette, n, &col);
}
static const int first[21] = {
0, 2, 4, 6, 8, 10, 12, 14,
1, 3, 5, 7, 9, 11, 13, 15,
- 16, 17, 18, 20, 22
+ 16, 17, 18, 20, 21
};
if (!HAVE_COLOR_QD())
return;
real_palette_set(s, first[n], r, g, b);
- if (first[n] >= 18)
+ if (first[n] == 18)
real_palette_set(s, first[n]+1, r, g, b);
if (first[n] == DEFAULT_BG)
mac_adjustwinbg(s);
Rect r;
RgnHandle update;
- /* FIXME: This is seriously broken on Original QuickDraw. No idea why. */
SetPort(s->window);
+ PenNormal();
if (HAVE_COLOR_QD())
PmBackColor(DEFAULT_BG);
else
- BackColor(blackColor);
+ BackColor(blackColor); /* XXX make configurable */
update = NewRgn();
SetRect(&r, 0, topline * s->font_height,
s->term->cols * s->font_width, (botline + 1) * s->font_height);