]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Now uses the Palette Manager for everything. Unfortunately this seems to
authorBen Harris <bjh21@bjh21.me.uk>
Wed, 24 Feb 1999 01:29:10 +0000 (01:29 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Wed, 24 Feb 1999 01:29:10 +0000 (01:29 +0000)
have killed colour entirely.  It was working earlier today.  Really!

[originally from svn r60]

mac.c
mac_res.r
macresid.h
macterm.c
putty.h

diff --git a/mac.c b/mac.c
index b3d4aad8894a689bd51a0ce5b68c30e97543e463..4310212ef9dad7ecb46addf1bb8d9e6ae0c92d56 100644 (file)
--- a/mac.c
+++ b/mac.c
@@ -1,4 +1,4 @@
-/* $Id: mac.c,v 1.1.2.6 1999/02/21 18:09:41 ben Exp $ */
+/* $Id: mac.c,v 1.1.2.7 1999/02/24 01:29:10 ben Exp $ */
 /*
  * mac.c -- miscellaneous Mac-specific routines
  */
@@ -166,9 +166,6 @@ static void mac_contentclick(WindowPtr window, EventRecord *event) {
       case wAbout:
        if (DialogSelect(event, &(DialogPtr)window, &item))
            switch (item) {
-             case wiAboutClose:
-               mac_closewindow(window);
-               break;
              case wiAboutLicence:
                /* XXX: Do something */
                break;
@@ -194,6 +191,9 @@ static void mac_updatewindow(WindowPtr window) {
        UpdateDialog(window, window->visRgn);
        EndUpdate(window);
        break;
+      case wLicence:
+        /* Do something */
+        break;
     }
 }
 
@@ -209,10 +209,9 @@ static int mac_windowtype(WindowPtr window) {
     kind = ((WindowPeek)window)->windowKind;
     if (kind < 0)
        return wDA;
-    else if (kind == userKind)
+    if (GetWVariant(window) == zoomDocProc)
        return wTerminal;
-    else
-       return GetWRefCon(window);
+    return GetWRefCon(window);
 }
 
 /*
index a4133c3d81ad3358df7e8676951cb6bb1fc6cb0f..c4814bcafcac71f478820606ba4d95b424f3361e 100644 (file)
--- a/mac_res.r
+++ b/mac_res.r
@@ -1,9 +1,10 @@
-/* $Id: mac_res.r,v 1.1.2.2 1999/02/21 18:09:41 ben Exp $ */
+/* $Id: mac_res.r,v 1.1.2.3 1999/02/24 01:29:10 ben Exp $ */
 /* PuTTY resources */
 
 #define PICT_RezTemplateVersion 1
 
 #include "Types.r"
+#include "Palettes.r"
 
 /* Get resource IDs we share with C code */
 #include "macresid.h"
@@ -87,11 +88,11 @@ resource 'ICN#' (128, purgeable) {
        {       /* array: 2 elements */
                /* [1] */
                $"0000 3FFE 0000 4001 0000 4FF9 0000 5005"
-               $"0000 5545 0000 5005 0000 5405 0000 5005"
-               $"0000 5505 0000 5005 0000 4FF9 0000 4001"
-               $"0000 4001 7FFC 407D 8002 4001 9FF2 4001"
-               $"A00A 3FFE AA8A 2002 A00A 3FFE A80A 0000"
-               $"A00A 0000 AA0A 0000 A00A 0000 9FF2 0000"
+               $"0000 5355 0000 4505 0000 5A05 0000 2405"
+               $"0000 4A85 0001 9005 0002 23F9 0004 7C01"
+               $"0018 0201 7FA0 0C7D 801F 1001 9FE2 2001"
+               $"A00C DFFE AA89 2002 A012 3FFE A82C 0000"
+               $"A052 0000 AA6A 0000 A00A 0000 9FF2 0000"
                $"8002 0000 8002 0000 80FA 0000 8002 0000"
                $"8002 0000 7FFC 0000 4004 0000 7FFC",
                /* [2] */
@@ -105,7 +106,6 @@ resource 'ICN#' (128, purgeable) {
                $"FFFE 0000 7FFC 0000 7FFC 0000 7FFC"
        }
 };
-
 resource 'ics#' (128, purgeable) {
        {       /* array: 2 elements */
                /* [1] */
@@ -312,7 +312,7 @@ resource 'DITL' (wFatal, "fatalbox", purgeable) {
 
 /* Terminal window */
 
-resource 'WIND' (wTerminal, "terminal", purgeable) {
+resource 'WIND' (PREF_pltt_ID, "terminal", purgeable) {
     { 0, 0, 200, 200 },
     zoomDocProc,
     invisible,
@@ -322,6 +322,35 @@ resource 'WIND' (wTerminal, "terminal", purgeable) {
     staggerParentWindowScreen
 };
 
+resource 'pltt' (wTerminal, "terminal", purgeable) {
+    {
+       0x0000, 0x0000, 0x0000, pmTolerant, 0x2000,     /* black */
+       0x5555, 0x5555, 0x5555, pmTolerant, 0x2000,     /* bright black */
+       0xbbbb, 0x0000, 0x0000, pmTolerant, 0x2000,     /* red */
+       0xffff, 0x5555, 0x5555, pmTolerant, 0x2000,     /* bright red */
+       0x0000, 0xbbbb, 0x0000, pmTolerant, 0x2000,     /* green */
+       0x5555, 0xffff, 0x5555, pmTolerant, 0x2000,     /* bright green */
+       0xbbbb, 0xbbbb, 0x0000, pmTolerant, 0x2000,     /* yellow */
+       0xffff, 0xffff, 0x0000, pmTolerant, 0x2000,     /* bright yellow */
+       0x0000, 0x0000, 0xbbbb, pmTolerant, 0x2000,     /* blue */
+       0x5555, 0x5555, 0xffff, pmTolerant, 0x2000,     /* bright blue */
+       0xbbbb, 0x0000, 0xbbbb, pmTolerant, 0x2000,     /* magenta */
+       0xffff, 0x5555, 0xffff, pmTolerant, 0x2000,     /* bright magenta */
+       0x0000, 0xbbbb, 0xbbbb, pmTolerant, 0x2000,     /* cyan */
+       0x5555, 0xffff, 0xffff, pmTolerant, 0x2000,     /* bright cyan */
+       0xbbbb, 0xbbbb, 0xbbbb, pmTolerant, 0x2000,     /* white */
+       0xffff, 0xffff, 0xffff, pmTolerant, 0x2000,     /* bright white */
+       0xbbbb, 0xbbbb, 0xbbbb, pmTolerant, 0x2000,     /* default fg */
+       0xffff, 0xffff, 0xffff, pmTolerant, 0x2000,     /* default bold fg */
+       0x0000, 0x0000, 0x0000, pmTolerant, 0x2000,     /* default bg */
+       0x5555, 0x5555, 0x5555, pmTolerant, 0x2000,     /* default bold bg */
+       0x0000, 0x0000, 0x0000, pmTolerant, 0x2000,     /* cursor bg */
+       0x0000, 0x0000, 0x0000, pmTolerant, 0x2000,     /* bold cursor bg */
+       0x0000, 0xffff, 0x0000, pmTolerant, 0x2000,     /* cursor fg */
+       0x0000, 0xffff, 0x0000, pmTolerant, 0x2000,     /* bold cursor fg */
+    }
+};
+
 /* "About" box */
 
 resource 'DLOG' (wAbout, "about", purgeable) {
@@ -337,26 +366,23 @@ resource 'DLOG' (wAbout, "about", purgeable) {
 
 resource 'DITL' (wAbout, "about", purgeable) {
     {
-       { 87, 116, 107, 173 },
-       Button { enabled, "Close" },
-       { 87, 13, 107, 103 },
+       { 87, 13, 107, 173 },
        Button { enabled, "View Licence" },
        { 13, 13, 29, 173 },
        StaticText { disabled, "PuTTY"},
        { 42, 13, 74, 173 },
-       StaticText { disabled,"Experimantal Mac Port\n© 1997-9 Simon Tatham"},
+       StaticText { disabled,"Experimental Mac Port\n© 1997-9 Simon Tatham"},
     }
 };
 
 /* Licence box */
 
-resource 'DLOG' (wLicence, "licence", purgeable) {
+resource 'WIND' (wLicence, "licence", purgeable) {
     { 0, 0, 300, 300 },
     noGrowDocProc,
     visible,
     goAway,
     wLicence,
-    wLicence,
     "PuTTY Licence",
     alertPositionParentWindowScreen
 };
@@ -390,22 +416,3 @@ resource 'TEXT' (wLicence, "licence", purgeable) {
     "CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE "
     "SOFTWARE."
 };
-
-#if 0
-resource 'DITL' (wLicence, "licence", purgeable) {
-    {
-       { 13, 23, 287, 277 },
-       Picture { enabled, wLicence }
-    }
-};
-
-resource 'PICT' (wLicence, "licence", purgeable) {
-    { 0, 0, 274, 254 },
-     VersionTwo {
-       {
-           LongText { { 16, 0 }, "Copyright © 1997-9 Simon Tatham" },
-           LongText { { 32, 0 }, "Portions copyright Gary S. Brown and Eric Young" },
-       }
-    }
-};
-#endif
index fbaf3a970955697a04b7258e0ab6752b29620c2c..f1ea8db9ff29d3abc1fdc635900d31ad4647ae68 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macresid.h,v 1.1.2.2 1999/02/20 23:55:55 ben Exp $ */
+/* $Id: macresid.h,v 1.1.2.3 1999/02/24 01:29:10 ben Exp $ */
 
 /*
  * macresid.h -- Mac resource IDs
 
 /* Window types (and resource IDs) */
 #define wNone          0 /* Dummy value for no window */
-#define wDA                    1 /* DUmmy value for desk accessory */
+#define wDA            1 /* Dummy value for desk accessory */
 #define wFatal         128
 #define wAbout         129
-#define wiAboutClose           1
-#define wiAboutLicence         2
+#define wiAboutLicence         1
 #define wTerminal      130
 #define wLicence       131
+
+
+/* Preferences */
+#define PREF_pltt_ID   1024
index d88c0aadfddd25a7b500f26b155c414fdcd96976..d4400ad7130aca072d26f4bcd883e6fb6b4b66f9 100644 (file)
--- a/macterm.c
+++ b/macterm.c
@@ -6,6 +6,7 @@
 #include <Fonts.h>
 #include <Gestalt.h>
 #include <MacWindows.h>
+#include <Palettes.h>
 #include <Quickdraw.h>
 #include <QuickdrawText.h>
 #include <Sound.h>
 #include "mac.h"
 
 struct mac_session {
-    short fontnum;
-    int font_ascent;
-    WindowPtr(window);
-    RGBColor defpal[24];
-    RGBColor palette[24];
+    short              fontnum;
+    int                        font_ascent;
+    WindowPtr          window;
+    PaletteHandle      palette;
 };
 
 static void mac_initfont(struct mac_session *);
@@ -31,6 +31,16 @@ static void mac_initpalette(struct mac_session *);
 
 static struct mac_session *onlysession;
 
+static void inbuf_putc(int c) {
+    inbuf[inbuf_head] = c;
+    inbuf_head = (inbuf_head+1) & INBUF_MASK;
+}
+
+static void inbuf_putstr(const char *c) {
+    while (*c)
+       inbuf_putc(*c++);
+}
+
 void mac_newsession(void) {
     struct mac_session *s;
     int i;
@@ -55,27 +65,10 @@ void mac_newsession(void) {
     cfg.vtmode = VT_POORMAN;
     cfg.try_palette = FALSE;
     cfg.bold_colour = TRUE;
-    for (i = 0; i < 22; i++) {
-        static char defaults[22][3] = {
-            {187, 187, 187}, {255, 255, 255},
-            {0, 0, 0}, {85, 85, 85},
-            {0, 0, 0}, {0, 255, 0},
-            {0, 0, 0}, {85, 85, 85},
-            {187, 0, 0}, {255, 85, 85},
-            {0, 187, 0}, {85, 255, 85},
-            {187, 187, 0}, {255, 255, 85},
-            {0, 0, 187}, {85, 85, 255},
-            {187, 0, 187}, {255, 85, 255},
-            {0, 187, 187}, {85, 255, 255},
-            {187, 187, 187}, {255, 255, 255}
-         };
-         cfg.colours[i][0] = defaults[i][0];
-         cfg.colours[i][1] = defaults[i][1];
-         cfg.colours[i][2] = defaults[i][2];
-    }
+    cfg.colours = GetNewPalette(PREF_pltt_ID);
     onlysession = s;
        
-    /* XXX: non-Color-QuickDraw?  Own storage management? */
+    /* XXX: Own storage management? */
     if (mac_qdversion == gestaltOriginalQD)
        s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
     else
@@ -85,17 +78,22 @@ void mac_newsession(void) {
     term_size(24, 80, 100);
     mac_initfont(s);
     mac_initpalette(s);
+    /* Set to TRUE to get palette updates in the background. */
+    SetPalette(s->window, s->palette, FALSE); 
     ShowWindow(s->window);
-}
-
-static void inbuf_putc(int c) {
-    inbuf[inbuf_head] = c;
-    inbuf_head = (inbuf_head+1) & INBUF_MASK;
-}
+    inbuf_putstr("\033[1mBold\033[m    \033[2mfaint\033[m   \033[3mitalic\033[m  \033[4mu_line\033[m  "
+                 "\033[5mslow bl\033[m \033[6mfast bl\033[m \033[7minverse\033[m \033[8mconceal\033[m "
+                 "\033[9mstruck\033[m  \033[21mdbl ul\033[m\015\012");
+    term_out();
+    inbuf_putstr("\033[30mblack   \033[31mred     \033[32mgreen   \033[33myellow  "
+                 "\033[34mblue    \033[35mmagenta \033[36mcyan    \033[37mwhite\015\012");
+    term_out();
+    inbuf_putstr("\033[1m\033[30mblack   \033[31mred     \033[32mgreen   \033[33myellow  "
+                 "\033[1m\033[34mblue    \033[35mmagenta \033[36mcyan    \033[37mwhite\015\012");
+    term_out();
+    inbuf_putstr("\033[37;44mwhite on blue     \033[32;41mgreen on red\015\012");
+    term_out();
 
-static void inbuf_putstr(const char *c) {
-    while (*c)
-       inbuf_putc(*c++);
 }
 
 static void mac_initfont(struct mac_session *s) {
@@ -113,44 +111,14 @@ static void mac_initfont(struct mac_session *s) {
     font_height = fi.ascent + fi.descent + fi.leading;
     s->font_ascent = fi.ascent;
     SizeWindow(s->window, cols * font_width, rows * font_height, true);
-    inbuf_putstr("\033[1mBold\033[m    \033[2mfaint\033[m   \033[3mitalic\033[m  \033[4mu_line\033[m  "
-                 "\033[5mslow bl\033[m \033[6mfast bl\033[m \033[7minverse\033[m \033[8mconceal\033[m "
-                 "\033[9mstruck\033[m  \033[21mdbl ul\033[m\015\012");
-    term_out();
-    inbuf_putstr("\033[30mblack   \033[31mred     \033[32mgreen   \033[33myellow  "
-                 "\033[34mblue    \033[35mmagenta \033[36mcyan    \033[37mwhite\015\012");
-    term_out();
-    inbuf_putstr("\033[1m\033[30mblack   \033[31mred     \033[32mgreen   \033[33myellow  "
-                 "\033[1m\033[34mblue    \033[35mmagenta \033[36mcyan    \033[37mwhite\015\012");
-    term_out();
-    inbuf_putstr("\033[37;44mwhite on blue     \033[32;41mgreen on red\015\012");
-    term_out();
 }
 
-
-/*
- * Set up the default palette, then call palette_reset to transfer
- * it to the working palette (should the emulator do this at
- * startup?
- */
 static void mac_initpalette(struct mac_session *s) {
-    int i;
-    static const int ww[] = {
-       6, 7, 8, 9, 10, 11, 12, 13,
-       14, 15, 16, 17, 18, 19, 20, 21,
-       0, 1, 2, 3, 4, 4, 5, 5
-    };
 
-    for (i=0; i<24; i++) {
-       int w = ww[i];
-       s->defpal[i].red   = cfg.colours[w][0] * 0x0101;
-       s->defpal[i].green = cfg.colours[w][1] * 0x0101;
-       s->defpal[i].blue  = cfg.colours[w][2] * 0x0101;
-    }
-    palette_reset();
+    s->palette = NewPalette(0, NULL, 0, 0);
+    CopyPalette(cfg.colours, s->palette, 0, 0, (*cfg.colours)->pmEntries);
 }
 
-
 /*
  * Call from the terminal emulator to draw a bit of text
  *
@@ -161,30 +129,18 @@ void do_text(struct mac_session *s, int x, int y, char *text, int len,
     int style = 0;
     int bgcolour, fgcolour;
     RGBColor rgbfore, rgbback;
-    RgnHandle textregion, intersection;
     Rect textrect;
 
     SetPort(s->window);
-#if 0
+    
     /* First check this text is relevant */
-    textregion = NewRgn();
-    SetRectRgn(textregion, x * font_width, (x + len) * font_width,
-              y * font_height, (y + 1) * font_height);
-    SectRgn(textregion, s->window->visRgn, textregion);
-    if (EmptyRgn(textregion)) {
-       DisposeRgn(textregion);
-       return;
-    }
-#else
-    /* alternatively */
     textrect.top = y * font_height;
     textrect.bottom = (y + 1) * font_height;
     textrect.left = x * font_width;
     textrect.right = (x + len) * font_width;
     if (!RectInRgn(&textrect, s->window->visRgn))
        return;
-#endif
-
+       
     TextFont(s->fontnum);
     if (cfg.fontisbold || (attr & ATTR_BOLD) && !cfg.bold_colour)
        style |= bold;
@@ -202,11 +158,16 @@ void do_text(struct mac_session *s, int x, int y, char *text, int len,
     }
     if ((attr & ATTR_BOLD) && cfg.bold_colour)
        fgcolour++;
-    RGBForeColor(&s->palette[fgcolour]);
-    RGBBackColor(&s->palette[bgcolour]);
+    /* RGBForeColor(&s->palette[fgcolour]); */ /* XXX Non-Color-QD version */
+    /* RGBBackColor(&s->palette[bgcolour]); */
+    PmForeColor(fgcolour);
+    PmBackColor(bgcolour);
     SetFractEnable(FALSE); /* We want characters on pixel boundaries */
-    MoveTo(x * font_width, y * font_height + s->font_ascent);
+    MoveTo(textrect.left, textrect.top + s->font_ascent);
     DrawText(text, 0, len);
+    
+    /* Tell the window manager about it in case this isn't an update */
+    ValidRect(&textrect);
 }
 
 /*
@@ -240,10 +201,14 @@ void set_sbar(int total, int start, int page) {
 void beep(void) {
 
     SysBeep(30);
+    /*
+     * XXX We should indicate the relevant window and/or use the
+     * Notification Manager
+     */
 }
 
 /*
- * Set icon string -- a no-op here (WIndowshade?)
+ * Set icon string -- a no-op here (Windowshade?)
  */
 void set_icon(char *icon) {
 
@@ -254,9 +219,10 @@ void set_icon(char *icon) {
  */
 void set_title(char *title) {
     Str255 mactitle;
+    struct mac_session *s = onlysession;
 
     mactitle[0] = sprintf((char *)&mactitle[1], "%s", title);
-    SetWTitle(onlysession->window, mactitle);
+    SetWTitle(s->window, mactitle);
 }
 
 /*
@@ -264,28 +230,41 @@ void set_title(char *title) {
  */
 void request_resize(int w, int h) {
 
-    /* XXX: Do something */
+    cols = w;
+    rows = h;
+    mac_initfont(onlysession);
 }
 
 /*
  * Set the logical palette
  */
 void palette_set(int n, int r, int g, int b) {
-
-    /* XXX: Do something */
+    RGBColor col;
+    struct mac_session *s = onlysession;
+    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
+    };
+    
+    col.red   = r * 0x0101;
+    col.green = g * 0x0101;
+    col.blue  = b * 0x0101;
+    SetEntryColor(s->palette, first[n], &col);
+    if (first[n] >= 18)
+       SetEntryColor(s->palette, first[n]+1, &col);
+    ActivatePalette(s->window);
 }
 
 /*
  * Reset to the default palette
  */
 void palette_reset(void) {
-    int i;
     struct mac_session *s = onlysession;
 
-    for (i = 0; i < 24; i++) {
-       s->palette[i].red   = s->defpal[i].red;
-       s->palette[i].green = s->defpal[i].green;
-       s->palette[i].blue  = s->defpal[i].blue;
-    }
-    term_invalidate();
+    if (mac_qdversion == gestaltOriginalQD)
+       return;
+    CopyPalette(cfg.colours, s->palette, 0, 0, (*cfg.colours)->pmEntries);
+    ActivatePalette(s->window);
+    /* Palette Manager will generate update events as required. */
 }
diff --git a/putty.h b/putty.h
index ab8b42ef31f5cf6bbd85ff674d4fe9064760ecdc..fb300a17054a498a6853a8a6dc0614eb8015adba 100644 (file)
--- a/putty.h
+++ b/putty.h
@@ -5,6 +5,7 @@
 
 #ifdef macintosh
 #include <MacTypes.h>
+#include <Palettes.h>
 typedef UInt32 DWORD;
 struct mac_session;
 #endif /* macintosh */
@@ -147,7 +148,11 @@ typedef struct {
     /* Colour options */
     int try_palette;
     int bold_colour;
+#ifdef macintosh
+    PaletteHandle colours;
+#else /* not macintosh */
     unsigned char colours[22][3];
+#endif /* not macintosh */
     /* Selection options */
     int mouse_is_xterm;
     short wordness[256];