-/* $Id: macterm.c,v 1.1.2.15 1999/03/07 23:22:23 ben Exp $ */
+/* $Id: macterm.c,v 1.1.2.18 1999/03/11 23:23:45 ben Exp $ */
/*
* Copyright (c) 1999 Ben Harris
* All rights reserved.
#include <Quickdraw.h>
#include <QuickdrawText.h>
#include <Resources.h>
+#include <Scrap.h>
#include <Sound.h>
#include <ToolUtils.h>
static pascal void mac_scrolltracker(ControlHandle, short);
static pascal void do_text_for_device(short, short, GDHandle, long);
static int mac_keytrans(struct mac_session *, EventRecord *, unsigned char *);
+static void text_click(struct mac_session *, EventRecord *);
/*
* Temporary hack till I get the terminal emulator supporting multiple
SetWinColor(s->window, cth);
}
+/*
+ * Enable/disable menu items based on the active terminal window.
+ */
+void mac_adjusttermmenus(WindowPtr window) {
+ struct mac_session *s;
+ MenuHandle menu;
+ long offset;
+
+ s = (struct mac_session *)GetWRefCon(window);
+ menu = GetMenuHandle(mEdit);
+ EnableItem(menu, 0);
+ DisableItem(menu, iUndo);
+ DisableItem(menu, iCut);
+ DisableItem(menu, iCopy);
+ if (GetScrap(NULL, 'TEXT', &offset) == noTypeErr)
+ DisableItem(menu, iPaste);
+ else
+ EnableItem(menu, iPaste);
+ DisableItem(menu, iClear);
+ EnableItem(menu, iSelectAll);
+}
+
void mac_clickterm(WindowPtr window, EventRecord *event) {
struct mac_session *s;
Point mouse;
TrackControl(control, mouse, mac_scrolltracker);
break;
}
+ } else {
+ text_click(s, event);
+ }
+}
+
+static void text_click(struct mac_session *s, EventRecord *event) {
+ Point localwhere;
+ int row, col;
+ static UInt32 lastwhen = 0;
+ static struct mac_session *lastsess = NULL;
+ static int lastrow = -1, lastcol = -1;
+ static Mouse_Action lastact = MA_NOTHING;
+
+ SetPort(s->window);
+ localwhere = event->where;
+ GlobalToLocal(&localwhere);
+
+ col = localwhere.h / font_width;
+ row = localwhere.v / font_height;
+ 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(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT, lastact,
+ col, row);
+ lastsess = s;
+ lastrow = row;
+ lastcol = col;
+ while (StillDown()) {
+ GetMouse(&localwhere);
+ col = localwhere.h / font_width;
+ row = localwhere.v / font_height;
+ term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT,
+ MA_DRAG, col, row);
+ if (row > rows - 1)
+ term_scroll(0, row - (rows - 1));
+ else if (row <= 0)
+ term_scroll(0, row - 1);
}
+ term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT, MA_RELEASE,
+ col, row);
+ lastwhen = TickCount();
+}
+
+void write_clip(void *data, int len) {
+
+ if (ZeroScrap() != noErr)
+ return;
+ PutScrap(len, 'TEXT', data);
+}
+
+void get_clip(void **p, int *lenp) {
+
+ /* XXX: do something */
}
static pascal void mac_scrolltracker(ControlHandle control, short part) {
InvalRgn(update);
DisposeRgn(update);
}
+
+/*
+ * Emacs magic:
+ * Local Variables:
+ * c-file-style: "simon"
+ * End:
+ */