2 * macterm.c -- Macintosh terminal front-end
8 #include <MacWindows.h>
9 #include <QuickdrawText.h>
24 static void mac_initfont(struct mac_session *);
26 /* Temporary hack till I get the terminal emulator supporting multiple sessions */
28 static struct mac_session *onlysession;
30 void mac_newsession(void) {
31 struct mac_session *s;
33 /* This should obviously be initialised by other means */
34 s = smalloc(sizeof(*s));
35 strcpy(cfg.font, "Monaco");
40 /* XXX: non-Color-QuickDraw? Own storage management? */
41 if (mac_qdversion == gestaltOriginalQD)
42 s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
44 s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1);
45 SetWRefCon(s->window, (long)s);
47 term_size(24, 80, 100);
49 ShowWindow(s->window);
52 static void inbuf_putc(int c) {
53 inbuf[inbuf_head] = c;
54 inbuf_head = (inbuf_head+1) & INBUF_MASK;
57 static void inbuf_putstr(const char *c) {
62 static void mac_initfont(struct mac_session *s) {
67 macfont[0] = sprintf((char *)&macfont[1], "%s", cfg.font);
68 GetFNum(macfont, &s->fontnum);
70 TextFace(cfg.fontisbold ? bold : 0);
71 TextSize(cfg.fontheight);
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");
82 * Call from the terminal emulator to draw a bit of text
84 * x and y are text row and column (zero-based)
86 void do_text(struct mac_session *s, int x, int y, char *text, int len,
92 if (cfg.fontisbold || (attr & ATTR_BOLD) && !cfg.bold_colour)
94 if (attr & ATTR_UNDER)
97 TextSize(cfg.fontheight);
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);
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.
109 struct mac_session *get_ctx(void) {
115 * Presumably this does something in Windows
117 void free_ctx(struct mac_session *ctx) {
122 * Set the scroll bar position
124 void set_sbar(int total, int start, int page) {
126 /* Do something once we actually have a scroll bar */
138 * Set icon string -- a no-op here (WIndowshade?)
140 void set_icon(char *icon) {
145 * Set the window title
147 void set_title(char *title) {
150 mactitle[0] = sprintf((char *)&mactitle[1], "%s", title);
151 SetWTitle(onlysession->window, mactitle);
155 * Resize the window at the emulator's request
157 void request_resize(int w, int h) {
159 /* XXX: Do something */
163 * Set the logical palette
165 void palette_set(int n, int r, int g, int b) {
167 /* XXX: Do something */
171 * Reset to the default palette
173 void palette_reset(void) {
175 /* XXX: Do something */