From 8ac1a08339a490b8f0c7614bc8b930272914a79e Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sun, 21 Feb 1999 18:09:41 +0000 Subject: [PATCH] Bloody Hell! It just managed to say "Hello, world" in a terminal window! I'd better check this lot in before something bad happens to it. [originally from svn r56] --- PuTTY.make | 8 ++- mac.c | 21 ++++++- mac_res.r | 16 ++--- macterm.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++------- putty.h | 41 +++++++------ 5 files changed, 207 insertions(+), 55 deletions(-) diff --git a/PuTTY.make b/PuTTY.make index f4b3b783..7f3d483f 100644 --- a/PuTTY.make +++ b/PuTTY.make @@ -1,4 +1,4 @@ -# $Id: PuTTY.make,v 1.1.2.5 1999/02/21 10:29:12 ben Exp $ +# $Id: PuTTY.make,v 1.1.2.6 1999/02/21 18:09:41 ben Exp $ # This is the Makefile for building PuTTY for the Mac OS. # Users of non-Mac systems will see some pretty strange characters around. @@ -12,6 +12,7 @@ COptions = {Includes} {Sym Objects¥68K = ¶ "{ObjDir¥68K}mac.c.o" ¶ + "{ObjDir¥68K}macterm.c.o" ¶ "{ObjDir¥68K}misc.c.o" ¶ # "{ObjDir¥68K}ssh.c.o" ¶ # "{ObjDir¥68K}sshcrc.c.o" ¶ @@ -43,9 +44,12 @@ PuTTY Rez mac_res.r -o {Targ} {Includes} -append -"{ObjDir¥68K}mac.c.o" Ä {¥MondoBuild¥} mac.c putty.h macresid.h +"{ObjDir¥68K}mac.c.o" Ä {¥MondoBuild¥} mac.c putty.h mac.h macresid.h {C} mac.c -o {Targ} {COptions} +"{ObjDir¥68K}macterm.c.o" Ä {¥MondoBuild¥} macterm.c mac.h putty.h + {C} macterm.c -o {Targ} {COptions} + "{ObjDir¥68K}misc.c.o" Ä {¥MondoBuild¥} misc.c putty.h {C} misc.c -o {Targ} {COptions} diff --git a/mac.c b/mac.c index 646c3610..b3d4aad8 100644 --- a/mac.c +++ b/mac.c @@ -1,4 +1,4 @@ -/* $Id: mac.c,v 1.1.2.5 1999/02/20 23:55:55 ben Exp $ */ +/* $Id: mac.c,v 1.1.2.6 1999/02/21 18:09:41 ben Exp $ */ /* * mac.c -- miscellaneous Mac-specific routines */ @@ -12,18 +12,23 @@ #include #include #include +#include #include #include #include #include /* putty.h needs size_t */ +#define PUTTY_DO_GLOBALS + #include "macresid.h" #include "putty.h" +#include "mac.h" QDGlobals qd; -int cold = 1; +static int cold = 1; +long mac_qdversion; static void mac_startup(void); static void mac_eventloop(void); @@ -64,6 +69,10 @@ static void mac_startup(void) { InitDialogs(nil); cold = 0; + /* Find out if we've got Color Quickdraw */ + if (Gestalt(gestaltQuickdrawVersion, &mac_qdversion) != noErr) + mac_qdversion = gestaltOriginalQD; + menuBar = GetNewMBar(128); if (menuBar == NULL) fatalbox("Unable to create menu bar."); @@ -172,7 +181,13 @@ static void mac_updatewindow(WindowPtr window) { switch (mac_windowtype(window)) { case wTerminal: - /* XXX: DO something */ + BeginUpdate(window); + term_paint((struct mac_session *)GetWRefCon(window), + (*window->visRgn)->rgnBBox.left, + (*window->visRgn)->rgnBBox.top, + (*window->visRgn)->rgnBBox.right, + (*window->visRgn)->rgnBBox.bottom); + EndUpdate(window); break; case wAbout: BeginUpdate(window); diff --git a/mac_res.r b/mac_res.r index 2304fe6a..a4133c3d 100644 --- a/mac_res.r +++ b/mac_res.r @@ -1,4 +1,4 @@ -/* $Id: mac_res.r,v 1.1.2.1 1999/02/21 10:29:13 ben Exp $ */ +/* $Id: mac_res.r,v 1.1.2.2 1999/02/21 18:09:41 ben Exp $ */ /* PuTTY resources */ #define PICT_RezTemplateVersion 1 @@ -45,8 +45,8 @@ resource 'SIZE' (-1) { reserved, reserved, reserved, - 65536, /* Minimum size */ - 65536, /* Preferred size */ + 1024 * 1024, /* Minimum size */ + 1024 * 1024, /* Preferred size */ }; resource 'FREF' (128, purgeable) { @@ -267,11 +267,11 @@ resource 'MENU' (mApple, preload) { resource 'MENU' (mFile, preload) { mFile, textMenuProc, - 0b11111111111111111111111111111101, + 0b11111111111111111111111111111011, enabled, "File", { - "New Session" noicon, "N", nomark, plain, + "New Session", noicon, "N", nomark, plain, "Close", noicon, "W", nomark, plain, "-", noicon, nokey, nomark, plain, "Quit", noicon, "Q", nomark, plain, @@ -313,12 +313,12 @@ resource 'DITL' (wFatal, "fatalbox", purgeable) { /* Terminal window */ resource 'WIND' (wTerminal, "terminal", purgeable) { - { 0, 0, 0, 0 }, + { 0, 0, 200, 200 }, zoomDocProc, invisible, goAway, 0x0, - "untitled" + "untitled", staggerParentWindowScreen }; @@ -344,7 +344,7 @@ resource 'DITL' (wAbout, "about", purgeable) { { 13, 13, 29, 173 }, StaticText { disabled, "PuTTY"}, { 42, 13, 74, 173 }, - StaticText { disabled, "Mac Development\n© 1997-9 Simon Tatham"}, + StaticText { disabled,"Experimantal Mac Port\n© 1997-9 Simon Tatham"}, } }; diff --git a/macterm.c b/macterm.c index 99102d83..05f0cc7a 100644 --- a/macterm.c +++ b/macterm.c @@ -2,45 +2,175 @@ * macterm.c -- Macintosh terminal front-end */ +#include +#include +#include #include +#include +#include #include #include "macresid.h" #include "putty.h" +#include "mac.h" struct mac_session { - short fnum; - int fsize; -} + short fontnum; + int font_ascent; + WindowPtr(window); +}; + +static void mac_initfont(struct mac_session *); + +/* Temporary hack till I get the terminal emulator supporting multiple sessions */ + +static struct mac_session *onlysession; void mac_newsession(void) { - WindowPtr window; struct mac_session *s; - + /* This should obviously be initialised by other means */ s = smalloc(sizeof(*s)); - s->fnum = GetFNum("\pMonaco"); - s->fsize = 9; - rows = 24; - cols = 80; + strcpy(cfg.font, "Monaco"); + cfg.fontisbold = 0; + cfg.fontheight = 9; + onlysession = s; /* XXX: non-Color-QuickDraw? Own storage management? */ - window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1); - SetPort(window); - mac_initfont(s); + if (mac_qdversion == gestaltOriginalQD) + s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1); + else + s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1); + SetWRefCon(s->window, (long)s); term_init(); - term_size(rows, cols); + term_size(24, 80, 100); + mac_initfont(s); + ShowWindow(s->window); } -void mac_initfont(struct mac_session *s) { - FMetricRec metrics; - - TextFont(s->fnum); - TextFace(0); - TextSize(s->fsize); - FontMetrics(&metrics); - font_width = metrics.widMax; - font_height = metrics.ascent + metrics.descent + metrics.leading; - SizeWindow(window, cols * font_width, rows * font_height, TRUE); +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++); +} + +static void mac_initfont(struct mac_session *s) { + Str255 macfont; + FontInfo fi; + + SetPort(s->window); + macfont[0] = sprintf((char *)&macfont[1], "%s", cfg.font); + GetFNum(macfont, &s->fontnum); + TextFont(s->fontnum); + TextFace(cfg.fontisbold ? bold : 0); + TextSize(cfg.fontheight); + GetFontInfo(&fi); + font_width = fi.widMax; + 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("Hello,\007 world\007"); + term_out(); +} + +/* + * Call from the terminal emulator to draw a bit of text + * + * x and y are text row and column (zero-based) + */ +void do_text(struct mac_session *s, int x, int y, char *text, int len, + unsigned long attr) { + int style = 0; + + SetPort(s->window); + TextFont(s->fontnum); + if (cfg.fontisbold || (attr & ATTR_BOLD) && !cfg.bold_colour) + style |= bold; + if (attr & ATTR_UNDER) + style |= underline; + TextFace(style); + TextSize(cfg.fontheight); + TextMode(srcCopy); + SetFractEnable(FALSE); /* We want characters on pixel boundaries */ + MoveTo(x * font_width, y * font_height + s->font_ascent); + DrawText(text, 0, len); +} + +/* + * Call from the terminal emulator to get its graphics context. + * I feel this should disappear entirely (and do_text should take + * a Session as an argument. Simon may disagree. + */ +struct mac_session *get_ctx(void) { + + return onlysession; +} + +/* + * Presumably this does something in Windows + */ +void free_ctx(struct mac_session *ctx) { + +} + +/* + * Set the scroll bar position + */ +void set_sbar(int total, int start, int page) { + + /* Do something once we actually have a scroll bar */ +} + +/* + * Beep + */ +void beep(void) { + + SysBeep(30); +} + +/* + * Set icon string -- a no-op here (WIndowshade?) + */ +void set_icon(char *icon) { + +} + +/* + * Set the window title + */ +void set_title(char *title) { + Str255 mactitle; + + mactitle[0] = sprintf((char *)&mactitle[1], "%s", title); + SetWTitle(onlysession->window, mactitle); +} + +/* + * Resize the window at the emulator's request + */ +void request_resize(int w, int h) { + + /* XXX: Do something */ +} + +/* + * Set the logical palette + */ +void palette_set(int n, int r, int g, int b) { + + /* XXX: Do something */ +} + +/* + * Reset to the default palette + */ +void palette_reset(void) { + + /* XXX: Do something */ } diff --git a/putty.h b/putty.h index 581225b3..ab8b42ef 100644 --- a/putty.h +++ b/putty.h @@ -6,6 +6,7 @@ #ifdef macintosh #include typedef UInt32 DWORD; +struct mac_session; #endif /* macintosh */ #ifndef TRUE @@ -41,7 +42,8 @@ typedef UInt32 DWORD; #define CHAR_MASK 0x000000FFUL #ifdef macintosh -typedef void *Context; /* Temporarily until I work out what it should really be */ +struct mac_session; +typedef struct mac_session *Context; #else /* not macintosh */ typedef HDC Context; #endif /* not macintosh */ @@ -59,24 +61,6 @@ typedef HDC Context; #define GLOBAL extern #endif -struct session { - /* Display state */ - int rows, cols, savelines; - int font_width, font_height; - int has_focus; - /* Buffers */ - unsigned char inbuf[INBUF_SIZE]; - int inbuf_head, inbuf_reap; - unsigned char outbuf[OUTBUF_SIZE]; - int outbuf_head, outbuf_reap; - /* Emulator state */ - int app_cursor_keys, app_keypad_keys; - /* Backend */ - Backend *back; - /* Config that created this session */ - Config cfg; -} - GLOBAL int rows, cols, savelines; GLOBAL int font_width, font_height; @@ -171,6 +155,25 @@ typedef struct { GLOBAL Config cfg; +typedef struct { + /* Display state */ + int rows, cols, savelines; + int font_width, font_height; + int has_focus; + /* Buffers */ + unsigned char inbuf[INBUF_SIZE]; + int inbuf_head, inbuf_reap; + unsigned char outbuf[OUTBUF_SIZE]; + int outbuf_head, outbuf_reap; + /* Emulator state */ + int app_cursor_keys, app_keypad_keys; + /* Backend */ + Backend *back; + /* Config that created this session */ + Config cfg; +} Session; + + /* * Exports from window.c. */