Add a "Config *" argument to term_init(), and use that instead of the global
[u/mdw/putty] / mac / macterm.c
index ebbc8c7..e2e33de 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macterm.c,v 1.1 2002/11/19 02:13:46 ben Exp $ */
+/* $Id: macterm.c,v 1.8 2002/11/23 19:01:01 ben Exp $ */
 /*
  * Copyright (c) 1999 Simon Tatham
  * Copyright (c) 1999, 2002 Ben Harris
@@ -66,9 +66,7 @@
 #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)
@@ -154,7 +152,7 @@ void mac_newsession(void) {
        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);
@@ -235,8 +233,8 @@ static void mac_initpalette(Session *s) {
      * 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)
@@ -248,7 +246,7 @@ static void mac_initpalette(Session *s) {
                  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);
 }
@@ -556,7 +554,11 @@ void mac_keyterm(WindowPtr window, EventRecord *event) {
 
     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,
@@ -731,7 +733,7 @@ void mac_activateterm(WindowPtr window, Boolean active) {
     Session *s;
 
     s = (Session *)GetWRefCon(window);
-    s->has_focus = active;
+    s->term->has_focus = active;
     term_update(s->term);
     if (active)
        ShowControl(s->scrollbar);
@@ -753,10 +755,10 @@ void mac_updateterm(WindowPtr window) {
     BeginUpdate(window);
     pre_paint(s);
     term_paint(s->term, s,
-              (*window->visRgn)->rgnBBox.left,
-              (*window->visRgn)->rgnBBox.top,
-              (*window->visRgn)->rgnBBox.right,
-              (*window->visRgn)->rgnBBox.bottom, 1);
+              PTOCC((*window->visRgn)->rgnBBox.left),
+              PTOCR((*window->visRgn)->rgnBBox.top),
+              PTOCC((*window->visRgn)->rgnBBox.right),
+              PTOCR((*window->visRgn)->rgnBBox.bottom), 1);
     /* Restore default colours in case the Window Manager uses them */
     if (HAVE_COLOR_QD()) {
        PmForeColor(DEFAULT_FG);
@@ -807,20 +809,9 @@ void do_text(Context ctx, int x, int y, char *text, int len,
     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;
@@ -889,7 +880,7 @@ static pascal void do_text_for_device(short depth, short devflags,
        break;
       case 2:
        if (a->attr & TATTR_ACTCURS) {
-           PmForeColor(bright ? CURSOR_FG_BOLD : CURSOR_FG);
+           PmForeColor(CURSOR_FG);
            PmBackColor(CURSOR_BG);
            TextMode(srcCopy);
        } else {
@@ -899,7 +890,7 @@ static pascal void do_text_for_device(short depth, short devflags,
        break;
       default:
        if (a->attr & TATTR_ACTCURS) {
-           fgcolour = bright ? CURSOR_FG_BOLD : CURSOR_FG;
+           fgcolour = CURSOR_FG;
            bgcolour = CURSOR_BG;
            TextMode(srcCopy);
        } else {
@@ -942,7 +933,7 @@ void do_cursor(Context ctx, int x, int y, char *text, int len,
             unsigned long attr, int lattr)
 {
 
-    /* FIXME: Should do something here! */
+    do_text(ctx, x, y, text, len, attr, lattr);
 }
 
 /*
@@ -1216,8 +1207,6 @@ static void real_palette_set(Session *s, int n, int r, int g, int b)
     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);
 }
 
@@ -1229,13 +1218,13 @@ void palette_set(void *frontend, int n, int r, int g, int b) {
     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);