SetPort(GetWindowPort(s->window));
SetPort((GrafPtr)GetWindowPort(s->window));
void do_scroll(Context ctx, int topline, int botline, int lines) {    Session *s = ctx;    Rect r;    RgnHandle scrollrgn = NewRgn();    RgnHandle movedupdate = NewRgn();    RgnHandle update = NewRgn();    Point g2l = { 0, 0 };    SetPort(GetWindowPort(s->window));    /*     * Work out the part of the update region that will scrolled by     * this operation.     */    if (lines > 0)	SetRectRgn(scrollrgn, 0, (topline + lines) * s->font_height,		   s->term->cols * s->font_width,		   (botline + 1) * s->font_height);    else	SetRectRgn(scrollrgn, 0, topline * s->font_height,		   s->term->cols * s->font_width,		   (botline - lines + 1) * s->font_height);#if TARGET_API_MAC_CARBON    GetWindowRegion(s->window, kWindowUpdateRgn, movedupdate);#else    GetWindowUpdateRgn(s->window, movedupdate);#endif    GlobalToLocal(&g2l);    OffsetRgn(movedupdate, g2l.h, g2l.v); /* Convert to local co-ords. */    SectRgn(scrollrgn, movedupdate, movedupdate); /* Clip scrolled section. */#if TARGET_API_MAC_CARBON    ValidWindowRgn(s->window, movedupdate);#else    ValidRgn(movedupdate);#endif    OffsetRgn(movedupdate, 0, -lines * s->font_height); /* Scroll it. */    PenNormal();    if (HAVE_COLOR_QD())	PmBackColor(DEFAULT_BG);    else	BackColor(blackColor); /* XXX make configurable */    SetRect(&r, 0, topline * s->font_height,	    s->term->cols * s->font_width, (botline + 1) * s->font_height);    ScrollRect(&r, 0, - lines * s->font_height, update);#if TARGET_API_MAC_CARBON    InvalWindowRgn(s->window, update);    InvalWindowRgn(s->window, movedupdate);#else    InvalRgn(update);    InvalRgn(movedupdate);#endif    DisposeRgn(scrollrgn);    DisposeRgn(movedupdate);    DisposeRgn(update);}