SetPort(GetWindowPort(s->window));
SetPort((GrafPtr)GetWindowPort(s->window));
static void text_click(Session *s, EventRecord *event) {    Point localwhere;    int row, col;    static UInt32 lastwhen = 0;    static Session *lastsess = NULL;    static int lastrow = -1, lastcol = -1;    static Mouse_Action lastact = MA_NOTHING;    SetPort(GetWindowPort(s->window));    localwhere = event->where;    GlobalToLocal(&localwhere);    col = PTOCC(localwhere.h);    row = PTOCR(localwhere.v);    if (event->when - lastwhen < GetDblTime() &&	row == lastrow && col == lastcol && s == lastsess)	lastact = (lastact == MA_CLICK ? MA_2CLK :		   lastact == MA_2CLK ? MA_3CLK :		   lastact == MA_3CLK ? MA_CLICK : MA_NOTHING);    else	lastact = MA_CLICK;    term_mouse(s->term, MBT_LEFT,	       event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,	       lastact, col, row, event->modifiers & shiftKey,	       event->modifiers & controlKey, event->modifiers & optionKey);    lastsess = s;    lastrow = row;    lastcol = col;    while (StillDown()) {	GetMouse(&localwhere);	col = PTOCC(localwhere.h);	row = PTOCR(localwhere.v);	term_mouse(s->term, MBT_LEFT, 		   event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,		   MA_DRAG, col, row, event->modifiers & shiftKey,		   event->modifiers & controlKey,		   event->modifiers & optionKey);	if (row > s->term->rows - 1)	    term_scroll(s->term, 0, row - (s->term->rows - 1));	else if (row < 0)	    term_scroll(s->term, 0, row);    }    term_mouse(s->term, MBT_LEFT,	       event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,	       MA_RELEASE, col, row, event->modifiers & shiftKey,	       event->modifiers & controlKey, event->modifiers & optionKey);    lastwhen = TickCount();}