New timing infrastructure. There's a new function schedule_timer()
[u/mdw/putty] / mac / macterm.c
CommitLineData
39934deb 1/* $Id$ */
d082ac49 2/*
3 * Copyright (c) 1999 Simon Tatham
4 * Copyright (c) 1999, 2002 Ben Harris
5 * All rights reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following
14 * conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
29/*
30 * macterm.c -- Macintosh terminal front-end
31 */
32
33#include <MacTypes.h>
34#include <Controls.h>
35#include <ControlDefinitions.h>
2b8dca9e 36#include <FixMath.h>
d082ac49 37#include <Fonts.h>
38#include <Gestalt.h>
64b8ebc6 39#include <LowMem.h>
d082ac49 40#include <MacMemory.h>
41#include <MacWindows.h>
42#include <MixedMode.h>
43#include <Palettes.h>
44#include <Quickdraw.h>
45#include <QuickdrawText.h>
46#include <Resources.h>
47#include <Scrap.h>
48#include <Script.h>
49#include <Sound.h>
8768ce31 50#include <TextCommon.h>
d082ac49 51#include <ToolUtils.h>
8768ce31 52#include <UnicodeConverter.h>
d082ac49 53
54#include <assert.h>
55#include <limits.h>
56#include <stdlib.h>
57#include <stdio.h>
58#include <string.h>
59
60#include "macresid.h"
61#include "putty.h"
801e70ea 62#include "charset.h"
d082ac49 63#include "mac.h"
64#include "terminal.h"
65
66#define NCOLOURS (lenof(((Config *)0)->colours))
67
68#define DEFAULT_FG 16
69#define DEFAULT_FG_BOLD 17
70#define DEFAULT_BG 18
71#define DEFAULT_BG_BOLD 19
72#define CURSOR_FG 20
e0cbe032 73#define CURSOR_BG 21
d082ac49 74
75#define PTOCC(x) ((x) < 0 ? -(-(x - s->font_width - 1) / s->font_width) : \
76 (x) / s->font_width)
77#define PTOCR(y) ((y) < 0 ? -(-(y - s->font_height - 1) / s->font_height) : \
78 (y) / s->font_height)
79
80static void mac_initfont(Session *);
8768ce31 81static pascal OSStatus uni_to_font_fallback(UniChar *, ByteCount, ByteCount *,
82 TextPtr, ByteCount, ByteCount *,
1d4d52ce 83 LogicalAddress,
8768ce31 84 ConstUnicodeMappingPtr);
d082ac49 85static void mac_initpalette(Session *);
86static void mac_adjustwinbg(Session *);
87static void mac_adjustsize(Session *, int, int);
88static void mac_drawgrowicon(Session *s);
64b8ebc6 89static pascal void mac_growtermdraghook(void);
d082ac49 90static pascal void mac_scrolltracker(ControlHandle, short);
91static pascal void do_text_for_device(short, short, GDHandle, long);
d082ac49 92static void text_click(Session *, EventRecord *);
f854b482 93static void mac_activateterm(WindowPtr, EventRecord *);
94static void mac_adjusttermcursor(WindowPtr, Point, RgnHandle);
95static void mac_adjusttermmenus(WindowPtr);
96static void mac_updateterm(WindowPtr);
97static void mac_clickterm(WindowPtr, EventRecord *);
98static void mac_growterm(WindowPtr, EventRecord *);
99static void mac_keyterm(WindowPtr, EventRecord *);
100static void mac_menuterm(WindowPtr, short, short);
101static void mac_closeterm(WindowPtr);
d082ac49 102
103void pre_paint(Session *s);
104void post_paint(Session *s);
105
ce283213 106void mac_startsession(Session *s)
107{
cbe2d68f 108 const char *errmsg;
5211281f 109 int i;
347bfcd7 110 WinInfo *wi;
ce283213 111
c31f6c61 112 init_ucs(s);
5211281f 113
114 /*
115 * Select protocol. This is farmed out into a table in a
116 * separate file to enable an ssh-free variant.
117 */
118 s->back = NULL;
119 for (i = 0; backends[i].backend != NULL; i++)
120 if (backends[i].protocol == s->cfg.protocol) {
121 s->back = backends[i].backend;
122 break;
123 }
124 if (s->back == NULL)
125 fatalbox("Unsupported protocol number found");
126
d082ac49 127 /* XXX: Own storage management? */
128 if (HAVE_COLOR_QD())
129 s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1);
130 else
131 s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
34773273 132 wi = snew(WinInfo);
f854b482 133 memset(wi, 0, sizeof(*wi));
347bfcd7 134 wi->s = s;
135 wi->wtype = wTerminal;
f854b482 136 wi->activate = &mac_activateterm;
137 wi->adjustcursor = &mac_adjusttermcursor;
138 wi->adjustmenus = &mac_adjusttermmenus;
139 wi->update = &mac_updateterm;
140 wi->click = &mac_clickterm;
141 wi->grow = &mac_growterm;
142 wi->key = &mac_keyterm;
143 wi->menu = &mac_menuterm;
144 wi->close = &mac_closeterm;
347bfcd7 145 SetWRefCon(s->window, (long)wi);
d082ac49 146 s->scrollbar = GetNewControl(cVScroll, s->window);
c31f6c61 147 s->term = term_init(&s->cfg, &s->ucsdata, s);
d082ac49 148
2beb0fb0 149 mac_initfont(s);
150 mac_initpalette(s);
151 if (HAVE_COLOR_QD()) {
152 /* Set to FALSE to not get palette updates in the background. */
153 SetPalette(s->window, s->palette, TRUE);
154 ActivatePalette(s->window);
155 }
156
7dcd1f87 157 s->logctx = log_init(s->term, &s->cfg);
d082ac49 158 term_provide_logctx(s->term, s->logctx);
159
1e5bde54 160 errmsg = s->back->init(s, &s->backhandle, &s->cfg, s->cfg.host,
79bf227b 161 s->cfg.port, &s->realhost, s->cfg.tcp_nodelay,
162 s->cfg.tcp_keepalives);
5eec331c 163 if (errmsg != NULL)
164 fatalbox("%s", errmsg);
d082ac49 165 s->back->provide_logctx(s->backhandle, s->logctx);
d9fffe93 166 set_title(s, s->realhost);
d082ac49 167
168 term_provide_resize_fn(s->term, s->back->size, s->backhandle);
169
170 mac_adjustsize(s, s->cfg.height, s->cfg.width);
171 term_size(s->term, s->cfg.height, s->cfg.width, s->cfg.savelines);
172
fe5634f6 173 s->ldisc = ldisc_create(&s->cfg, s->term, s->back, s->backhandle, s);
d082ac49 174 ldisc_send(s->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */
175
d082ac49 176 ShowWindow(s->window);
0c4b7799 177 s->next = sesslist;
fabd1805 178 s->prev = &sesslist;
9546c9c6 179 if (s->next != NULL)
b89053c0 180 s->next->prev = &s->next;
0c4b7799 181 sesslist = s;
d082ac49 182}
183
c3aef739 184/*
185 * Try to work out a horizontal scaling factor for the current font
186 * that will give a chracter width of wantwidth. Return it in numer
187 * and denom (suitable for passing to StdText()).
188 */
189static void mac_workoutfontscale(Session *s, int wantwidth,
190 Point *numerp, Point *denomp)
191{
192 Point numer, denom, tmpnumer, tmpdenom;
193 int gotwidth, i;
194 const char text = 'W';
195 FontInfo fi;
1d4d52ce 196#if TARGET_API_MAC_CARBON
bb8dd32f 197 CQDProcsPtr gp = GetPortGrafProcs(GetWindowPort(s->window));
1d4d52ce 198#else
bb8dd32f 199 QDProcsPtr gp = s->window->grafProcs;
1d4d52ce 200#endif
c3aef739 201
c3aef739 202 numer.v = denom.v = 1; /* always */
203 numer.h = denom.h = 1;
204 for (i = 0; i < 3; i++) {
c3aef739 205 tmpnumer = numer;
206 tmpdenom = denom;
1d4d52ce 207 if (gp != NULL)
c3aef739 208 gotwidth = InvokeQDTxMeasUPP(1, &text, &tmpnumer, &tmpdenom, &fi,
1d4d52ce 209 gp->txMeasProc);
c3aef739 210 else
211 gotwidth = StdTxMeas(1, &text, &tmpnumer, &tmpdenom, &fi);
212 /* The result of StdTxMeas must be scaled by the factors it returns. */
213 gotwidth = FixRound(FixMul(gotwidth << 16,
214 FixRatio(tmpnumer.h, tmpdenom.h)));
c3aef739 215 if (gotwidth == wantwidth)
216 break;
217 numer.h *= wantwidth;
218 denom.h *= gotwidth;
219 }
220 *numerp = numer;
221 *denomp = denom;
222}
223
8768ce31 224static UnicodeToTextFallbackUPP uni_to_font_fallback_upp;
225
f854b482 226static void mac_initfont(Session *s)
227{
d082ac49 228 FontInfo fi;
8768ce31 229 TextEncoding enc;
379836ca 230 OptionBits fbflags;
8768ce31 231
5a736db6 232 SetPort((GrafPtr)GetWindowPort(s->window));
e3c5b245 233 GetFNum(s->cfg.font.name, &s->fontnum);
d082ac49 234 TextFont(s->fontnum);
e3c5b245 235 TextFace(s->cfg.font.face);
236 TextSize(s->cfg.font.size);
d082ac49 237 GetFontInfo(&fi);
238 s->font_width = CharWidth('W'); /* Well, it's what NCSA uses. */
239 s->font_ascent = fi.ascent;
240 s->font_leading = fi.leading;
241 s->font_height = s->font_ascent + fi.descent + s->font_leading;
c3aef739 242 mac_workoutfontscale(s, s->font_width,
243 &s->font_stdnumer, &s->font_stddenom);
244 mac_workoutfontscale(s, s->font_width * 2,
245 &s->font_widenumer, &s->font_widedenom);
e3c5b245 246 TextSize(s->cfg.font.size * 2);
c3aef739 247 mac_workoutfontscale(s, s->font_width * 2,
248 &s->font_bignumer, &s->font_bigdenom);
e3c5b245 249 TextSize(s->cfg.font.size);
d082ac49 250 if (!s->cfg.bold_colour) {
251 TextFace(bold);
252 s->font_boldadjust = s->font_width - CharWidth('W');
253 } else
254 s->font_boldadjust = 0;
8768ce31 255
256 if (s->uni_to_font != NULL)
257 DisposeUnicodeToTextInfo(&s->uni_to_font);
8ef2b196 258 if (mac_gestalts.encvvers != 0 &&
8768ce31 259 UpgradeScriptInfoToTextEncoding(kTextScriptDontCare,
260 kTextLanguageDontCare,
e3c5b245 261 kTextRegionDontCare, s->cfg.font.name,
8ef2b196 262 &enc) == noErr &&
263 CreateUnicodeToTextInfoByEncoding(enc, &s->uni_to_font) == noErr) {
8768ce31 264 if (uni_to_font_fallback_upp == NULL)
265 uni_to_font_fallback_upp =
1d4d52ce 266 NewUnicodeToTextFallbackUPP(&uni_to_font_fallback);
379836ca 267 fbflags = kUnicodeFallbackCustomOnly;
268 if (mac_gestalts.uncvattr & kTECAddFallbackInterruptMask)
269 fbflags |= kUnicodeFallbackInterruptSafeMask;
8768ce31 270 if (SetFallbackUnicodeToText(s->uni_to_font,
379836ca 271 uni_to_font_fallback_upp, fbflags, NULL) != noErr) {
8768ce31 272 DisposeUnicodeToTextInfo(&s->uni_to_font);
379836ca 273 goto no_encv;
8768ce31 274 }
8ef2b196 275 } else {
e3c5b245 276 char cfontname[256];
277
379836ca 278 no_encv:
8ef2b196 279 s->uni_to_font = NULL;
e3c5b245 280 p2cstrcpy(cfontname, s->cfg.font.name);
8ef2b196 281 s->font_charset =
282 charset_from_macenc(FontToScript(s->fontnum),
283 GetScriptManagerVariable(smRegionCode),
e3c5b245 284 mac_gestalts.sysvers, cfontname);
8768ce31 285 }
286
d082ac49 287 mac_adjustsize(s, s->term->rows, s->term->cols);
288}
289
8768ce31 290static pascal OSStatus uni_to_font_fallback(UniChar *ucp,
291 ByteCount ilen, ByteCount *iusedp, TextPtr obuf, ByteCount olen,
1d4d52ce 292 ByteCount *ousedp, LogicalAddress cookie, ConstUnicodeMappingPtr mapping)
8768ce31 293{
294
295 if (olen < 1)
296 return kTECOutputBufferFullStatus;
d1c57171 297 /*
298 * What I'd _like_ to do here is to somehow generate the
299 * missing-character glyph that every font is required to have.
300 * Unfortunately (and somewhat surprisingly), I can't find any way
301 * to actually ask for it explicitly. Bah.
302 */
303 *obuf = '.';
8768ce31 304 *iusedp = ilen;
305 *ousedp = 1;
306 return noErr;
307}
308
0c4b7799 309/*
310 * Called every time round the event loop.
311 */
312void mac_pollterm(void)
313{
314 Session *s;
315
316 for (s = sesslist; s != NULL; s = s->next) {
0c4b7799 317 term_update(s->term);
318 }
319}
8768ce31 320
d082ac49 321/*
322 * To be called whenever the window size changes.
323 * rows and cols should be desired values.
324 * It's assumed the terminal emulator will be informed, and will set rows
325 * and cols for us.
326 */
327static void mac_adjustsize(Session *s, int newrows, int newcols) {
328 int winwidth, winheight;
329
330 winwidth = newcols * s->font_width + 15;
331 winheight = newrows * s->font_height;
332 SizeWindow(s->window, winwidth, winheight, true);
333 HideControl(s->scrollbar);
334 MoveControl(s->scrollbar, winwidth - 15, -1);
335 SizeControl(s->scrollbar, 16, winheight - 13);
336 ShowControl(s->scrollbar);
0c367171 337 mac_drawgrowicon(s);
d082ac49 338}
339
f854b482 340static void mac_initpalette(Session *s)
341{
d082ac49 342
1eb3f8f0 343 if (!HAVE_COLOR_QD())
344 return;
d082ac49 345 /*
346 * Most colours should be inhibited on 2bpp displays.
347 * Palette manager documentation suggests inhibiting all tolerant colours
348 * on greyscale displays.
349 */
8a00b869 350#define PM_NORMAL ( pmTolerant | pmInhibitC2 | \
351 pmInhibitG2 | pmInhibitG4 | pmInhibitG8 )
d082ac49 352#define PM_TOLERANCE 0x2000
353 s->palette = NewPalette(22, NULL, PM_NORMAL, PM_TOLERANCE);
354 if (s->palette == NULL)
355 fatalbox("Unable to create palette");
356 /* In 2bpp, these are the colours we want most. */
357 SetEntryUsage(s->palette, DEFAULT_BG,
358 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
359 SetEntryUsage(s->palette, DEFAULT_FG,
360 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
361 SetEntryUsage(s->palette, DEFAULT_FG_BOLD,
362 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
8a00b869 363 SetEntryUsage(s->palette, CURSOR_BG,
d082ac49 364 PM_NORMAL &~ pmInhibitC2, PM_TOLERANCE);
365 palette_reset(s);
366}
367
368/*
369 * Set the background colour of the window correctly. Should be
370 * called whenever the default background changes.
371 */
f854b482 372static void mac_adjustwinbg(Session *s)
373{
d082ac49 374
375 if (!HAVE_COLOR_QD())
376 return;
1fc898ea 377#if !TARGET_CPU_68K
d082ac49 378 if (mac_gestalts.windattr & gestaltWindowMgrPresent)
379 SetWindowContentColor(s->window,
380 &(*s->palette)->pmInfo[DEFAULT_BG].ciRGB);
381 else
382#endif
383 {
1d4d52ce 384#if !TARGET_API_MAC_CARBON
d082ac49 385 if (s->wctab == NULL)
386 s->wctab = (WCTabHandle)NewHandle(sizeof(**s->wctab));
387 if (s->wctab == NULL)
388 return; /* do without */
389 (*s->wctab)->wCSeed = 0;
390 (*s->wctab)->wCReserved = 0;
391 (*s->wctab)->ctSize = 0;
392 (*s->wctab)->ctTable[0].value = wContentColor;
393 (*s->wctab)->ctTable[0].rgb = (*s->palette)->pmInfo[DEFAULT_BG].ciRGB;
394 SetWinColor(s->window, s->wctab);
1d4d52ce 395#endif
d082ac49 396 }
397}
398
399/*
400 * Set the cursor shape correctly
401 */
f854b482 402static void mac_adjusttermcursor(WindowPtr window, Point mouse,
403 RgnHandle cursrgn)
404{
d082ac49 405 Session *s;
406 ControlHandle control;
407 short part;
408 int x, y;
1d4d52ce 409#if TARGET_API_MAC_CARBON
410 Cursor arrow;
411 Rect rect;
412 RgnHandle visrgn;
413#endif
d082ac49 414
5a736db6 415 SetPort((GrafPtr)GetWindowPort(window));
347bfcd7 416 s = mac_windowsession(window);
d082ac49 417 GlobalToLocal(&mouse);
418 part = FindControl(mouse, window, &control);
419 if (control == s->scrollbar) {
1d4d52ce 420#if TARGET_API_MAC_CARBON
421 SetCursor(GetQDGlobalsArrow(&arrow));
422 RectRgn(cursrgn, GetControlBounds(s->scrollbar, &rect));
423#else
d082ac49 424 SetCursor(&qd.arrow);
425 RectRgn(cursrgn, &(*s->scrollbar)->contrlRect);
1d4d52ce 426#endif
d082ac49 427 } else {
428 x = mouse.h / s->font_width;
429 y = mouse.v / s->font_height;
1d4d52ce 430 if (s->raw_mouse) {
431#if TARGET_API_MAC_CARBON
432 SetCursor(GetQDGlobalsArrow(&arrow));
433#else
d082ac49 434 SetCursor(&qd.arrow);
1d4d52ce 435#endif
436 } else
d082ac49 437 SetCursor(*GetCursor(iBeamCursor));
438 /* Ask for shape changes if we leave this character cell. */
439 SetRectRgn(cursrgn, x * s->font_width, y * s->font_height,
440 (x + 1) * s->font_width, (y + 1) * s->font_height);
d082ac49 441 }
1d4d52ce 442#if TARGET_API_MAC_CARBON
443 visrgn = NewRgn();
444 GetPortVisibleRegion(GetWindowPort(window), visrgn);
445 SectRgn(cursrgn, visrgn, cursrgn);
446 DisposeRgn(visrgn);
447#else
448 SectRgn(cursrgn, window->visRgn, cursrgn);
449#endif
d082ac49 450}
451
452/*
453 * Enable/disable menu items based on the active terminal window.
454 */
1d4d52ce 455#if TARGET_API_MAC_CARBON
456#define DisableItem DisableMenuItem
457#define EnableItem EnableMenuItem
458#endif
f854b482 459static void mac_adjusttermmenus(WindowPtr window)
460{
d082ac49 461 Session *s;
462 MenuHandle menu;
1d4d52ce 463#if !TARGET_API_MAC_CARBON
d082ac49 464 long offset;
1d4d52ce 465#endif
d082ac49 466
347bfcd7 467 s = mac_windowsession(window);
b537dd42 468 menu = GetMenuHandle(mFile);
469 DisableItem(menu, iSave); /* XXX enable if modified */
470 EnableItem(menu, iSaveAs);
5211281f 471 EnableItem(menu, iDuplicate);
d082ac49 472 menu = GetMenuHandle(mEdit);
473 EnableItem(menu, 0);
474 DisableItem(menu, iUndo);
475 DisableItem(menu, iCut);
476 if (1/*s->term->selstate == SELECTED*/)
477 EnableItem(menu, iCopy);
478 else
479 DisableItem(menu, iCopy);
1d4d52ce 480#if TARGET_API_MAC_CARBON
481 if (1)
482#else
47de7565 483 if (GetScrap(NULL, kScrapFlavorTypeText, &offset) == noTypeErr)
1d4d52ce 484#endif
d082ac49 485 DisableItem(menu, iPaste);
486 else
487 EnableItem(menu, iPaste);
488 DisableItem(menu, iClear);
489 EnableItem(menu, iSelectAll);
7dcd1f87 490 menu = GetMenuHandle(mWindow);
491 EnableItem(menu, 0);
492 EnableItem(menu, iShowEventLog);
d082ac49 493}
494
f854b482 495static void mac_menuterm(WindowPtr window, short menu, short item)
496{
d082ac49 497 Session *s;
498
347bfcd7 499 s = mac_windowsession(window);
d082ac49 500 switch (menu) {
501 case mEdit:
502 switch (item) {
503 case iCopy:
504 /* term_copy(s); */
505 break;
506 case iPaste:
507 term_do_paste(s->term);
508 break;
509 }
7dcd1f87 510 break;
511 case mWindow:
512 switch(item) {
513 case iShowEventLog:
514 mac_showeventlog(s);
515 break;
516 }
517 break;
d082ac49 518 }
519}
520
f854b482 521static void mac_clickterm(WindowPtr window, EventRecord *event)
522{
d082ac49 523 Session *s;
524 Point mouse;
525 ControlHandle control;
526 int part;
1d4d52ce 527 static ControlActionUPP mac_scrolltracker_upp = NULL;
d082ac49 528
347bfcd7 529 s = mac_windowsession(window);
5a736db6 530 SetPort((GrafPtr)GetWindowPort(window));
d082ac49 531 mouse = event->where;
532 GlobalToLocal(&mouse);
533 part = FindControl(mouse, window, &control);
534 if (control == s->scrollbar) {
535 switch (part) {
536 case kControlIndicatorPart:
537 if (TrackControl(control, mouse, NULL) == kControlIndicatorPart)
538 term_scroll(s->term, +1, GetControlValue(control));
539 break;
540 case kControlUpButtonPart:
541 case kControlDownButtonPart:
542 case kControlPageUpPart:
543 case kControlPageDownPart:
1d4d52ce 544 if (mac_scrolltracker_upp == NULL)
545 mac_scrolltracker_upp =
546 NewControlActionUPP(&mac_scrolltracker);
547 TrackControl(control, mouse, mac_scrolltracker_upp);
d082ac49 548 break;
549 }
550 } else {
551 text_click(s, event);
552 }
553}
554
f854b482 555static void text_click(Session *s, EventRecord *event)
556{
d082ac49 557 Point localwhere;
558 int row, col;
559 static UInt32 lastwhen = 0;
560 static Session *lastsess = NULL;
561 static int lastrow = -1, lastcol = -1;
562 static Mouse_Action lastact = MA_NOTHING;
563
5a736db6 564 SetPort((GrafPtr)GetWindowPort(s->window));
d082ac49 565 localwhere = event->where;
566 GlobalToLocal(&localwhere);
567
568 col = PTOCC(localwhere.h);
569 row = PTOCR(localwhere.v);
570 if (event->when - lastwhen < GetDblTime() &&
571 row == lastrow && col == lastcol && s == lastsess)
572 lastact = (lastact == MA_CLICK ? MA_2CLK :
573 lastact == MA_2CLK ? MA_3CLK :
574 lastact == MA_3CLK ? MA_CLICK : MA_NOTHING);
575 else
576 lastact = MA_CLICK;
fc5b0934 577 term_mouse(s->term, MBT_LEFT,
578 event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
d082ac49 579 lastact, col, row, event->modifiers & shiftKey,
580 event->modifiers & controlKey, event->modifiers & optionKey);
581 lastsess = s;
582 lastrow = row;
583 lastcol = col;
584 while (StillDown()) {
585 GetMouse(&localwhere);
586 col = PTOCC(localwhere.h);
587 row = PTOCR(localwhere.v);
fc5b0934 588 term_mouse(s->term, MBT_LEFT,
589 event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
d082ac49 590 MA_DRAG, col, row, event->modifiers & shiftKey,
591 event->modifiers & controlKey,
592 event->modifiers & optionKey);
593 if (row > s->term->rows - 1)
594 term_scroll(s->term, 0, row - (s->term->rows - 1));
595 else if (row < 0)
596 term_scroll(s->term, 0, row);
597 }
fc5b0934 598 term_mouse(s->term, MBT_LEFT,
599 event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
d082ac49 600 MA_RELEASE, col, row, event->modifiers & shiftKey,
601 event->modifiers & controlKey, event->modifiers & optionKey);
602 lastwhen = TickCount();
603}
604
39687cc7 605void write_clip(void *cookie, wchar_t *data, int len, int must_deselect)
606{
1d4d52ce 607#if !TARGET_API_MAC_CARBON
39687cc7 608 Session *s = cookie;
609 char *mactextbuf;
610 ByteCount iread, olen;
611 wchar_t *unitextptr;
612 StScrpRec *stsc;
613 size_t stsz;
614 OSErr err;
615 int i;
616
d082ac49 617 /*
618 * See "Programming with the Text Encoding Conversion Manager"
619 * Appendix E for Unicode scrap conventions.
620 *
d082ac49 621 * XXX Maybe PICT scrap too.
622 */
623 if (ZeroScrap() != noErr)
624 return;
47de7565 625 PutScrap(len * sizeof(*data), kScrapFlavorTypeUnicode, data);
39687cc7 626
627 /* Replace LINE SEPARATORs with CR for TEXT output. */
628 for (i = 0; i < len; i++)
629 if (data[i] == 0x2028)
630 data[i] = 0x000d;
631
34773273 632 mactextbuf = snewn(len, char); /* XXX DBCS */
39687cc7 633 if (s->uni_to_font != NULL) {
634 err = ConvertFromUnicodeToText(s->uni_to_font, len * sizeof(UniChar),
635 (UniChar *)data,
636 kUnicodeUseFallbacksMask,
637 0, NULL, NULL, NULL,
638 len, &iread, &olen, mactextbuf);
639 if (err != noErr && err != kTECUsedFallbacksStatus)
640 return;
641 } else if (s->font_charset != CS_NONE) {
642 unitextptr = data;
643 olen = charset_from_unicode(&unitextptr, &len, mactextbuf, 1024,
644 s->font_charset, NULL, ".", 1);
645 } else
646 return;
47de7565 647 PutScrap(olen, kScrapFlavorTypeText, mactextbuf);
39687cc7 648 sfree(mactextbuf);
649
650 stsz = offsetof(StScrpRec, scrpStyleTab) + sizeof(ScrpSTElement);
651 stsc = smalloc(stsz);
652 stsc->scrpNStyles = 1;
653 stsc->scrpStyleTab[0].scrpStartChar = 0;
654 stsc->scrpStyleTab[0].scrpHeight = s->font_height;
655 stsc->scrpStyleTab[0].scrpAscent = s->font_ascent;
656 stsc->scrpStyleTab[0].scrpFont = s->fontnum;
657 stsc->scrpStyleTab[0].scrpFace = 0;
e3c5b245 658 stsc->scrpStyleTab[0].scrpSize = s->cfg.font.size;
39687cc7 659 stsc->scrpStyleTab[0].scrpColor.red = 0;
660 stsc->scrpStyleTab[0].scrpColor.green = 0;
661 stsc->scrpStyleTab[0].scrpColor.blue = 0;
47de7565 662 PutScrap(stsz, kScrapFlavorTypeTextStyle, stsc);
39687cc7 663 sfree(stsc);
1d4d52ce 664#endif
d082ac49 665}
666
f854b482 667void get_clip(void *frontend, wchar_t **p, int *lenp)
668{
1d4d52ce 669#if TARGET_API_MAC_CARBON
670 *lenp = 0;
671#else
d082ac49 672 Session *s = frontend;
673 static Handle h = NULL;
fd3bd9fb 674 static wchar_t *data = NULL;
675 Handle texth;
d082ac49 676 long offset;
fd3bd9fb 677 int textlen;
678 TextEncoding enc;
679 TextToUnicodeInfo scrap_to_uni;
680 ByteCount iread, olen;
681 int charset;
682 char *tptr;
683 OSErr err;
d082ac49 684
685 if (p == NULL) {
686 /* release memory */
687 if (h != NULL)
688 DisposeHandle(h);
689 h = NULL;
fd3bd9fb 690 if (data != NULL)
691 sfree(data);
692 data = NULL;
693 } else {
47de7565 694 if (GetScrap(NULL, kScrapFlavorTypeUnicode, &offset) > 0) {
fd3bd9fb 695 if (h == NULL)
696 h = NewHandle(0);
47de7565 697 *lenp =
698 GetScrap(h, kScrapFlavorTypeUnicode, &offset) / sizeof(**p);
d082ac49 699 HLock(h);
700 *p = (wchar_t *)*h;
47de7565 701 } else if (GetScrap(NULL, kScrapFlavorTypeText, &offset) > 0) {
fd3bd9fb 702 texth = NewHandle(0);
47de7565 703 textlen = GetScrap(texth, kScrapFlavorTypeText, &offset);
fd3bd9fb 704 HLock(texth);
34773273 705 data = snewn(textlen, wchar_t);
fd3bd9fb 706 /* XXX should use 'styl' scrap if it's there. */
707 if (mac_gestalts.encvvers != 0 &&
708 UpgradeScriptInfoToTextEncoding(smSystemScript,
709 kTextLanguageDontCare,
710 kTextRegionDontCare, NULL,
711 &enc) == noErr &&
712 CreateTextToUnicodeInfoByEncoding(enc, &scrap_to_uni) ==
713 noErr) {
714 err = ConvertFromTextToUnicode(scrap_to_uni, textlen,
715 *texth, 0, 0, NULL, NULL, NULL,
716 textlen * 2,
717 &iread, &olen, data);
718 DisposeTextToUnicodeInfo(&scrap_to_uni);
719 if (err == noErr) {
720 *p = data;
721 *lenp = olen / sizeof(**p);
722 } else {
723 *p = NULL;
724 *lenp = 0;
725 }
726 } else {
727 charset =
728 charset_from_macenc(GetScriptManagerVariable(smSysScript),
729 GetScriptManagerVariable(smRegionCode),
730 mac_gestalts.sysvers, NULL);
731 if (charset != CS_NONE) {
732 tptr = *texth;
733 *lenp = charset_to_unicode(&tptr, &textlen, data,
734 textlen * 2, charset, NULL,
735 NULL, 0);
736 }
737 *p = data;
738 }
739 DisposeHandle(texth);
d082ac49 740 } else {
741 *p = NULL;
742 *lenp = 0;
743 }
fd3bd9fb 744 }
1d4d52ce 745#endif
d082ac49 746}
747
f854b482 748static pascal void mac_scrolltracker(ControlHandle control, short part)
749{
d082ac49 750 Session *s;
751
1d4d52ce 752#if TARGET_API_MAC_CARBON
347bfcd7 753 s = mac_windowsession(GetControlOwner(control));
1d4d52ce 754#else
347bfcd7 755 s = mac_windowsession((*control)->contrlOwner);
1d4d52ce 756#endif
d082ac49 757 switch (part) {
758 case kControlUpButtonPart:
759 term_scroll(s->term, 0, -1);
760 break;
761 case kControlDownButtonPart:
762 term_scroll(s->term, 0, +1);
763 break;
764 case kControlPageUpPart:
765 term_scroll(s->term, 0, -(s->term->rows - 1));
766 break;
767 case kControlPageDownPart:
768 term_scroll(s->term, 0, +(s->term->rows - 1));
769 break;
770 }
771}
772
f854b482 773static void mac_keyterm(WindowPtr window, EventRecord *event)
774{
347bfcd7 775 Session *s = mac_windowsession(window);
6c50d421 776 Key_Sym keysym = PK_NULL;
777 unsigned int mods = 0, flags = PKF_NUMLOCK;
4fa38586 778 UniChar utxt[1];
779 char txt[1];
780 size_t len = 0;
781 ScriptCode key_script;
d082ac49 782
10135a55 783 ObscureCursor();
d082ac49 784
37ea5668 785#if 0
6c50d421 786 fprintf(stderr, "Got key event %08x\n", event->message);
37ea5668 787#endif
d082ac49 788
789 /* No meta key yet -- that'll be rather fun. */
790
791 /* Keys that we handle locally */
792 if (event->modifiers & shiftKey) {
6c50d421 793 switch ((event->message & keyCodeMask) >> 8) {
794 case 0x74: /* shift-pageup */
d082ac49 795 term_scroll(s->term, 0, -(s->term->rows - 1));
6c50d421 796 return;
797 case 0x79: /* shift-pagedown */
d082ac49 798 term_scroll(s->term, 0, +(s->term->rows - 1));
6c50d421 799 return;
d082ac49 800 }
801 }
802
6c50d421 803 if (event->modifiers & shiftKey)
804 mods |= PKM_SHIFT;
805 if (event->modifiers & controlKey)
806 mods |= PKM_CONTROL;
807 if (event->what == autoKey)
808 flags |= PKF_REPEAT;
809
810 /* Mac key events consist of a virtual key code and a character code. */
811
812 switch ((event->message & keyCodeMask) >> 8) {
813 case 0x24: keysym = PK_RETURN; break;
814 case 0x30: keysym = PK_TAB; break;
815 case 0x33: keysym = PK_BACKSPACE; break;
816 case 0x35: keysym = PK_ESCAPE; break;
817
818 case 0x7A: keysym = PK_F1; break;
819 case 0x78: keysym = PK_F2; break;
820 case 0x63: keysym = PK_F3; break;
821 case 0x76: keysym = PK_F4; break;
822 case 0x60: keysym = PK_F5; break;
823 case 0x61: keysym = PK_F6; break;
824 case 0x62: keysym = PK_F7; break;
825 case 0x64: keysym = PK_F8; break;
826 case 0x65: keysym = PK_F9; break;
827 case 0x6D: keysym = PK_F10; break;
828 case 0x67: keysym = PK_F11; break;
829 case 0x6F: keysym = PK_F12; break;
830 case 0x69: keysym = PK_F13; break;
831 case 0x6B: keysym = PK_F14; break;
832 case 0x71: keysym = PK_F15; break;
833
834 case 0x72: keysym = PK_INSERT; break;
835 case 0x73: keysym = PK_HOME; break;
836 case 0x74: keysym = PK_PAGEUP; break;
837 case 0x75: keysym = PK_DELETE; break;
838 case 0x77: keysym = PK_END; break;
839 case 0x79: keysym = PK_PAGEDOWN; break;
840
841 case 0x47: keysym = PK_PF1; break;
842 case 0x51: keysym = PK_PF2; break;
843 case 0x4B: keysym = PK_PF3; break;
844 case 0x43: keysym = PK_PF4; break;
845 case 0x4E: keysym = PK_KPMINUS; break;
846 case 0x45: keysym = PK_KPCOMMA; break;
847 case 0x41: keysym = PK_KPDECIMAL; break;
848 case 0x4C: keysym = PK_KPENTER; break;
849 case 0x52: keysym = PK_KP0; break;
850 case 0x53: keysym = PK_KP1; break;
851 case 0x54: keysym = PK_KP2; break;
852 case 0x55: keysym = PK_KP3; break;
853 case 0x56: keysym = PK_KP4; break;
854 case 0x57: keysym = PK_KP5; break;
855 case 0x58: keysym = PK_KP6; break;
856 case 0x59: keysym = PK_KP7; break;
857 case 0x5B: keysym = PK_KP8; break;
858 case 0x5C: keysym = PK_KP9; break;
859
860 case 0x7B: keysym = PK_LEFT; break;
861 case 0x7C: keysym = PK_RIGHT; break;
862 case 0x7D: keysym = PK_DOWN; break;
863 case 0x7E: keysym = PK_UP; break;
d082ac49 864 }
865
4fa38586 866 /* Map from key script to Unicode. */
867 txt[0] = event->message & charCodeMask;
868 key_script = GetScriptManagerVariable(smKeyScript);
869
870 if (mac_gestalts.encvvers != 0) {
871 static TextToUnicodeInfo key_to_uni = NULL;
872 static ScriptCode key_to_uni_script;
873 TextEncoding enc;
874 ByteCount iread, olen;
875 OSErr err;
876
877 if (key_to_uni != NULL && key_to_uni_script != key_script)
878 DisposeTextToUnicodeInfo(&key_to_uni);
879 if (key_to_uni == NULL || key_to_uni_script != key_script) {
880 if (UpgradeScriptInfoToTextEncoding(key_script,
881 kTextLanguageDontCare,
882 kTextRegionDontCare, NULL,
883 &enc) == noErr &&
884 CreateTextToUnicodeInfoByEncoding(enc, &key_to_uni) == noErr)
885 key_to_uni_script = key_script;
886 else
887 key_to_uni = NULL;
888 }
889 if (key_to_uni != NULL) {
890 err = ConvertFromTextToUnicode(key_to_uni, 1, txt,
891 (kUnicodeKeepInfoMask |
892 kUnicodeStringUnterminatedMask),
893 0, NULL, NULL, NULL,
894 sizeof(utxt), &iread, &olen, utxt);
895 if (err == noErr)
896 len = olen / sizeof(*utxt);
897 }
898 } else {
899 int charset;
900 char *tptr = txt;
901 int tlen = 1;
902
903 charset = charset_from_macenc(key_script,
904 GetScriptManagerVariable(smRegionCode),
905 mac_gestalts.sysvers, NULL);
906 if (charset != CS_NONE) {
907 len = charset_to_unicode(&tptr, &tlen, utxt, sizeof(utxt), charset,
908 NULL, NULL, 0);
909 }
910 }
911 term_key(s->term, keysym, utxt, len, mods, flags);
d082ac49 912}
913
914void request_paste(void *frontend)
915{
916 Session *s = frontend;
917
918 /*
919 * In the Mac OS, pasting is synchronous: we can read the
920 * clipboard with no difficulty, so request_paste() can just go
921 * ahead and paste.
922 */
923 term_do_paste(s->term);
924}
925
64b8ebc6 926static struct {
927 Rect msgrect;
928 Point msgorigin;
8095091b 929 Point zeromouse;
64b8ebc6 930 Session *s;
931 char oldmsg[20];
932} growterm_state;
933
f854b482 934static void mac_growterm(WindowPtr window, EventRecord *event)
935{
d082ac49 936 Rect limits;
937 long grow_result;
938 int newrows, newcols;
939 Session *s;
1d4d52ce 940#if !TARGET_API_MAC_CARBON
64b8ebc6 941 DragGrayRgnUPP draghooksave;
942 GrafPtr portsave;
943 FontInfo fi;
1d4d52ce 944#endif
d082ac49 945
347bfcd7 946 s = mac_windowsession(window);
64b8ebc6 947
1d4d52ce 948#if !TARGET_API_MAC_CARBON
64b8ebc6 949 draghooksave = LMGetDragHook();
950 growterm_state.oldmsg[0] = '\0';
8095091b 951 growterm_state.zeromouse = event->where;
952 growterm_state.zeromouse.h -= s->term->cols * s->font_width;
953 growterm_state.zeromouse.v -= s->term->rows * s->font_height;
64b8ebc6 954 growterm_state.s = s;
955 GetPort(&portsave);
956 SetPort(s->window);
957 BackColor(whiteColor);
958 ForeColor(blackColor);
959 TextFont(systemFont);
960 TextFace(0);
961 TextSize(12);
962 GetFontInfo(&fi);
963 SetRect(&growterm_state.msgrect, 0, 0,
964 StringWidth("\p99999x99999") + 4, fi.ascent + fi.descent + 4);
965 SetPt(&growterm_state.msgorigin, 2, fi.ascent + 2);
966 LMSetDragHook(NewDragGrayRgnUPP(mac_growtermdraghook));
1d4d52ce 967#endif
64b8ebc6 968
d082ac49 969 SetRect(&limits, s->font_width + 15, s->font_height, SHRT_MAX, SHRT_MAX);
970 grow_result = GrowWindow(window, event->where, &limits);
64b8ebc6 971
1d4d52ce 972#if !TARGET_API_MAC_CARBON
64b8ebc6 973 DisposeDragGrayRgnUPP(LMGetDragHook());
974 LMSetDragHook(draghooksave);
975 InvalRect(&growterm_state.msgrect);
976
977 SetPort(portsave);
1d4d52ce 978#endif
64b8ebc6 979
d082ac49 980 if (grow_result != 0) {
981 newrows = HiWord(grow_result) / s->font_height;
982 newcols = (LoWord(grow_result) - 15) / s->font_width;
983 mac_adjustsize(s, newrows, newcols);
984 term_size(s->term, newrows, newcols, s->cfg.savelines);
985 }
986}
987
1d4d52ce 988#if !TARGET_API_MAC_CARBON
64b8ebc6 989static pascal void mac_growtermdraghook(void)
990{
991 Session *s = growterm_state.s;
992 GrafPtr portsave;
993 Point mouse;
994 char buf[20];
786ccf05 995 unsigned char pbuf[20];
64b8ebc6 996 int newrows, newcols;
997
998 GetMouse(&mouse);
8095091b 999 newrows = (mouse.v - growterm_state.zeromouse.v) / s->font_height;
64b8ebc6 1000 if (newrows < 1) newrows = 1;
8095091b 1001 newcols = (mouse.h - growterm_state.zeromouse.h) / s->font_width;
64b8ebc6 1002 if (newcols < 1) newcols = 1;
1003 sprintf(buf, "%dx%d", newcols, newrows);
1004 if (strcmp(buf, growterm_state.oldmsg) == 0)
1005 return;
1006 strcpy(growterm_state.oldmsg, buf);
786ccf05 1007 c2pstrcpy(pbuf, buf);
64b8ebc6 1008
1009 GetPort(&portsave);
1010 SetPort(growterm_state.s->window);
1011 EraseRect(&growterm_state.msgrect);
1012 MoveTo(growterm_state.msgorigin.h, growterm_state.msgorigin.v);
786ccf05 1013 DrawString(pbuf);
64b8ebc6 1014 SetPort(portsave);
1015}
1d4d52ce 1016#endif
64b8ebc6 1017
fabd1805 1018void mac_closeterm(WindowPtr window)
1019{
347bfcd7 1020 Session *s = mac_windowsession(window);
fabd1805 1021
1022 /* XXX warn on close */
1023 HideWindow(s->window);
1024 *s->prev = s->next;
1025 s->next->prev = s->prev;
1026 ldisc_free(s->ldisc);
1027 s->back->free(s->backhandle);
1028 log_free(s->logctx);
1029 if (s->uni_to_font != NULL)
1030 DisposeUnicodeToTextInfo(&s->uni_to_font);
1031 term_free(s->term);
7dcd1f87 1032 mac_freeeventlog(s);
347bfcd7 1033 sfree((WinInfo *)GetWRefCon(s->window));
fabd1805 1034 DisposeWindow(s->window);
1035 DisposePalette(s->palette);
1036 sfree(s);
1037}
1038
f854b482 1039static void mac_activateterm(WindowPtr window, EventRecord *event)
1040{
d082ac49 1041 Session *s;
f854b482 1042 Boolean active = (event->modifiers & activeFlag) != 0;
d082ac49 1043
347bfcd7 1044 s = mac_windowsession(window);
7d22c2e8 1045 s->term->has_focus = active;
d082ac49 1046 term_update(s->term);
1047 if (active)
1048 ShowControl(s->scrollbar);
1049 else {
1050 if (HAVE_COLOR_QD())
1051 PmBackColor(DEFAULT_BG);/* HideControl clears behind the control */
1052 else
1053 BackColor(blackColor);
1054 HideControl(s->scrollbar);
1055 }
1056 mac_drawgrowicon(s);
1057}
1058
f854b482 1059static void mac_updateterm(WindowPtr window)
1060{
d082ac49 1061 Session *s;
1d4d52ce 1062 Rect bbox;
1063#if TARGET_API_MAC_CARBON
1064 RgnHandle visrgn;
1065#endif
d082ac49 1066
347bfcd7 1067 s = mac_windowsession(window);
5a736db6 1068 SetPort((GrafPtr)GetWindowPort(window));
d082ac49 1069 BeginUpdate(window);
1070 pre_paint(s);
1d4d52ce 1071#if TARGET_API_MAC_CARBON
1072 visrgn = NewRgn();
1073 GetPortVisibleRegion(GetWindowPort(window), visrgn);
1074 GetRegionBounds(visrgn, &bbox);
1075#else
1076 bbox = (*window->visRgn)->rgnBBox;
1077#endif
1078 term_paint(s->term, s, PTOCC(bbox.left), PTOCR(bbox.top),
1079 PTOCC(bbox.right), PTOCR(bbox.bottom), 1);
d082ac49 1080 /* Restore default colours in case the Window Manager uses them */
1081 if (HAVE_COLOR_QD()) {
1082 PmForeColor(DEFAULT_FG);
1083 PmBackColor(DEFAULT_BG);
1084 } else {
1085 ForeColor(whiteColor);
1086 BackColor(blackColor);
1087 }
1088 if (FrontWindow() != window)
1d4d52ce 1089#if TARGET_API_MAC_CARBON
1090 EraseRect(GetControlBounds(s->scrollbar, &bbox));
1091 UpdateControls(window, visrgn);
1092 DisposeRgn(visrgn);
1093#else
d082ac49 1094 EraseRect(&(*s->scrollbar)->contrlRect);
1095 UpdateControls(window, window->visRgn);
1d4d52ce 1096#endif
d082ac49 1097 mac_drawgrowicon(s);
1098 post_paint(s);
1099 EndUpdate(window);
1100}
1101
f854b482 1102static void mac_drawgrowicon(Session *s)
1103{
d082ac49 1104 Rect clip;
ea4c3d8a 1105 RgnHandle savergn;
d082ac49 1106
5a736db6 1107 SetPort((GrafPtr)GetWindowPort(s->window));
ea4c3d8a 1108 /*
1109 * Stop DrawGrowIcon giving us space for a horizontal scrollbar
1110 * See Tech Note TB575 for details.
1111 */
1d4d52ce 1112#if TARGET_API_MAC_CARBON
1113 GetPortBounds(GetWindowPort(s->window), &clip);
1114#else
ea4c3d8a 1115 clip = s->window->portRect;
1d4d52ce 1116#endif
ea4c3d8a 1117 clip.left = clip.right - 15;
1118 savergn = NewRgn();
1119 GetClip(savergn);
d082ac49 1120 ClipRect(&clip);
1121 DrawGrowIcon(s->window);
ea4c3d8a 1122 SetClip(savergn);
1123 DisposeRgn(savergn);
d082ac49 1124}
1125
1126struct do_text_args {
1127 Session *s;
1128 Rect textrect;
d082ac49 1129 char *text;
1130 int len;
1131 unsigned long attr;
1132 int lattr;
fd7d8b47 1133 Point numer, denom;
d082ac49 1134};
1135
1136/*
1137 * Call from the terminal emulator to draw a bit of text
1138 *
1139 * x and y are text row and column (zero-based)
1140 */
36566009 1141void do_text(Context ctx, int x, int y, wchar_t *text, int len,
f854b482 1142 unsigned long attr, int lattr)
1143{
d082ac49 1144 Session *s = ctx;
e3c5b245 1145 int style;
d082ac49 1146 struct do_text_args a;
c3aef739 1147 RgnHandle textrgn, saveclip;
1d4d52ce 1148#if TARGET_API_MAC_CARBON
1149 RgnHandle visrgn;
1150#endif
8768ce31 1151 char mactextbuf[1024];
801e70ea 1152 wchar_t *unitextptr;
c3aef739 1153 int i, fontwidth;
801e70ea 1154 ByteCount iread, olen;
1155 OSStatus err;
1d4d52ce 1156 static DeviceLoopDrawingUPP do_text_for_device_upp = NULL;
8768ce31 1157
1158 assert(len <= 1024);
d082ac49 1159
c6958dfe 1160 /* SGT, 2004-10-14: I don't know how to support combining characters
1161 * on the Mac. Hopefully the first person to fail this assertion will
1162 * know how to do it better than me... */
1163 assert(!(attr & TATTR_COMBINING));
1164
5a736db6 1165 SetPort((GrafPtr)GetWindowPort(s->window));
c3aef739 1166
1167 fontwidth = s->font_width;
1168 if ((lattr & LATTR_MODE) != LATTR_NORM)
1169 fontwidth *= 2;
1170
d082ac49 1171 /* First check this text is relevant */
1172 a.textrect.top = y * s->font_height;
1173 a.textrect.bottom = (y + 1) * s->font_height;
c3aef739 1174 a.textrect.left = x * fontwidth;
1175 a.textrect.right = (x + len) * fontwidth;
1176 if (a.textrect.right > s->term->cols * s->font_width)
1177 a.textrect.right = s->term->cols * s->font_width;
1d4d52ce 1178#if TARGET_API_MAC_CARBON
1179 visrgn = NewRgn();
1180 GetPortVisibleRegion(GetWindowPort(s->window), visrgn);
1181 if (!RectInRgn(&a.textrect, visrgn)) {
1182 DisposeRgn(visrgn);
1183 return;
1184 }
1185 DisposeRgn(visrgn);
1186#else
d082ac49 1187 if (!RectInRgn(&a.textrect, s->window->visRgn))
1188 return;
1d4d52ce 1189#endif
d082ac49 1190
801e70ea 1191 if (s->uni_to_font != NULL) {
8768ce31 1192 err = ConvertFromUnicodeToText(s->uni_to_font, len * sizeof(UniChar),
36566009 1193 text, kUnicodeUseFallbacksMask,
8768ce31 1194 0, NULL, NULL, NULL,
1195 1024, &iread, &olen, mactextbuf);
801e70ea 1196 if (err != noErr && err != kTECUsedFallbacksStatus)
379836ca 1197 olen = 0;
8ef2b196 1198 } else if (s->font_charset != CS_NONE) {
801e70ea 1199 /* XXX this is bogus if wchar_t and UniChar are different sizes. */
36566009 1200 unitextptr = (wchar_t *)text;
801e70ea 1201 olen = charset_from_unicode(&unitextptr, &len, mactextbuf, 1024,
8ef2b196 1202 s->font_charset, NULL, ".", 1);
1203 } else
379836ca 1204 olen = 0;
8768ce31 1205
d082ac49 1206 a.s = s;
801e70ea 1207 a.text = mactextbuf;
1208 a.len = olen;
d082ac49 1209 a.attr = attr;
1210 a.lattr = lattr;
c3aef739 1211 switch (lattr & LATTR_MODE) {
1212 case LATTR_NORM:
e3c5b245 1213 TextSize(s->cfg.font.size);
c3aef739 1214 a.numer = s->font_stdnumer;
1215 a.denom = s->font_stddenom;
1216 break;
1217 case LATTR_WIDE:
e3c5b245 1218 TextSize(s->cfg.font.size);
c3aef739 1219 a.numer = s->font_widenumer;
1220 a.denom = s->font_widedenom;
1221 break;
1222 case LATTR_TOP:
1223 case LATTR_BOT:
e3c5b245 1224 TextSize(s->cfg.font.size * 2);
c3aef739 1225 a.numer = s->font_bignumer;
1226 a.denom = s->font_bigdenom;
1227 break;
1228 }
5a736db6 1229 SetPort((GrafPtr)GetWindowPort(s->window));
d082ac49 1230 TextFont(s->fontnum);
e3c5b245 1231 style = s->cfg.font.face;
1232 if ((attr & ATTR_BOLD) && !s->cfg.bold_colour)
d082ac49 1233 style |= bold;
1234 if (attr & ATTR_UNDER)
1235 style |= underline;
1236 TextFace(style);
4d1565a4 1237 TextMode(srcOr);
d082ac49 1238 if (HAVE_COLOR_QD())
1239 if (style & bold) {
1240 SpaceExtra(s->font_boldadjust << 16);
1241 CharExtra(s->font_boldadjust << 16);
1242 } else {
1243 SpaceExtra(0);
1244 CharExtra(0);
1245 }
c3aef739 1246 saveclip = NewRgn();
1247 GetClip(saveclip);
1248 ClipRect(&a.textrect);
d082ac49 1249 textrgn = NewRgn();
1250 RectRgn(textrgn, &a.textrect);
1d4d52ce 1251 if (HAVE_COLOR_QD()) {
1252 if (do_text_for_device_upp == NULL)
1253 do_text_for_device_upp =
1254 NewDeviceLoopDrawingUPP(&do_text_for_device);
1255 DeviceLoop(textrgn, do_text_for_device_upp, (long)&a, 0);
1256 } else
d082ac49 1257 do_text_for_device(1, 0, NULL, (long)&a);
c3aef739 1258 SetClip(saveclip);
1259 DisposeRgn(saveclip);
d082ac49 1260 DisposeRgn(textrgn);
1261 /* Tell the window manager about it in case this isn't an update */
1d4d52ce 1262#if TARGET_API_MAC_CARBON
1263 ValidWindowRect(s->window, &a.textrect);
1264#else
d082ac49 1265 ValidRect(&a.textrect);
1d4d52ce 1266#endif
d082ac49 1267}
1268
1269static pascal void do_text_for_device(short depth, short devflags,
f854b482 1270 GDHandle device, long cookie)
1271{
5a736db6 1272 struct do_text_args *a = (struct do_text_args *)cookie;
4d1565a4 1273 int bgcolour, fgcolour, bright, reverse, tmp;
1d4d52ce 1274#if TARGET_API_MAC_CARBON
1275 CQDProcsPtr gp = GetPortGrafProcs(GetWindowPort(a->s->window));
1276#else
1277 QDProcsPtr gp = a->s->window->grafProcs;
1278#endif
d082ac49 1279
d082ac49 1280 bright = (a->attr & ATTR_BOLD) && a->s->cfg.bold_colour;
4d1565a4 1281 reverse = a->attr & ATTR_REVERSE;
d082ac49 1282
4d1565a4 1283 if (depth == 1 && (a->attr & TATTR_ACTCURS))
1284 reverse = !reverse;
d082ac49 1285
4d1565a4 1286 if (HAVE_COLOR_QD()) {
1287 if (depth > 2) {
37ca32ed 1288 fgcolour = ((a->attr & ATTR_FGMASK) >> ATTR_FGSHIFT);
1289 fgcolour = (fgcolour & 0xF) * 2 + (fgcolour & 0x10 ? 1 : 0);
22afb0a5 1290 bgcolour = ((a->attr & ATTR_BGMASK) >> ATTR_BGSHIFT);
37ca32ed 1291 bgcolour = (bgcolour & 0xF) * 2 + (bgcolour & 0x10 ? 1 : 0);
d082ac49 1292 } else {
4d1565a4 1293 /*
1294 * NB: bold reverse in 2bpp breaks with the usual PuTTY model and
1295 * boldens the background, because that's all we can do.
1296 */
1297 fgcolour = bright ? DEFAULT_FG_BOLD : DEFAULT_FG;
1298 bgcolour = DEFAULT_BG;
d082ac49 1299 }
4d1565a4 1300 if (reverse) {
1301 tmp = fgcolour;
1302 fgcolour = bgcolour;
1303 bgcolour = tmp;
1304 }
1305 if (bright && depth > 2)
37ca32ed 1306 fgcolour |= 1;
4d1565a4 1307 if ((a->attr & TATTR_ACTCURS) && depth > 1) {
e0cbe032 1308 fgcolour = CURSOR_FG;
d082ac49 1309 bgcolour = CURSOR_BG;
d082ac49 1310 }
1311 PmForeColor(fgcolour);
1312 PmBackColor(bgcolour);
4d1565a4 1313 } else { /* No Color Quickdraw */
1314 /* XXX This should be done with a _little_ more configurability */
1315 if (reverse) {
1316 ForeColor(blackColor);
1317 BackColor(whiteColor);
1318 } else {
1319 ForeColor(whiteColor);
1320 BackColor(blackColor);
1321 }
d082ac49 1322 }
1323
4d1565a4 1324 EraseRect(&a->textrect);
c3aef739 1325 switch (a->lattr & LATTR_MODE) {
1326 case LATTR_NORM:
1327 case LATTR_WIDE:
1328 MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent);
1329 break;
1330 case LATTR_TOP:
1331 MoveTo(a->textrect.left, a->textrect.top + a->s->font_ascent * 2);
1332 break;
1333 case LATTR_BOT:
1334 MoveTo(a->textrect.left,
1335 a->textrect.top - a->s->font_height + a->s->font_ascent * 2);
1336 break;
1337 }
d082ac49 1338 /* FIXME: Sort out bold width adjustments on Original QuickDraw. */
1d4d52ce 1339 if (gp != NULL)
1340 InvokeQDTextUPP(a->len, a->text, a->numer, a->denom, gp->textProc);
fd7d8b47 1341 else
1342 StdText(a->len, a->text, a->numer, a->denom);
d082ac49 1343
1344 if (a->attr & TATTR_PASCURS) {
1345 PenNormal();
1346 switch (depth) {
1347 case 1:
1348 PenMode(patXor);
1349 break;
1350 default:
1351 PmForeColor(CURSOR_BG);
1352 break;
1353 }
1354 FrameRect(&a->textrect);
1355 }
1356}
1357
1358void do_cursor(Context ctx, int x, int y, char *text, int len,
1359 unsigned long attr, int lattr)
1360{
1361
e0cbe032 1362 do_text(ctx, x, y, text, len, attr, lattr);
d082ac49 1363}
1364
1365/*
1366 * Call from the terminal emulator to get its graphics context.
1367 * Should probably be called start_redraw or something.
1368 */
f854b482 1369void pre_paint(Session *s)
1370{
2647b103 1371 GDHandle gdh;
1372 Rect myrect, tmprect;
1d4d52ce 1373#if TARGET_API_MAC_CARBON
1374 RgnHandle visrgn;
1375#endif
d082ac49 1376
2647b103 1377 if (HAVE_COLOR_QD()) {
0a0fa8cd 1378 s->term->attr_mask = 0;
5a736db6 1379 SetPort((GrafPtr)GetWindowPort(s->window));
1d4d52ce 1380#if TARGET_API_MAC_CARBON
1381 visrgn = NewRgn();
1382 GetPortVisibleRegion(GetWindowPort(s->window), visrgn);
1383 GetRegionBounds(visrgn, &myrect);
1384 DisposeRgn(visrgn);
1385#else
2647b103 1386 myrect = (*s->window->visRgn)->rgnBBox;
1d4d52ce 1387#endif
2647b103 1388 LocalToGlobal((Point *)&myrect.top);
1389 LocalToGlobal((Point *)&myrect.bottom);
1390 for (gdh = GetDeviceList();
1391 gdh != NULL;
1392 gdh = GetNextDevice(gdh)) {
1393 if (TestDeviceAttribute(gdh, screenDevice) &&
1394 TestDeviceAttribute(gdh, screenActive) &&
1395 SectRect(&(*gdh)->gdRect, &myrect, &tmprect)) {
1396 switch ((*(*gdh)->gdPMap)->pixelSize) {
1397 case 1:
1398 if (s->cfg.bold_colour)
0a0fa8cd 1399 s->term->attr_mask |= ~(ATTR_COLOURS |
1400 (s->cfg.bold_colour ? ATTR_BOLD : 0));
e373bb53 1401 break;
2647b103 1402 case 2:
e373bb53 1403 s->term->attr_mask |= ~ATTR_COLOURS;
1404 break;
1405 default:
1406 s->term->attr_mask = ~0;
1407 return; /* No point checking more screens. */
2647b103 1408 }
1409 }
1410 }
1411 } else
0a0fa8cd 1412 s->term->attr_mask = ~(ATTR_COLOURS |
2647b103 1413 (s->cfg.bold_colour ? ATTR_BOLD : 0));
d082ac49 1414}
1415
f854b482 1416Context get_ctx(void *frontend)
1417{
d082ac49 1418 Session *s = frontend;
1419
1420 pre_paint(s);
1421 return s;
1422}
1423
f854b482 1424void free_ctx(Context ctx)
1425{
d082ac49 1426
1427}
1428
d082ac49 1429/*
1430 * Presumably this does something in Windows
1431 */
f854b482 1432void post_paint(Session *s)
1433{
d082ac49 1434
1435}
1436
1437/*
1438 * Set the scroll bar position
1439 *
1440 * total is the line number of the bottom of the working screen
1441 * start is the line number of the top of the display
1442 * page is the length of the displayed page
1443 */
f854b482 1444void set_sbar(void *frontend, int total, int start, int page)
1445{
d082ac49 1446 Session *s = frontend;
1447
1448 /* We don't redraw until we've set everything up, to avoid glitches */
1d4d52ce 1449 SetControlMinimum(s->scrollbar, 0);
1450 SetControlMaximum(s->scrollbar, total - page);
d082ac49 1451 SetControlValue(s->scrollbar, start);
1fc898ea 1452#if !TARGET_CPU_68K
d082ac49 1453 if (mac_gestalts.cntlattr & gestaltControlMgrPresent)
1454 SetControlViewSize(s->scrollbar, page);
1455#endif
1456}
1457
1458void sys_cursor(void *frontend, int x, int y)
1459{
1460 /*
1461 * I think his is meaningless under Mac OS.
1462 */
1463}
1464
1465/*
1466 * This is still called when mode==BELL_VISUAL, even though the
1467 * visual bell is handled entirely within terminal.c, because we
1468 * may want to perform additional actions on any kind of bell (for
1469 * example, taskbar flashing in Windows).
1470 */
1471void beep(void *frontend, int mode)
1472{
1473 if (mode != BELL_VISUAL)
1474 SysBeep(30);
1475 /*
1476 * XXX We should indicate the relevant window and/or use the
1477 * Notification Manager
1478 */
1479}
1480
1481int char_width(Context ctx, int uc)
1482{
1483 /*
1484 * Until we support exciting character-set stuff, assume all chars are
1485 * single-width.
1486 */
1487 return 1;
1488}
1489
1490/*
1491 * Set icon string -- a no-op here (Windowshade?)
1492 */
1493void set_icon(void *frontend, char *icon) {
1494 Session *s = frontend;
1495
1496}
1497
1498/*
1499 * Set the window title
1500 */
f854b482 1501void set_title(void *frontend, char *title)
1502{
d082ac49 1503 Session *s = frontend;
1504 Str255 mactitle;
1505
7770ad29 1506 c2pstrcpy(mactitle, title);
d082ac49 1507 SetWTitle(s->window, mactitle);
1508}
1509
1510/*
1511 * set or clear the "raw mouse message" mode
1512 */
1513void set_raw_mouse_mode(void *frontend, int activate)
1514{
1515 Session *s = frontend;
1516
1517 s->raw_mouse = activate;
1518 /* FIXME: Should call mac_updatetermcursor as appropriate. */
1519}
1520
1521/*
1522 * Resize the window at the emulator's request
1523 */
8ff3f021 1524void request_resize(void *frontend, int w, int h)
1525{
d082ac49 1526 Session *s = frontend;
8ff3f021 1527 RgnHandle grayrgn;
1528 Rect graybox;
1529 int wlim, hlim;
d082ac49 1530
8ff3f021 1531 /* Arbitrarily clip to the size of the desktop. */
1532 grayrgn = GetGrayRgn();
1533#if TARGET_API_MAC_CARBON
1534 GetRegionBounds(grayrgn, &graybox);
1535#else
1536 graybox = (*grayrgn)->rgnBBox;
1537#endif
1538 wlim = (graybox.right - graybox.left) / s->font_width;
1539 hlim = (graybox.bottom - graybox.top) / s->font_height;
1540 if (w > wlim) w = wlim;
1541 if (h > hlim) h = hlim;
97c511f6 1542 term_size(s->term, h, w, s->cfg.savelines);
d082ac49 1543 mac_initfont(s);
1544}
1545
1546/*
1547 * Iconify (actually collapse) the window at the emulator's request.
1548 */
1549void set_iconic(void *frontend, int iconic)
1550{
1551 Session *s = frontend;
1552 UInt32 features;
1553
1554 if (mac_gestalts.apprvers >= 0x0100 &&
1555 GetWindowFeatures(s->window, &features) == noErr &&
1556 (features & kWindowCanCollapse))
1557 CollapseWindow(s->window, iconic);
1558}
1559
1560/*
1561 * Move the window in response to a server-side request.
1562 */
1563void move_window(void *frontend, int x, int y)
1564{
1565 Session *s = frontend;
1566
1567 MoveWindow(s->window, x, y, FALSE);
1568}
1569
1570/*
1571 * Move the window to the top or bottom of the z-order in response
1572 * to a server-side request.
1573 */
1574void set_zorder(void *frontend, int top)
1575{
1576 Session *s = frontend;
1577
1578 /*
1579 * We also change the input focus to point to the topmost window,
1580 * since that's probably what the Human Interface Guidelines would
1581 * like us to do.
1582 */
1583 if (top)
1584 SelectWindow(s->window);
1585 else
1586 SendBehind(s->window, NULL);
1587}
1588
1589/*
1590 * Refresh the window in response to a server-side request.
1591 */
1592void refresh_window(void *frontend)
1593{
1594 Session *s = frontend;
1595
1596 term_invalidate(s->term);
1597}
1598
1599/*
1600 * Maximise or restore the window in response to a server-side
1601 * request.
1602 */
1603void set_zoomed(void *frontend, int zoomed)
1604{
1605 Session *s = frontend;
1606
1607 ZoomWindow(s->window, zoomed ? inZoomOut : inZoomIn, FALSE);
1608}
1609
1610/*
1611 * Report whether the window is iconic, for terminal reports.
1612 */
1613int is_iconic(void *frontend)
1614{
1615 Session *s = frontend;
1616 UInt32 features;
1617
1618 if (mac_gestalts.apprvers >= 0x0100 &&
1619 GetWindowFeatures(s->window, &features) == noErr &&
1620 (features & kWindowCanCollapse))
1621 return IsWindowCollapsed(s->window);
1622 return FALSE;
1623}
1624
1625/*
1626 * Report the window's position, for terminal reports.
1627 */
1628void get_window_pos(void *frontend, int *x, int *y)
1629{
1630 Session *s = frontend;
1d4d52ce 1631 Rect rect;
d082ac49 1632
1d4d52ce 1633#if TARGET_API_MAC_CARBON
1634 GetPortBounds(GetWindowPort(s->window), &rect);
1635#else
1636 rect = s->window->portRect;
1637#endif
1638 *x = rect.left;
1639 *y = rect.top;
d082ac49 1640}
1641
1642/*
1643 * Report the window's pixel size, for terminal reports.
1644 */
1645void get_window_pixels(void *frontend, int *x, int *y)
1646{
1647 Session *s = frontend;
1d4d52ce 1648 Rect rect;
d082ac49 1649
1d4d52ce 1650#if TARGET_API_MAC_CARBON
1651 GetPortBounds(GetWindowPort(s->window), &rect);
1652#else
1653 rect = s->window->portRect;
1654#endif
1655 *x = rect.right - rect.left;
1656 *y = rect.bottom - rect.top;
d082ac49 1657}
1658
1659/*
1660 * Return the window or icon title.
1661 */
1662char *get_window_title(void *frontend, int icon)
1663{
1664 Session *s = frontend;
b6dfe962 1665 Str255 ptitle;
1666 static char title[256];
d082ac49 1667
b6dfe962 1668 GetWTitle(s->window, ptitle);
1669 p2cstrcpy(title, ptitle);
1670 return title;
d082ac49 1671}
1672
1673/*
1674 * real_palette_set(): This does the actual palette-changing work on behalf
1675 * of palette_set(). Does _not_ call ActivatePalette() in case the caller
1676 * is doing a batch of updates.
1677 */
1678static void real_palette_set(Session *s, int n, int r, int g, int b)
1679{
1680 RGBColor col;
1681
1682 if (!HAVE_COLOR_QD())
1683 return;
1684 col.red = r * 0x0101;
1685 col.green = g * 0x0101;
1686 col.blue = b * 0x0101;
d082ac49 1687 SetEntryColor(s->palette, n, &col);
1688}
1689
1690/*
1691 * Set the logical palette. Called by the terminal emulator.
1692 */
f854b482 1693void palette_set(void *frontend, int n, int r, int g, int b)
1694{
d082ac49 1695 Session *s = frontend;
1696 static const int first[21] = {
1697 0, 2, 4, 6, 8, 10, 12, 14,
1698 1, 3, 5, 7, 9, 11, 13, 15,
e0cbe032 1699 16, 17, 18, 20, 21
d082ac49 1700 };
1701
1702 if (!HAVE_COLOR_QD())
1703 return;
1704 real_palette_set(s, first[n], r, g, b);
e0cbe032 1705 if (first[n] == 18)
d082ac49 1706 real_palette_set(s, first[n]+1, r, g, b);
1707 if (first[n] == DEFAULT_BG)
1708 mac_adjustwinbg(s);
1709 ActivatePalette(s->window);
1710}
1711
1712/*
1713 * Reset to the default palette
1714 */
f854b482 1715void palette_reset(void *frontend)
1716{
d082ac49 1717 Session *s = frontend;
1718 /* This maps colour indices in cfg to those used in our palette. */
1719 static const int ww[] = {
1720 6, 7, 8, 9, 10, 11, 12, 13,
1721 14, 15, 16, 17, 18, 19, 20, 21,
1722 0, 1, 2, 3, 4, 5
1723 };
1724 int i;
1725
1726 if (!HAVE_COLOR_QD())
1727 return;
1728
1729 assert(lenof(ww) == NCOLOURS);
1730
1731 for (i = 0; i < NCOLOURS; i++) {
1732 real_palette_set(s, i,
1733 s->cfg.colours[ww[i]][0],
1734 s->cfg.colours[ww[i]][1],
1735 s->cfg.colours[ww[i]][2]);
1736 }
1737 mac_adjustwinbg(s);
1738 ActivatePalette(s->window);
1739 /* Palette Manager will generate update events as required. */
1740}
1741
1742/*
1743 * Scroll the screen. (`lines' is +ve for scrolling forward, -ve
1744 * for backward.)
1745 */
f854b482 1746void do_scroll(Context ctx, int topline, int botline, int lines)
1747{
341eb978 1748 Session *s = ctx;
d082ac49 1749 Rect r;
11ddab61 1750 RgnHandle scrollrgn = NewRgn();
1751 RgnHandle movedupdate = NewRgn();
1752 RgnHandle update = NewRgn();
1753 Point g2l = { 0, 0 };
d082ac49 1754
5a736db6 1755 SetPort((GrafPtr)GetWindowPort(s->window));
11ddab61 1756
1757 /*
1758 * Work out the part of the update region that will scrolled by
1759 * this operation.
1760 */
1761 if (lines > 0)
1762 SetRectRgn(scrollrgn, 0, (topline + lines) * s->font_height,
1763 s->term->cols * s->font_width,
1764 (botline + 1) * s->font_height);
1765 else
1766 SetRectRgn(scrollrgn, 0, topline * s->font_height,
1767 s->term->cols * s->font_width,
1768 (botline - lines + 1) * s->font_height);
1d4d52ce 1769#if TARGET_API_MAC_CARBON
1770 GetWindowRegion(s->window, kWindowUpdateRgn, movedupdate);
1771#else
1772 GetWindowUpdateRgn(s->window, movedupdate);
1773#endif
11ddab61 1774 GlobalToLocal(&g2l);
1775 OffsetRgn(movedupdate, g2l.h, g2l.v); /* Convert to local co-ords. */
1776 SectRgn(scrollrgn, movedupdate, movedupdate); /* Clip scrolled section. */
1d4d52ce 1777#if TARGET_API_MAC_CARBON
1778 ValidWindowRgn(s->window, movedupdate);
1779#else
11ddab61 1780 ValidRgn(movedupdate);
1d4d52ce 1781#endif
11ddab61 1782 OffsetRgn(movedupdate, 0, -lines * s->font_height); /* Scroll it. */
1783
1951eebc 1784 PenNormal();
d082ac49 1785 if (HAVE_COLOR_QD())
1786 PmBackColor(DEFAULT_BG);
fd7d8b47 1787 else
1788 BackColor(blackColor); /* XXX make configurable */
d082ac49 1789 SetRect(&r, 0, topline * s->font_height,
1790 s->term->cols * s->font_width, (botline + 1) * s->font_height);
1791 ScrollRect(&r, 0, - lines * s->font_height, update);
11ddab61 1792
1d4d52ce 1793#if TARGET_API_MAC_CARBON
1794 InvalWindowRgn(s->window, update);
1795 InvalWindowRgn(s->window, movedupdate);
1796#else
d082ac49 1797 InvalRgn(update);
11ddab61 1798 InvalRgn(movedupdate);
1d4d52ce 1799#endif
11ddab61 1800
1801 DisposeRgn(scrollrgn);
1802 DisposeRgn(movedupdate);
d082ac49 1803 DisposeRgn(update);
1804}
1805
d082ac49 1806/* Dummy routine, only required in plink. */
1807void ldisc_update(void *frontend, int echo, int edit)
1808{
1809}
1810
1811/*
1812 * Mac PuTTY doesn't support printing yet.
1813 */
1814printer_job *printer_start_job(char *printer)
1815{
1816
1817 return NULL;
1818}
1819
1820void printer_job_data(printer_job *pj, void *data, int len)
1821{
1822}
1823
1824void printer_finish_job(printer_job *pj)
1825{
1826}
1827
1828void frontend_keypress(void *handle)
1829{
1830 /*
1831 * Keypress termination in non-Close-On-Exit mode is not
1832 * currently supported in PuTTY proper, because the window
1833 * always has a perfectly good Close button anyway. So we do
1834 * nothing here.
1835 */
1836 return;
1837}
1838
1839/*
1840 * Ask whether to wipe a session log file before writing to it.
1841 * Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
1842 */
9a30e26b 1843int askappend(void *frontend, Filename filename)
d082ac49 1844{
1845
1846 /* FIXME: not implemented yet. */
1847 return 2;
1848}
1849
1e5bde54 1850int from_backend(void *frontend, int is_stderr, const char *data, int len)
1851{
1852 Session *s = frontend;
1853
1854 return term_data(s->term, is_stderr, data, len);
1855}
1856
d082ac49 1857/*
1858 * Emacs magic:
1859 * Local Variables:
1860 * c-file-style: "simon"
1861 * End:
1862 */
1863