]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - macterm.c
Bloody Hell! It just managed to say "Hello, world" in a terminal window!
[PuTTY.git] / macterm.c
1 /*
2  * macterm.c -- Macintosh terminal front-end
3  */
4
5 #include <MacTypes.h>
6 #include <Fonts.h>
7 #include <Gestalt.h>
8 #include <MacWindows.h>
9 #include <QuickdrawText.h>
10 #include <Sound.h>
11
12 #include <stdlib.h>
13
14 #include "macresid.h"
15 #include "putty.h"
16 #include "mac.h"
17
18 struct mac_session {
19     short fontnum;
20     int font_ascent;
21     WindowPtr(window);
22 };
23
24 static void mac_initfont(struct mac_session *);
25
26 /* Temporary hack till I get the terminal emulator supporting multiple sessions */
27
28 static struct mac_session *onlysession;
29
30 void mac_newsession(void) {
31     struct mac_session *s;
32
33     /* This should obviously be initialised by other means */
34     s = smalloc(sizeof(*s));
35     strcpy(cfg.font, "Monaco");
36     cfg.fontisbold = 0;
37     cfg.fontheight = 9;
38     onlysession = s;
39         
40     /* XXX: non-Color-QuickDraw?  Own storage management? */
41     if (mac_qdversion == gestaltOriginalQD)
42         s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
43     else
44         s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1);
45     SetWRefCon(s->window, (long)s);
46     term_init();
47     term_size(24, 80, 100);
48     mac_initfont(s);
49     ShowWindow(s->window);
50 }
51
52 static void inbuf_putc(int c) {
53     inbuf[inbuf_head] = c;
54     inbuf_head = (inbuf_head+1) & INBUF_MASK;
55 }
56
57 static void inbuf_putstr(const char *c) {
58     while (*c)
59         inbuf_putc(*c++);
60 }
61
62 static void mac_initfont(struct mac_session *s) {
63     Str255 macfont;
64     FontInfo fi;
65  
66     SetPort(s->window);
67     macfont[0] = sprintf((char *)&macfont[1], "%s", cfg.font);
68     GetFNum(macfont, &s->fontnum);
69     TextFont(s->fontnum);
70     TextFace(cfg.fontisbold ? bold : 0);
71     TextSize(cfg.fontheight);
72     GetFontInfo(&fi);
73     font_width = fi.widMax;
74     font_height = fi.ascent + fi.descent + fi.leading;
75     s->font_ascent = fi.ascent;
76     SizeWindow(s->window, cols * font_width, rows * font_height, true);
77     inbuf_putstr("Hello,\007 world\007");
78     term_out();
79 }
80
81 /*
82  * Call from the terminal emulator to draw a bit of text
83  *
84  * x and y are text row and column (zero-based)
85  */
86 void do_text(struct mac_session *s, int x, int y, char *text, int len,
87              unsigned long attr) {
88     int style = 0;
89
90     SetPort(s->window);
91     TextFont(s->fontnum);
92     if (cfg.fontisbold || (attr & ATTR_BOLD) && !cfg.bold_colour)
93         style |= bold;
94     if (attr & ATTR_UNDER)
95         style |= underline;
96     TextFace(style);
97     TextSize(cfg.fontheight);
98     TextMode(srcCopy);
99     SetFractEnable(FALSE); /* We want characters on pixel boundaries */
100     MoveTo(x * font_width, y * font_height + s->font_ascent);
101     DrawText(text, 0, len);
102 }
103
104 /*
105  * Call from the terminal emulator to get its graphics context.
106  * I feel this should disappear entirely (and do_text should take
107  * a Session as an argument.  Simon may disagree.
108  */
109 struct mac_session *get_ctx(void) {
110
111     return onlysession;
112 }
113
114 /*
115  * Presumably this does something in Windows
116  */
117 void free_ctx(struct mac_session *ctx) {
118
119 }
120
121 /*
122  * Set the scroll bar position
123  */
124 void set_sbar(int total, int start, int page) {
125
126     /* Do something once we actually have a scroll bar */
127 }
128
129 /*
130  * Beep
131  */
132 void beep(void) {
133
134     SysBeep(30);
135 }
136
137 /*
138  * Set icon string -- a no-op here (WIndowshade?)
139  */
140 void set_icon(char *icon) {
141
142 }
143
144 /*
145  * Set the window title
146  */
147 void set_title(char *title) {
148     Str255 mactitle;
149
150     mactitle[0] = sprintf((char *)&mactitle[1], "%s", title);
151     SetWTitle(onlysession->window, mactitle);
152 }
153
154 /*
155  * Resize the window at the emulator's request
156  */
157 void request_resize(int w, int h) {
158
159     /* XXX: Do something */
160 }
161
162 /*
163  * Set the logical palette
164  */
165 void palette_set(int n, int r, int g, int b) {
166
167     /* XXX: Do something */
168 }
169
170 /*
171  * Reset to the default palette
172  */
173 void palette_reset(void) {
174
175     /* XXX: Do something */
176 }