2 * macterm.c -- Macintosh terminal front-end
8 #include <MacWindows.h>
10 #include <QuickdrawText.h>
27 static void mac_initfont(struct mac_session *);
28 static void mac_initpalette(struct mac_session *);
30 /* Temporary hack till I get the terminal emulator supporting multiple sessions */
32 static struct mac_session *onlysession;
34 void mac_newsession(void) {
35 struct mac_session *s;
38 /* This should obviously be initialised by other means */
39 s = smalloc(sizeof(*s));
40 cfg.bksp_is_delete = TRUE;
41 cfg.rxvt_homeend = FALSE;
42 cfg.linux_funkeys = FALSE;
43 cfg.app_cursor = FALSE;
44 cfg.app_keypad = FALSE;
49 cfg.win_name_always = FALSE;
52 strcpy(cfg.font, "Monaco");
55 cfg.vtmode = VT_POORMAN;
56 cfg.try_palette = FALSE;
57 cfg.bold_colour = TRUE;
58 for (i = 0; i < 22; i++) {
59 static char defaults[22][3] = {
60 {187, 187, 187}, {255, 255, 255},
61 {0, 0, 0}, {85, 85, 85},
62 {0, 0, 0}, {0, 255, 0},
63 {0, 0, 0}, {85, 85, 85},
64 {187, 0, 0}, {255, 85, 85},
65 {0, 187, 0}, {85, 255, 85},
66 {187, 187, 0}, {255, 255, 85},
67 {0, 0, 187}, {85, 85, 255},
68 {187, 0, 187}, {255, 85, 255},
69 {0, 187, 187}, {85, 255, 255},
70 {187, 187, 187}, {255, 255, 255}
72 cfg.colours[i][0] = defaults[i][0];
73 cfg.colours[i][1] = defaults[i][1];
74 cfg.colours[i][2] = defaults[i][2];
78 /* XXX: non-Color-QuickDraw? Own storage management? */
79 if (mac_qdversion == gestaltOriginalQD)
80 s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
82 s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1);
83 SetWRefCon(s->window, (long)s);
85 term_size(24, 80, 100);
88 ShowWindow(s->window);
91 static void inbuf_putc(int c) {
92 inbuf[inbuf_head] = c;
93 inbuf_head = (inbuf_head+1) & INBUF_MASK;
96 static void inbuf_putstr(const char *c) {
101 static void mac_initfont(struct mac_session *s) {
106 macfont[0] = sprintf((char *)&macfont[1], "%s", cfg.font);
107 GetFNum(macfont, &s->fontnum);
108 TextFont(s->fontnum);
109 TextFace(cfg.fontisbold ? bold : 0);
110 TextSize(cfg.fontheight);
112 font_width = fi.widMax;
113 font_height = fi.ascent + fi.descent + fi.leading;
114 s->font_ascent = fi.ascent;
115 SizeWindow(s->window, cols * font_width, rows * font_height, true);
116 inbuf_putstr("\033[1mBold\033[m \033[2mfaint\033[m \033[3mitalic\033[m \033[4mu_line\033[m "
117 "\033[5mslow bl\033[m \033[6mfast bl\033[m \033[7minverse\033[m \033[8mconceal\033[m "
118 "\033[9mstruck\033[m \033[21mdbl ul\033[m\015\012");
120 inbuf_putstr("\033[30mblack \033[31mred \033[32mgreen \033[33myellow "
121 "\033[34mblue \033[35mmagenta \033[36mcyan \033[37mwhite\015\012");
123 inbuf_putstr("\033[1m\033[30mblack \033[31mred \033[32mgreen \033[33myellow "
124 "\033[1m\033[34mblue \033[35mmagenta \033[36mcyan \033[37mwhite\015\012");
126 inbuf_putstr("\033[37;44mwhite on blue \033[32;41mgreen on red\015\012");
132 * Set up the default palette, then call palette_reset to transfer
133 * it to the working palette (should the emulator do this at
136 static void mac_initpalette(struct mac_session *s) {
138 static const int ww[] = {
139 6, 7, 8, 9, 10, 11, 12, 13,
140 14, 15, 16, 17, 18, 19, 20, 21,
141 0, 1, 2, 3, 4, 4, 5, 5
144 for (i=0; i<24; i++) {
146 s->defpal[i].red = cfg.colours[w][0] * 0x0101;
147 s->defpal[i].green = cfg.colours[w][1] * 0x0101;
148 s->defpal[i].blue = cfg.colours[w][2] * 0x0101;
155 * Call from the terminal emulator to draw a bit of text
157 * x and y are text row and column (zero-based)
159 void do_text(struct mac_session *s, int x, int y, char *text, int len,
160 unsigned long attr) {
162 int bgcolour, fgcolour;
163 RGBColor rgbfore, rgbback;
164 RgnHandle textregion, intersection;
169 /* First check this text is relevant */
170 textregion = NewRgn();
171 SetRectRgn(textregion, x * font_width, (x + len) * font_width,
172 y * font_height, (y + 1) * font_height);
173 SectRgn(textregion, s->window->visRgn, textregion);
174 if (EmptyRgn(textregion)) {
175 DisposeRgn(textregion);
180 textrect.top = y * font_height;
181 textrect.bottom = (y + 1) * font_height;
182 textrect.left = x * font_width;
183 textrect.right = (x + len) * font_width;
184 if (!RectInRgn(&textrect, s->window->visRgn))
188 TextFont(s->fontnum);
189 if (cfg.fontisbold || (attr & ATTR_BOLD) && !cfg.bold_colour)
191 if (attr & ATTR_UNDER)
194 TextSize(cfg.fontheight);
196 if (attr & ATTR_REVERSE) {
197 bgcolour = ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT) * 2;
198 fgcolour = ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT) * 2;
200 fgcolour = ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT) * 2;
201 bgcolour = ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT) * 2;
203 if ((attr & ATTR_BOLD) && cfg.bold_colour)
205 RGBForeColor(&s->palette[fgcolour]);
206 RGBBackColor(&s->palette[bgcolour]);
207 SetFractEnable(FALSE); /* We want characters on pixel boundaries */
208 MoveTo(x * font_width, y * font_height + s->font_ascent);
209 DrawText(text, 0, len);
213 * Call from the terminal emulator to get its graphics context.
214 * I feel this should disappear entirely (and do_text should take
215 * a Session as an argument). Simon may disagree.
217 struct mac_session *get_ctx(void) {
223 * Presumably this does something in Windows
225 void free_ctx(struct mac_session *ctx) {
230 * Set the scroll bar position
232 void set_sbar(int total, int start, int page) {
234 /* Do something once we actually have a scroll bar */
246 * Set icon string -- a no-op here (WIndowshade?)
248 void set_icon(char *icon) {
253 * Set the window title
255 void set_title(char *title) {
258 mactitle[0] = sprintf((char *)&mactitle[1], "%s", title);
259 SetWTitle(onlysession->window, mactitle);
263 * Resize the window at the emulator's request
265 void request_resize(int w, int h) {
267 /* XXX: Do something */
271 * Set the logical palette
273 void palette_set(int n, int r, int g, int b) {
275 /* XXX: Do something */
279 * Reset to the default palette
281 void palette_reset(void) {
283 struct mac_session *s = onlysession;
285 for (i = 0; i < 24; i++) {
286 s->palette[i].red = s->defpal[i].red;
287 s->palette[i].green = s->defpal[i].green;
288 s->palette[i].blue = s->defpal[i].blue;