diff -urN links-2.3pre2-orig/Makefile.am links-2.3pre2/Makefile.am
--- links-2.3pre2-orig/Makefile.am	2009-05-17 20:45:41.000000000 +0000
+++ links-2.3pre2/Makefile.am	2011-05-13 09:05:58.243269632 +0000
@@ -4,7 +4,7 @@
 
 man_MANS=links.1
 
-EXTRA_DIST=atheos.cpp $(man_MANS) BRAILLE_HOWTO KEYS BUGS TODO SITES PATCH-gpm-1.20.0-smooth-cursor PATCH-libpng-1.2.18 mailcap.pl rebuild Links_logo.png Unicode/*.cp Unicode/[!C]* intl/[!C]* graphics/*.c graphics/arrow.png graphics/gen graphics/system_font/*.png graphics/font/century_school-medium-roman-serif-vari/*.png graphics/font/century_school-bold-roman-serif-vari/*.png graphics/font/symbol-medium-roman-sans-vari/*.png graphics/font/courier-medium-roman-serif-mono/*.png graphics/font/japanese-medium-roman-sans-mono/*.png graphics/font/century_school-bold-roman-serif-vari/aliases graphics/font/century_school-medium-roman-serif-vari/aliases graphics/font/symbol-medium-roman-sans-vari/aliases doc/links_cal/*.png doc/links_cal/*.html graphics/Makefile graphics/Fontmap graphics/clip.c graphics/links.xpm graphics/makefont graphics/pdf2html graphics/spacer.png links_16x16_1.xpm links_16x16_2.xpm links_32x32.xpm links.nsi
+EXTRA_DIST=atheos.cpp beosgui.cpp $(man_MANS) BRAILLE_HOWTO KEYS BUGS TODO SITES PATCH-gpm-1.20.0-smooth-cursor PATCH-libpng-1.2.18 mailcap.pl rebuild Links_logo.png Unicode/*.cp Unicode/[!C]* intl/[!C]* graphics/*.c graphics/arrow.png graphics/gen graphics/system_font/*.png graphics/font/century_school-medium-roman-serif-vari/*.png graphics/font/century_school-bold-roman-serif-vari/*.png graphics/font/symbol-medium-roman-sans-vari/*.png graphics/font/courier-medium-roman-serif-mono/*.png graphics/font/japanese-medium-roman-sans-mono/*.png graphics/font/century_school-bold-roman-serif-vari/aliases graphics/font/century_school-medium-roman-serif-vari/aliases graphics/font/symbol-medium-roman-sans-vari/aliases doc/links_cal/*.png doc/links_cal/*.html graphics/Makefile graphics/Fontmap graphics/clip.c graphics/links.xpm graphics/makefont graphics/pdf2html graphics/spacer.png links_16x16_1.xpm links_16x16_2.xpm links_32x32.xpm links.nsi links-beos.rdef
 
 bin_PROGRAMS=links
 
@@ -13,6 +13,11 @@
 else
 endif
 
+if BEOS_GR
+links_LDADD=beosgui.o -lbe
+else
+endif
+
 links_SOURCES=af_unix.c auth.c beos.c bfu.c block.c bookmarks.c cache.c charsets.c connect.c cookies.c default.c dip.c directfb.c directfb_cursors.h dither.c dns.c drivers.c error.c file.c finger.c font_include.c framebuffer.c ftp.c gif.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c links_icon.c listedit.c lru.c mailto.c main.c memory.c menu.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c x.c xbm.c links.h cfg.h os_dep.h os_depx.h setup.h codepage.h language.h codepage.inc entity.inc uni_7b.inc language.inc upcase.inc arrow.inc bits.h
 
 dist-hook:
@@ -31,7 +36,12 @@
 CXXFLAGS=@CXXFLAGS@
 
 atheos.o: atheos.cpp
-	$(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c atheos.cpp
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -o $@ -c $<
+
+beosgui.o: beosgui.cpp
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -o $@ -c $<
+
+
 
 datadir = $(prefix)/@DATADIRNAME@
 LIBS = @LIBS@
diff -urN links-2.3pre2-orig/acconfig.h links-2.3pre2/acconfig.h
--- links-2.3pre2-orig/acconfig.h	2009-05-17 20:14:00.000000000 +0000
+++ links-2.3pre2/acconfig.h	2011-05-13 09:04:15.857210880 +0000
@@ -119,6 +119,9 @@
 #undef GRDRV_ATHEOS
 
 /* */
+#undef GRDRV_BEOS
+
+/* */
 #undef DONT_INCLUDE_SETJMP
 
 /* Tiff by Brain */
diff -urN links-2.3pre2-orig/atheos.cpp links-2.3pre2/atheos.cpp
--- links-2.3pre2-orig/atheos.cpp	2004-10-22 18:11:31.000000000 +0000
+++ links-2.3pre2/atheos.cpp	2011-05-13 09:04:15.882638848 +0000
@@ -207,7 +207,7 @@
 	win->Unlock();
 	ath_lock->Lock();
 	win->Lock();
-	if (dev) dev->mouse_handler(dev, last_x = (int)p.x, last_y = (int)p.y, B_DOWN | (b == 2 ? B_RIGHT : b == 3 ? B_MIDDLE : B_LEFT));
+	if (dev) dev->mouse_handler(dev, last_x = (int)p.x, last_y = (int)p.y, BTN_DOWN | (b == 2 ? BTN_RIGHT : b == 3 ? BTN_MIDDLE : BTN_LEFT));
 	ath_lock->Unlock();
 	write(wpipe, " ", 1);
 }
@@ -217,7 +217,7 @@
 	win->Unlock();
 	ath_lock->Lock();
 	win->Lock();
-	if (dev) dev->mouse_handler(dev, last_x = (int)p.x, last_y = (int)p.y, B_UP | (b == 2 ? B_RIGHT : b == 3 ? B_MIDDLE : B_LEFT));
+	if (dev) dev->mouse_handler(dev, last_x = (int)p.x, last_y = (int)p.y, BTN_UP | (b == 2 ? BTN_RIGHT : b == 3 ? BTN_MIDDLE : BTN_LEFT));
 	ath_lock->Unlock();
 	write(wpipe, " ", 1);
 }
@@ -227,7 +227,7 @@
 	win->Unlock();
 	ath_lock->Lock();
 	win->Lock();
-	if (dev) dev->mouse_handler(dev, last_x = (int)p.x, last_y = (int)p.y, !b ? B_MOVE : B_DRAG | (b & 1 ? B_LEFT : b & 2 ? B_RIGHT : b & 4 ? B_MIDDLE : B_LEFT));
+	if (dev) dev->mouse_handler(dev, last_x = (int)p.x, last_y = (int)p.y, !b ? BTN_MOVE : BTN_DRAG | (b & 1 ? BTN_LEFT : b & 2 ? BTN_RIGHT : b & 4 ? BTN_MIDDLE : BTN_LEFT));
 	ath_lock->Unlock();
 	write(wpipe, " ", 1);
 }
@@ -237,8 +237,8 @@
 	win->Unlock();
 	ath_lock->Lock();
 	win->Lock();
-	if (d.y) if (dev) dev->mouse_handler(dev, last_x, last_y, B_MOVE | (d.y > 0 ? B_WHEELDOWN : B_WHEELUP));
-	if (d.x) if (dev) dev->mouse_handler(dev, last_x, last_y, B_MOVE | (d.x < 0 ? B_WHEELLEFT : B_WHEELRIGHT));
+	if (d.y) if (dev) dev->mouse_handler(dev, last_x, last_y, BTN_MOVE | (d.y > 0 ? BTN_WHEELDOWN : BTN_WHEELUP));
+	if (d.x) if (dev) dev->mouse_handler(dev, last_x, last_y, BTN_MOVE | (d.x < 0 ? BTN_WHEELLEFT : BTN_WHEELRIGHT));
 	ath_lock->Unlock();
 	write(wpipe, " ", 1);
 }
diff -urN links-2.3pre2-orig/beos.c links-2.3pre2/beos.c
--- links-2.3pre2-orig/beos.c	2006-09-11 01:47:20.000000000 +0000
+++ links-2.3pre2/beos.c	2011-05-13 09:32:23.000000000 +0000
@@ -3,7 +3,7 @@
  * This file is a part of the Links program, released under GPL
  */
 
-#ifdef __BEOS__
+#if defined __BEOS__ || defined __HAIKU__
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -11,8 +11,9 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <netinet/in.h>
-#include <be/kernel/OS.h>
+#include <kernel/OS.h>
 
 #define SHS	128
 
@@ -20,6 +21,42 @@
 #define MAXINT 0x7fffffff
 #endif
 
+extern int ggr;
+
+#ifdef __cplusplus
+extern "C" {
+int get_input_handle();
+void unblock_stdin();
+void block_stdin();
+}
+#endif
+
+void maybe_force_gr(void)
+{
+	struct stat stn, stin, stout;
+	/* 
+	 * if stdin and out are /dev/null it's likely
+	 * we have been started from the gui...
+	 */
+	if (lstat("/dev/null", &stn) < 0)
+		return;
+	if (fstat(0, &stin) < 0)
+		return;
+	if (fstat(1, &stout) < 0)
+		return;
+	if (stin.st_dev != stn.st_dev)
+		return;
+	if (stout.st_dev != stn.st_dev)
+		return;
+	if (stin.st_ino != stn.st_ino)
+		return;
+	if (stout.st_ino != stn.st_ino)
+		return;
+	ggr = 1;
+}
+
+#if IPPROTO_TCP != 6
+
 int be_read(int s, void *ptr, int len)
 {
 	if (s >= SHS) return recv(s - SHS, ptr, len, 0);
@@ -90,6 +127,10 @@
 
 #define PIPE_RETRIES	10
 
+#ifndef PF_INET
+#define PF_INET AF_INET
+#endif
+
 int be_pipe(int *fd)
 {
 	int s1, s2, s3, l;
@@ -250,4 +291,21 @@
 	return h = ohpipe[1];
 }*/
 
+#else /* IPPROTO_TCP != 6 */
+
+void block_stdin()
+{
+}
+
+void unblock_stdin()
+{
+}
+
+int get_input_handle()
+{
+	return 0;
+}
+
+#endif
+
 #endif
diff -urN links-2.3pre2-orig/beosgui.cpp links-2.3pre2/beosgui.cpp
--- links-2.3pre2-orig/beosgui.cpp	1970-01-01 00:00:00.000000000 +0000
+++ links-2.3pre2/beosgui.cpp	2011-05-13 09:04:15.932446208 +0000
@@ -0,0 +1,884 @@
+/* beos.c
+ * (c) 2007 François Revol
+ * This file is a part of the Links program, released under GPL
+ */
+
+#if defined __BEOS__ || defined __HAIKU__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <kernel/OS.h>
+
+/*
+ * GUI code
+ */
+
+/*
+ * TODO:
+ * - BeOS doesn't handle BView::DrawBitmap() with RGB24, and links doesn't seem to handle RGB32, 
+ *   so the colorspace is forced into 16bpp for now.
+ * - more paste handling ?
+ * - more DnD (maybe check if in menu or not and prepend "g" ?)
+ * - handle DnD of Net+ bookmarks
+ */
+
+#include "cfg.h"
+
+#ifdef GRDRV_BEOS
+
+#include <app/Application.h>
+#include <app/Clipboard.h>
+#include <interface/Bitmap.h>
+#include <interface/Region.h>
+#include <interface/Screen.h>
+#include <interface/View.h>
+#include <interface/Window.h>
+#include <storage/Entry.h>
+#include <storage/File.h>
+#include <storage/Path.h>
+#include <support/Locker.h>
+#include <support/String.h>
+
+extern "C" {
+#include "links.h"
+}
+
+//#define DBG(l...) fprintf(stderr, l);
+#define DBG(l...) {}
+
+/*
+#ifdef debug
+#undef debug
+#endif
+#define debug(x)
+#define fprintf(x, y)
+*/
+
+extern struct graphics_driver beos_driver;
+
+class LinksApplication : public BApplication {
+	public:
+	LinksApplication():BApplication("application/x-vnd.links"){}
+	virtual void RefsReceived(BMessage *message);
+	virtual bool QuitRequested();
+};
+
+class LinksView;
+
+class LinksWindow : public BWindow {
+	public:
+	LinksWindow(BRect r);
+	~LinksWindow();
+	virtual void FrameResized(float width, float height);
+	virtual bool QuitRequested();
+	int resized;
+	LinksView *view;
+};
+
+class LinksView : public BView {
+	public:
+	LinksView(LinksWindow *w);
+	~LinksView();
+	virtual void Draw(BRect r);
+	virtual void MouseDown(BPoint p);
+	virtual void MouseUp(BPoint p);
+	virtual void MouseMoved(BPoint p, uint32 transit, const BMessage *dragmsg);
+	virtual void KeyDown(const char *s, int32 numBytes);
+	virtual void MessageReceived(BMessage *msg);
+	LinksWindow *win;
+	struct graphics_device *dev;
+	void d_flush();
+	int flushing;
+	int last_x, last_y;
+};
+
+#define lv(dev) ((LinksView *)(dev)->driver_data)
+
+#define lock_dev(dev) do { if (!lv(dev)->win->Lock()) return; } while (0)
+#define lock_dev0(dev) do { if (!lv(dev)->win->Lock()) return 0; } while (0)
+#define unlock_dev(dev) do { lv(dev)->win->Unlock(); } while (0)
+
+void be_get_size(struct graphics_device *dev);
+
+#define detach_message(dev) \
+	BMessage *current = Looper()->DetachCurrentMessage(); \
+	if (current) { \
+		current->AddPointer("linksdev", dev); \
+	}
+
+#define pipe_message(dev) \
+	if (current) { \
+		write(wpipe, &current, sizeof(current)); \
+	}
+
+#define detach_and_pipe_message(dev) do { \
+	BMessage *current = Looper()->DetachCurrentMessage(); \
+	if (current) { \
+		current->AddPointer("linksdev", dev); \
+		write(wpipe, &current, sizeof(current)); \
+	} \
+} while (0)
+
+LinksApplication *be_links_app;
+BLocker *be_lock = NULL;
+
+int msg_pipe[2];
+
+thread_id be_app_thread_id;
+
+#define rpipe (msg_pipe[0])
+#define wpipe (msg_pipe[1])
+
+#define small_color (sizeof(rgb_color) <= sizeof(long))
+#define get_color32(c, rgb) rgb_color c((rgb_color){(rgb >> 16) & 255, (rgb >> 8) & 255, rgb & 255, 255})
+
+color_space be_cs_desktop, be_cs_bmp;
+
+int be_x_size, be_y_size;
+
+int be_win_x_size, be_win_y_size;
+int be_win_x_pos, be_win_y_pos;
+
+static BMessage *initial_refs_msg;
+
+void LinksApplication::RefsReceived(BMessage *message)
+{
+	entry_ref ref;
+	//if (!IsLaunching())
+	//	return;
+	BMessenger msgr(WindowAt(0));
+	BMessage *m = new BMessage(*message);
+	m->AddSpecifier("View", (long)0);
+	//m->what = B_SIMPLE_DATA;
+	if (msgr.IsValid()) {
+		msgr.SendMessage(m);
+	} else
+		initial_refs_msg = m;
+}
+
+bool LinksApplication::QuitRequested()
+{
+	BApplication::QuitRequested();
+	//printf("qc: %ld\n", CountWindows());
+	return true;
+}
+
+LinksWindow::LinksWindow(BRect r):BWindow(r, "Links", B_DOCUMENT_WINDOW, 0)
+{
+	DBG("LINKSWINDOW\n");
+	resized = 0;
+	view = NULL;
+}
+
+LinksWindow::~LinksWindow()
+{
+	view = NULL;
+	DBG("~LINKSWINDOW\n");
+}
+
+void LinksWindow::FrameResized(float width, float height)
+{
+	resized = 1;
+}
+
+bool LinksWindow::QuitRequested()
+{
+	detach_and_pipe_message(view->dev);
+	return false;
+}
+
+void do_flush(void *p_dev)
+{
+	struct graphics_device *dev = (struct graphics_device *)p_dev;
+	LinksView *v = lv(dev);
+	v->win->Lock();
+	v->win->Flush();
+	v->win->Unlock();
+	v->flushing = 0;
+}
+
+LinksView::LinksView(LinksWindow *w):BView(w->Bounds(), "Links", B_FOLLOW_ALL, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_NAVIGABLE)
+{
+	DBG("LINKSVIEW\n");
+	(win = w)->AddChild(this);
+	SetViewColor(B_TRANSPARENT_32_BIT);
+	MakeFocus();
+	w->view = this;
+	flushing = 0;
+	last_x = last_y = 0;
+}
+
+LinksView::~LinksView()
+{
+	win->view = NULL;
+	DBG("~LINKSVIEW\n");
+}
+
+void LinksView::d_flush()
+{
+	if (flushing) return;
+	register_bottom_half(do_flush, this->dev);
+	flushing = 1;
+}
+
+#undef select
+
+int be_loop_select(int n, fd_set *r, fd_set *w, fd_set *e, struct timeval *t)
+{
+	int v;
+	v = select(n, r, w, e, t);
+	check_bottom_halves();
+	return v;
+}
+
+void be_paste_string(struct graphics_device *dev, const char *str)
+{
+	unsigned char *s = (unsigned char *)str;
+	int c, i;
+	while (s && *s) {
+		GET_UTF_8(s, c);
+		if (dev) dev->keyboard_handler(dev, c, 0);
+	}
+}
+
+void be_get_event(void *dummy)
+{
+	BMessage *msg;
+	LinksView *view = NULL;
+	LinksWindow *win = NULL;
+	struct graphics_device *dev;
+	read(rpipe, &msg, sizeof(msg));
+	DBG("GETE\n");
+	if (!msg)
+		return;
+	if (msg->FindPointer("linksdev", (void **)&dev) < B_OK)
+		return;
+	if (dev) {
+		view = lv(dev);
+		if (view)
+			win = dynamic_cast<LinksWindow *>(view->Window());
+	}
+	switch (msg->what) {
+	case B_QUIT_REQUESTED:
+		if (dev)
+			dev->keyboard_handler(dev, KBD_CTRL_C, 0);
+		break;
+	case _UPDATE_:
+	{
+		BRect r;
+		if (msg->FindRect("updateRect", &r) < B_OK)
+			return;
+		struct rect rr;
+		rr.x1 = (int)r.left;
+		rr.x2 = (int)r.right + 1;
+		rr.y1 = (int)r.top;
+		rr.y2 = (int)r.bottom + 1;
+		/*DBG("paint: %d %d %d %d\n", rr.x1, rr.x2, rr.y1, rr.y2);*/
+		if (dev) {
+			if (!win->resized) dev->redraw_handler(dev, &rr);
+			else {
+				be_get_size(dev);
+				win->resized = 0;
+				dev->resize_handler(dev);
+			}
+		}
+		check_bottom_halves();
+	}
+		break;
+	case B_MOUSE_DOWN:
+	{
+		BPoint where;
+		int32 buttons;
+		int btn = BTN_LEFT;
+		if (msg->FindInt32("buttons", &buttons) != B_OK)
+			return;
+		if (msg->FindPoint("where", &where) != B_OK)
+			return;
+		if (buttons & B_PRIMARY_MOUSE_BUTTON)
+			btn = BTN_LEFT;
+		else if (buttons & B_SECONDARY_MOUSE_BUTTON)
+			btn = BTN_RIGHT;
+		else if (buttons & B_TERTIARY_MOUSE_BUTTON)
+			btn = BTN_MIDDLE;
+		else if (buttons & (B_TERTIARY_MOUSE_BUTTON << 1))
+			btn = BTN_FOURTH;
+		else if (buttons & (B_TERTIARY_MOUSE_BUTTON << 2))
+			btn = BTN_FIFTH;
+		else if (buttons & (B_TERTIARY_MOUSE_BUTTON << 3))
+			btn = BTN_SIXTH;
+		if (dev) dev->mouse_handler(dev, view->last_x = (int)where.x, view->last_y = (int)where.y, BTN_DOWN | btn);
+	}
+		break;
+	case B_MOUSE_UP:
+	{
+		BPoint where;
+		int32 buttons;
+		int btn = BTN_LEFT;
+		if (msg->FindInt32("buttons", &buttons) != B_OK)
+			return;
+		if (msg->FindPoint("where", &where) != B_OK)
+			return;
+		if (buttons & ~B_PRIMARY_MOUSE_BUTTON == 0)
+			btn = BTN_LEFT;
+		else if (buttons & ~B_SECONDARY_MOUSE_BUTTON == 0)
+			btn = BTN_RIGHT;
+		else if (buttons & ~B_TERTIARY_MOUSE_BUTTON == 0)
+			btn = BTN_MIDDLE;
+		else if (buttons & ~(B_TERTIARY_MOUSE_BUTTON << 1) == 0)
+			btn = BTN_FOURTH;
+		else if (buttons & ~(B_TERTIARY_MOUSE_BUTTON << 2) == 0)
+			btn = BTN_FIFTH;
+		else if (buttons & ~(B_TERTIARY_MOUSE_BUTTON << 3) == 0)
+			btn = BTN_SIXTH;
+		if (dev) dev->mouse_handler(dev, view->last_x = (int)where.x, view->last_y = (int)where.y, BTN_UP | btn);
+	}
+		break;
+	case B_MOUSE_MOVED:
+	{
+		BPoint where;
+		int32 buttons;
+		int btn = BTN_LEFT;
+		if (msg->FindInt32("buttons", &buttons) != B_OK)
+			return;
+		if (msg->FindPoint("where", &where) != B_OK)
+			return;
+		if (buttons & B_PRIMARY_MOUSE_BUTTON)
+			btn = BTN_LEFT;
+		else if (buttons & B_SECONDARY_MOUSE_BUTTON)
+			btn = BTN_RIGHT;
+		else if (buttons & B_TERTIARY_MOUSE_BUTTON)
+			btn = BTN_MIDDLE;
+		else if (buttons & (B_TERTIARY_MOUSE_BUTTON << 1))
+			btn = BTN_FOURTH;
+		else if (buttons & (B_TERTIARY_MOUSE_BUTTON << 2))
+			btn = BTN_FIFTH;
+		else if (buttons & (B_TERTIARY_MOUSE_BUTTON << 3))
+			btn = BTN_SIXTH;
+		if (dev) dev->mouse_handler(dev, view->last_x = (int)where.x, view->last_y = (int)where.y, !buttons ? BTN_MOVE : BTN_DRAG | btn);
+	}
+		break;
+	case B_KEY_DOWN:
+	{
+		int32 modifiers;
+		int32 numBytes;
+		const char *bytes;
+		int c;
+		int mods = 0;
+		if (msg->FindInt32("modifiers", &modifiers) != B_OK)
+			return;
+		if (msg->FindString("bytes", &bytes) != B_OK)
+			return;
+		unsigned char buf[4] = { 0, 0, 0, 0 };
+		unsigned char *ss;
+		if (modifiers & (B_LEFT_CONTROL_KEY | B_RIGHT_CONTROL_KEY | B_LEFT_COMMAND_KEY | B_RIGHT_COMMAND_KEY)) {
+			int32 raw;
+			if (msg->FindInt32("raw_char", &raw) != B_OK)
+				return;
+			buf[0] = (unsigned char)raw;
+			ss = buf;
+		} else
+			ss = (unsigned char *)bytes;
+		
+		GET_UTF_8(ss, c);
+		switch (c) {
+			case B_BACKSPACE: c = KBD_BS; break;
+			case B_ENTER: c = KBD_ENTER; break;
+			case B_SPACE: c = ' '; break;
+			case B_TAB: c = KBD_TAB; break;
+			case B_ESCAPE: c = KBD_ESC; break;
+			case B_LEFT_ARROW: c = KBD_LEFT; break;
+			case B_RIGHT_ARROW: c = KBD_RIGHT; break;
+			case B_UP_ARROW: c = KBD_UP; break;
+			case B_DOWN_ARROW: c = KBD_DOWN; break;
+			case B_INSERT: c = KBD_INS; break;
+			case B_DELETE: c = KBD_DEL; break;
+			case B_HOME: c = KBD_HOME; break;
+			case B_END: c = KBD_END; break;
+			case B_PAGE_UP: c = KBD_PAGE_UP; break;
+			case B_PAGE_DOWN: c = KBD_PAGE_DOWN; break;
+			default: if (c < 32) c = 0;
+				 else modifiers &= ~(B_LEFT_SHIFT_KEY|B_RIGHT_SHIFT_KEY);
+				 break;
+		}
+		if (modifiers & (B_LEFT_SHIFT_KEY|B_RIGHT_SHIFT_KEY))
+			mods |= KBD_SHIFT;
+		if (modifiers & (B_LEFT_CONTROL_KEY|B_RIGHT_CONTROL_KEY))
+			mods |= KBD_CTRL;
+		if (modifiers & (B_LEFT_COMMAND_KEY|B_RIGHT_COMMAND_KEY))
+			mods |= KBD_ALT;
+		if (c) if (dev) dev->keyboard_handler(dev, c, mods);
+	}
+		break;
+	case B_MOUSE_WHEEL_CHANGED:
+	{
+		float delta_x, delta_y;
+		if (msg->FindFloat("be:wheel_delta_x", &delta_x) != B_OK)
+			delta_x = 0;
+		if (msg->FindFloat("be:wheel_delta_y", &delta_y) != B_OK)
+			delta_y = 0;
+		if (delta_y) if (dev) dev->mouse_handler(dev, view->last_x, view->last_y, BTN_MOVE | (delta_y > 0 ? BTN_WHEELDOWN : BTN_WHEELUP));
+		if (delta_x) if (dev) dev->mouse_handler(dev, view->last_x, view->last_y, BTN_MOVE | (delta_x < 0 ? BTN_WHEELLEFT : BTN_WHEELRIGHT));
+	}
+		break;
+	case B_PASTE:
+		if (be_clipboard->Lock()) {
+			BMessage *data = be_clipboard->Data();
+			if (data) {
+				const char *text_plain;
+				ssize_t len;
+				//data->PrintToStream();
+				if (data->FindData("text/plain", B_MIME_TYPE, (const void **)&text_plain, &len) == B_OK) {
+					be_paste_string(dev, text_plain);
+				}
+			}
+			be_clipboard->Unlock();
+		}
+		break;
+	case B_REFS_RECEIVED:
+		if (dev)
+			be_paste_string(dev, "\033\ng");
+		/* FALLTHROUGH */
+	case B_SIMPLE_DATA:
+	{
+		/* something got dropped */
+		entry_ref ref;
+		const char *text_plain;
+		ssize_t len;
+		//msg->PrintToStream();
+		/* try find a file path to paste */
+		if (msg->FindRef("refs", &ref) == B_OK) {
+			BPath path(&ref);
+			if (path.InitCheck() == B_OK) {
+				BFile f(path.Path(), B_READ_ONLY);
+				BString url;
+				if (f.InitCheck() == B_OK && f.ReadAttrString("META:url", &url) >= B_OK) {
+					be_paste_string(dev, url.String());
+				} else
+					be_paste_string(dev, path.Path());
+			}
+		} else if (msg->FindData("text/plain", B_MIME_TYPE, (const void **)&text_plain, &len) == B_OK) {
+			be_paste_string(dev, text_plain);
+		}
+	}
+		break;
+	default:
+		msg->PrintToStream();
+		break;
+	}
+	delete msg;
+}
+
+void be_get_size(struct graphics_device *dev)
+{
+	BRect r;
+	lock_dev(dev);
+	r = lv(dev)->Bounds();
+	unlock_dev(dev);
+	dev->size.x1 = dev->size.y1 = 0;
+	dev->size.x2 = (int)r.Width() + 1;
+	dev->size.y2 = (int)r.Height() + 1;
+}
+
+void LinksView::Draw(BRect r)
+{
+	detach_message(dev);
+	current->AddRect("updateRect", r);
+	pipe_message(dev);
+}
+
+
+void LinksView::MouseDown(BPoint p)
+{
+	detach_and_pipe_message(dev);
+}
+
+void LinksView::MouseUp(BPoint p)
+{
+	detach_and_pipe_message(dev);
+}
+
+void LinksView::MouseMoved(BPoint p, uint32 transit, const BMessage *dragmsg)
+{
+	detach_and_pipe_message(dev);
+}
+
+void LinksView::MessageReceived(BMessage *msg)
+{
+	switch (msg->what) {
+	case B_REFS_RECEIVED:
+	case B_MOUSE_WHEEL_CHANGED:
+	case B_PASTE:
+	case B_SIMPLE_DATA:
+		detach_and_pipe_message(dev);
+		break;
+	default:
+		BView::MessageReceived(msg);
+	}
+}
+
+void LinksView::KeyDown(const char *s, int32 numBytes)
+{
+	detach_and_pipe_message(dev);
+}
+
+unsigned char *be_get_driver_param(void)
+{
+	return NULL;
+}
+
+int32 be_app_thread(void *p)
+{
+	be_links_app->Lock();
+	be_links_app->Run();
+	delete be_links_app;
+	return 0;
+}
+
+unsigned char *be_init_driver(unsigned char *param, unsigned char *display)
+{
+	be_links_app = new LinksApplication();
+	if (!be_links_app) {
+		return stracpy((unsigned char *)"Unable to allocate Application object.\n");
+	}
+	if (c_pipe(msg_pipe)) {
+		delete be_links_app;
+		return stracpy((unsigned char *)"Could not create pipe.\n");
+	}
+	fcntl(rpipe, F_SETFL, O_NONBLOCK);
+	fcntl(wpipe, F_SETFL, O_NONBLOCK);
+	set_handlers(rpipe, be_get_event, NULL, NULL, NULL);
+	be_app_thread_id = spawn_thread(be_app_thread, "links_app", B_NORMAL_PRIORITY, NULL);
+	resume_thread(be_app_thread_id);
+	be_links_app->Unlock();
+	be_cs_desktop = B_NO_COLOR_SPACE;
+	be_x_size = 640;
+	be_y_size = 480;
+	BScreen d;
+	if (d.IsValid()) {
+		be_cs_desktop = d.ColorSpace();
+		be_x_size = (int)d.Frame().Width() + 1;
+		be_y_size = (int)d.Frame().Height() + 1;
+	}
+	be_win_y_size = be_y_size * 9 / 10;
+	be_win_x_size = be_win_y_size;
+	/*
+	DBG("%d %d\n", be_x_size, be_y_size);
+	DBG("%d %d\n", be_win_x_size, be_win_y_size);
+	*/
+	be_win_y_pos = (be_y_size - be_win_y_size) / 2;
+	be_win_x_pos = be_x_size - be_win_x_size - be_win_y_pos;
+	if (/*be_cs_desktop == B_RGB32 ||*/ be_cs_desktop == B_RGB24 || be_cs_desktop == B_RGB16 || be_cs_desktop == B_RGB15) 
+		be_cs_bmp = be_cs_desktop;
+	else if (be_cs_desktop == B_RGB32 || be_cs_desktop == B_RGBA32) be_cs_bmp = B_RGB24;
+	else be_cs_bmp = B_RGB15;
+	be_cs_bmp = B_RGB16; // XXX: DEBUG
+	switch (be_cs_bmp) {
+		case B_RGB24:
+			beos_driver.depth = 0xc3;
+			break;
+		case B_RGB16:
+			beos_driver.depth = 0x82;
+			break;
+		case B_RGB15:
+			beos_driver.depth = 0x7a;
+			break;
+		default:
+			internal((unsigned char *)"unknown depth");
+	}
+	return NULL;
+}
+
+void be_shutdown_driver()
+{
+	status_t ret;
+	//debug((unsigned char *)"D");
+	close(rpipe);
+	close(wpipe);
+	set_handlers(rpipe, NULL, NULL, NULL, NULL);
+	//debug((unsigned char *)"DD");
+	be_links_app->PostMessage(B_QUIT_REQUESTED);
+	//debug((unsigned char *)"E");
+	wait_for_thread(be_app_thread_id, &ret);
+	//debug((unsigned char *)"F");
+}
+
+struct graphics_device *be_init_device()
+{
+	LinksView *view;
+	LinksWindow *win;
+	struct graphics_device *dev = (struct graphics_device *)mem_calloc(sizeof(struct graphics_device));
+	if (!dev) return NULL;
+	dev->drv = &beos_driver;
+	//debug((unsigned char *)"1");
+	win = new LinksWindow(BRect(be_win_x_pos, be_win_y_pos, be_win_x_pos + be_win_x_size, be_win_y_pos + be_win_y_size));
+	//debug((unsigned char *)"2");
+	if (!win) {
+		mem_free(dev);
+		return NULL;
+	}
+	//debug((unsigned char *)"3");
+	view = new LinksView(win);
+	if (!view) {
+		delete win;
+		mem_free(dev);
+		return NULL;
+	}
+	view->dev = dev;
+	dev->driver_data = view;
+	be_get_size(dev);
+	memcpy(&dev->clip, &dev->size, sizeof(struct rect));
+	//debug((unsigned char *)"4");
+	win->Show();
+	win->Lock();
+	view->MakeFocus();
+	win->Unlock();
+	//debug((unsigned char *)"5");
+	if (initial_refs_msg) {
+		BMessenger msgr(win);
+		if (msgr.IsValid()) {
+			msgr.SendMessage(initial_refs_msg);
+			initial_refs_msg = NULL;
+		}
+	}
+	return dev;
+}
+
+void be_shutdown_device(struct graphics_device *dev)
+{
+	LinksWindow *win = lv(dev)->win;
+	unregister_bottom_half(do_flush, dev);
+	lv(dev)->dev = NULL;
+	win->PostMessage(B_QUIT_REQUESTED);
+	mem_free(dev);
+}
+
+void be_set_title(struct graphics_device *dev, unsigned char *title)
+{
+	LinksWindow *win = lv(dev)->win;
+	lock_dev(dev);
+	win->SetTitle((const char *)title);
+	lv(dev)->d_flush();
+	unlock_dev(dev);
+}
+
+/*
+int be_get_filled_bitmap(struct bitmap *bmp, long color)
+{
+	internal((unsigned char *)"nedopsano");
+	return 0;
+}
+*/
+
+int be_get_empty_bitmap(struct bitmap *bmp)
+{
+	DBG("bmp\n");
+//DBG("bmp (%d, %d) cs %08x\n", bmp->x, bmp->y, be_cs_bmp);
+	BRect r(0, 0, bmp->x - 1, bmp->y - 1);
+	BBitmap *b = new BBitmap(r, /*B_RGB32*/be_cs_bmp);
+	if (!b) {
+		bmp->data = NULL;
+DBG("%s: error 1\n", __FUNCTION__);
+		return 0;
+	}
+	if (!b->IsValid()) {
+		bmp->data = NULL;
+		delete b;
+DBG("%s: error 2\n", __FUNCTION__);
+		return 0;
+	}
+	if (b->LockBits() < B_OK) {
+		bmp->data = NULL;
+		delete b;
+DBG("%s: error 3\n", __FUNCTION__);
+		return 0;
+	}
+	bmp->data = b->Bits();
+	bmp->skip = b->BytesPerRow();
+	bmp->flags = b;
+//DBG("bmp: data %p, skip %d, flags %p\n", bmp->data, bmp->skip, bmp->flags);
+	return 0;
+}
+
+void be_register_bitmap(struct bitmap *bmp)
+{
+	BBitmap *b = (BBitmap *)bmp->flags;
+	b->UnlockBits();
+}
+
+void *be_prepare_strip(struct bitmap *bmp, int top, int lines)
+{
+	DBG("preps\n");
+	BBitmap *b = (BBitmap *)bmp->flags;
+	if (b->LockBits() < B_OK)
+		return NULL;
+	bmp->data = b->Bits();
+	bmp->skip = b->BytesPerRow();
+	return ((char *)bmp->data) + bmp->skip * top;
+}
+
+void be_commit_strip(struct bitmap *bmp, int top, int lines)
+{
+	BBitmap *b = (BBitmap *)bmp->flags;
+	b->UnlockBits();
+}
+
+void be_unregister_bitmap(struct bitmap *bmp)
+{
+	DBG("unb\n");
+	BBitmap *b = (BBitmap *)bmp->flags;
+	delete b;
+}
+
+void be_draw_bitmap(struct graphics_device *dev, struct bitmap *bmp, int x, int y)
+{
+	DBG("drawb\n");
+	BBitmap *b = (BBitmap *)bmp->flags;
+	lock_dev(dev);
+	lv(dev)->DrawBitmap(b, b->Bounds(), BRect(x, y, x + bmp->x - 1, y + bmp->y - 1));
+	lv(dev)->d_flush();
+	unlock_dev(dev);
+}
+
+void be_draw_bitmaps(struct graphics_device *dev, struct bitmap **bmp, int n, int x, int y)
+{
+	LinksView *lvv = lv(dev);
+	lock_dev(dev);
+	while (n--) {
+		BBitmap *b = (BBitmap *)(*bmp)->flags;
+		lvv->DrawBitmap(b, b->Bounds(), BRect(x, y, x + (*bmp)->x, y + (*bmp)->y));
+		x += (*bmp)->x;
+		bmp++;
+	}
+	lv(dev)->d_flush();
+	unlock_dev(dev);
+}
+
+long be_get_color(int rgb)
+{
+	if (small_color) {
+		get_color32(c, rgb);
+		return *(long *)(void *)&c;
+	} else return rgb & 0xffffff;
+}
+
+void be_fill_area(struct graphics_device *dev, int x1, int y1, int x2, int y2, long color)
+{
+	DBG("fill\n");
+	if (x1 >= x2 || y1 >= y2) return;
+	lock_dev(dev);
+	if (small_color)
+		lv(dev)->SetHighColor(*(rgb_color *)(void *)&color);
+	else
+		lv(dev)->SetHighColor(get_color32(, color));
+	lv(dev)->FillRect(BRect(x1, y1, x2 - 1, y2 - 1));
+	lv(dev)->d_flush();
+	unlock_dev(dev);
+}
+
+void be_draw_hline(struct graphics_device *dev, int x1, int y, int x2, long color)
+{
+	DBG("hline\n");
+	if (x1 >= x2) return;
+	lock_dev(dev);
+	if (small_color)
+		lv(dev)->SetHighColor(*(rgb_color *)(void *)&color);
+	else
+		lv(dev)->SetHighColor(get_color32(, color));
+	lv(dev)->StrokeLine(BPoint(x1, y), BPoint(x2 - 1, y));
+	lv(dev)->d_flush();
+	unlock_dev(dev);
+}
+
+void be_draw_vline(struct graphics_device *dev, int x, int y1, int y2, long color)
+{
+	DBG("vline\n");
+	if (y1 >= y2) return;
+	lock_dev(dev);
+	if (small_color)
+		lv(dev)->SetHighColor(*(rgb_color *)(void *)&color);
+	else
+		lv(dev)->SetHighColor(get_color32(, color));
+	lv(dev)->StrokeLine(BPoint(x, y1), BPoint(x, y2 - 1));
+	lv(dev)->d_flush();
+	unlock_dev(dev);
+}
+
+int be_hscroll(struct graphics_device *dev, struct rect_set **ignore, int sc)
+{
+	DBG("hscroll\n");
+	if (dev->clip.x1 >= dev->clip.x2 || dev->clip.y1 >= dev->clip.y2) return 0;
+	if (sc <= dev->clip.x1 - dev->clip.x2) return 1;
+	if (sc >= dev->clip.x2 - dev->clip.x1) return 1;
+	lock_dev0(dev);
+	if (sc > 0) lv(dev)->CopyBits(BRect(dev->clip.x1, dev->clip.y1, dev->clip.x2 - sc - 1, dev->clip.y2 - 1), BRect(dev->clip.x1 + sc, dev->clip.y1, dev->clip.x2 - 1, dev->clip.y2 - 1));
+	else lv(dev)->CopyBits(BRect(dev->clip.x1 - sc, dev->clip.y1, dev->clip.x2 - 1, dev->clip.y2 - 1), BRect(dev->clip.x1, dev->clip.y1, dev->clip.x2 + sc - 1, dev->clip.y2 - 1));
+	lv(dev)->d_flush();
+	unlock_dev(dev);
+	return 1;
+}
+
+int be_vscroll(struct graphics_device *dev, struct rect_set **ignore, int sc)
+{
+	DBG("vscroll\n");
+	if (!sc || dev->clip.x1 >= dev->clip.x2 || dev->clip.y1 >= dev->clip.y2) return 0;
+	if (sc <= dev->clip.y1 - dev->clip.y2) return 1;
+	if (sc >= dev->clip.y2 - dev->clip.y1) return 1;
+	lock_dev0(dev);
+	if (sc > 0) lv(dev)->CopyBits(BRect(dev->clip.x1, dev->clip.y1, dev->clip.x2 - 1, dev->clip.y2 - sc - 1), BRect(dev->clip.x1, dev->clip.y1 + sc, dev->clip.x2 - 1, dev->clip.y2 - 1));
+	else lv(dev)->CopyBits(BRect(dev->clip.x1, dev->clip.y1 - sc, dev->clip.x2 - 1, dev->clip.y2 - 1), BRect(dev->clip.x1, dev->clip.y1, dev->clip.x2 - 1, dev->clip.y2 + sc - 1));
+	lv(dev)->d_flush();
+	unlock_dev(dev);
+	return 1;
+}
+
+void be_set_clip_area(struct graphics_device *dev, struct rect *r)
+{
+	DBG("setc\n");
+	memcpy(&dev->clip, r, sizeof(struct rect));
+	lock_dev(dev);
+	BRegion clip(BRect(r->x1, r->y1, r->x2 - 1, r->y2 - 1));
+	lv(dev)->ConstrainClippingRegion(&clip);
+	unlock_dev(dev);
+}
+
+struct graphics_driver beos_driver = {
+	(unsigned char *)"beos",
+	be_init_driver,
+	be_init_device,
+	be_shutdown_device,
+	be_shutdown_driver,
+	be_get_driver_param,
+	be_get_empty_bitmap,
+	/*be_get_filled_bitmap,*/
+	be_register_bitmap,
+	be_prepare_strip,
+	be_commit_strip,
+	be_unregister_bitmap,
+	be_draw_bitmap,
+	be_draw_bitmaps,
+	be_get_color,
+	be_fill_area,
+	be_draw_hline,
+	be_draw_vline,
+	be_hscroll,
+	be_vscroll,
+	be_set_clip_area,
+	dummy_block,
+	dummy_unblock,
+	be_set_title,
+	NULL,				/* exec */
+	0,				/* depth */
+	0, 0,				/* size */
+	0,				/* flags */
+	0,				/* codepage */
+	NULL,				/* shell */
+};
+
+#endif /* GRDRV_BEOS */
+
+#endif
diff -urN links-2.3pre2-orig/bfu.c links-2.3pre2/bfu.c
--- links-2.3pre2-orig/bfu.c	2011-04-19 15:17:48.000000000 +0000
+++ links-2.3pre2/bfu.c	2011-05-13 09:04:15.983302144 +0000
@@ -474,7 +474,7 @@
 			draw_to_window(win, (void (*)(struct terminal *, void *))gf_val(display_menu_txt, display_menu_gfx), menu);
 			break;
 		case EV_MOUSE:
-			if ((ev->b & BM_ACT) == B_MOVE) break;
+			if ((ev->b & BM_ACT) == BTN_MOVE) break;
 			if (ev->x < menu->x || ev->x >= menu->x+menu->xw || ev->y < menu->y || ev->y >= menu->y+menu->yw) {
 				int f = 1;
 				for (w1 = win; (void *)w1 != &win->term->windows; w1 = w1->next) {
@@ -498,7 +498,7 @@
 					if (ev->x > m1->x && ev->x < m1->x+m1->xw-1 && ev->y > m1->y && ev->y < m1->y+m1->yw-1) goto del;
 					f--;
 				}
-				if ((ev->b & BM_ACT) == B_DOWN) goto del;
+				if ((ev->b & BM_ACT) == BTN_DOWN) goto del;
 				bbb:;
 			} else {
 				if (!(ev->x < menu->x || ev->x >= menu->x+menu->xw || ev->y < menu->y + gf_val(1, G_MENU_TOP_BORDER) || ev->y >= menu->y + menu->yw - gf_val(1, G_MENU_TOP_BORDER))) {
@@ -510,7 +510,7 @@
 						scroll_menu(menu, 0);
 						draw_to_window(win, (void (*)(struct terminal *, void *))gf_val(display_menu_txt, display_menu_gfx), menu);
 						menu_oldview = menu_oldsel = -1;
-						if ((ev->b & BM_ACT) == B_UP/* || menu->items[s].in_m*/) select_menu(win->term, menu);
+						if ((ev->b & BM_ACT) == BTN_UP/* || menu->items[s].in_m*/) select_menu(win->term, menu);
 					}
 				}
 			}
@@ -698,8 +698,8 @@
 			draw_to_window(win, (void (*)(struct terminal *, void *))display_mainmenu, menu);
 			break;
 		case EV_MOUSE:
-			if ((ev->b & BM_ACT) == B_MOVE) break;
-			if ((ev->b & BM_ACT) == B_DOWN && ev->y >= gf_val(1, G_BFU_FONT_SIZE)) delete_window_ev(win, ev);
+			if ((ev->b & BM_ACT) == BTN_MOVE) break;
+			if ((ev->b & BM_ACT) == BTN_DOWN && ev->y >= gf_val(1, G_BFU_FONT_SIZE)) delete_window_ev(win, ev);
 			else if (ev->y < gf_val(1, G_BFU_FONT_SIZE)) {
 				int i;
 				int p = gf_val(2, G_MAINMENU_LEFT_BORDER);
@@ -710,7 +710,7 @@
 					if (ev->x >= o && ev->x < p) {
 						menu->selected = i;
 						draw_to_window(win, (void (*)(struct terminal *, void *))display_mainmenu, menu);
-						if ((ev->b & BM_ACT) == B_UP || menu->items[s].in_m) select_mainmenu(win->term, menu);
+						if ((ev->b & BM_ACT) == BTN_UP || menu->items[s].in_m) select_mainmenu(win->term, menu);
 						break;
 					}
 				}
@@ -1046,7 +1046,7 @@
 				dlg->selected = di - dlg->items;
 				x_display_dlg_item(dlg, di, 1);
 			}
-			if ((ev->b & BM_ACT) == B_UP) dlg_select_item(dlg, di);
+			if ((ev->b & BM_ACT) == BTN_UP) dlg_select_item(dlg, di);
 			return 1;
 		case D_FIELD:
 		case D_FIELD_PASS:
@@ -1082,7 +1082,7 @@
 				dlg->selected = di - dlg->items;
 				x_display_dlg_item(dlg, di, 1);
 			}
-			if ((ev->b & BM_ACT) == B_UP) dlg_select_item(dlg, di);
+			if ((ev->b & BM_ACT) == BTN_UP) dlg_select_item(dlg, di);
 			return 1;
 	}
 	return 0;
@@ -1221,9 +1221,9 @@
 			draw_to_window(dlg->win, (void (*)(struct terminal *, void *))redraw_dialog, dlg);
 			break;
 		case EV_MOUSE:
-			if ((ev->b & BM_ACT) == B_MOVE) break;
+			if ((ev->b & BM_ACT) == BTN_MOVE) break;
 			for (i = 0; i < dlg->n; i++) if (dlg_mouse(dlg, &dlg->items[i], ev)) break;
-			if ((ev->b & BM_ACT) == B_DOWN && (ev->b & BM_BUTT) == B_MIDDLE) {
+			if ((ev->b & BM_ACT) == BTN_DOWN && (ev->b & BM_BUTT) == BTN_MIDDLE) {
 				di = &dlg->items[dlg->selected];  /* don't delete this!!! it's here because of jump from mouse event */
 				if (di->item->type == D_FIELD || di->item->type == D_FIELD_PASS) goto clipbd_paste;
 			}
@@ -1409,9 +1409,9 @@
 				}
 			}
 			if (ev->x == KBD_ENTER) for (i = 0; i < dlg->n; i++)
-				if (dlg->dlg->items[i].type == D_BUTTON && dlg->dlg->items[i].gid & B_ENTER) goto sel;
+				if (dlg->dlg->items[i].type == D_BUTTON && dlg->dlg->items[i].gid & BTN_ENTER) goto sel;
 			if (ev->x == KBD_ESC) for (i = 0; i < dlg->n; i++)
-				if (dlg->dlg->items[i].type == D_BUTTON && dlg->dlg->items[i].gid & B_ESC) goto sel;
+				if (dlg->dlg->items[i].type == D_BUTTON && dlg->dlg->items[i].gid & BTN_ESC) goto sel;
 			if (((ev->x == KBD_TAB && !ev->y) || ev->x == KBD_DOWN || ev->x == KBD_RIGHT) && (dlg->n > 1 || term->spec->braille)) {
 				if (term->spec->braille) dlg->brl_y = dlg->items[0].y - 3;
 				x_display_dlg_item(dlg, &dlg->items[dlg->selected], 0);
@@ -1447,11 +1447,11 @@
 	unsigned char *end;
 	double d = strtod(di->cdata, (char **)(void *)&end);
 	if (!*di->cdata || *end) {
-		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_EXPECTED), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_EXPECTED), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		return 1;
 	}
 	if (100*d < di->item->gid || 100*d > di->item->gnum) {
-		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_OUT_OF_RANGE), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_OUT_OF_RANGE), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		return 1;
 	}
 	return 0;
@@ -1462,11 +1462,11 @@
 	unsigned char *end;
 	long l = strtol(di->cdata, (char **)(void *)&end, 10);
 	if (!*di->cdata || *end) {
-		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_EXPECTED), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_EXPECTED), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		return 1;
 	}
 	if (l < di->item->gid || l > di->item->gnum) {
-		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_OUT_OF_RANGE), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_OUT_OF_RANGE), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		return 1;
 	}
 	return 0;
@@ -1477,11 +1477,11 @@
 	unsigned char *end;
 	long l = strtol(di->cdata, (char **)(void *)&end, 16);
 	if (!*di->cdata || *end) {
-		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_EXPECTED), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_EXPECTED), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		return 1;
 	}
 	if (l < di->item->gid || l > di->item->gnum) {
-		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_OUT_OF_RANGE), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_OUT_OF_RANGE), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		return 1;
 	}
 	return 0;
@@ -1491,7 +1491,7 @@
 {
 	unsigned char *p;
 	for (p = di->cdata; *p; p++) if (*p > ' ') return 0;
-	msg_box(dlg->win->term, NULL, TEXT(T_BAD_STRING), AL_CENTER, TEXT(T_EMPTY_STRING_NOT_ALLOWED), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+	msg_box(dlg->win->term, NULL, TEXT(T_BAD_STRING), AL_CENTER, TEXT(T_EMPTY_STRING_NOT_ALLOWED), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 	return 1;
 }
 
@@ -2283,7 +2283,7 @@
 	va_start(va, check);
 	for (i = 1; i <= n; i++) {
 		dlg->items[i].type = D_BUTTON;
-		dlg->items[i].gid = i == 1 ? B_ENTER : i == n ? B_ESC : 0;
+		dlg->items[i].gid = i == 1 ? BTN_ENTER : i == n ? BTN_ESC : 0;
 		dlg->items[i].fn = i != n || n == 1 ? input_field_ok : input_field_cancel;
 		dlg->items[i].dlen = 0;
 		dlg->items[i].text = va_arg(va, unsigned char *);
diff -urN links-2.3pre2-orig/block.c links-2.3pre2/block.c
--- links-2.3pre2-orig/block.c	2011-04-19 15:17:48.000000000 +0000
+++ links-2.3pre2/block.c	2011-05-13 09:04:16.001310720 +0000
@@ -222,11 +222,11 @@
 	d->items[0].data = url;
 	d->items[0].fn = check_nonempty;
 	d->items[1].type = D_BUTTON;
-	d->items[1].gid = B_ENTER;
+	d->items[1].gid = BTN_ENTER;
 	d->items[1].fn = ok_dialog;
 	d->items[1].text = TEXT(T_OK);
 	d->items[2].type = D_BUTTON;
-	d->items[2].gid = B_ESC;
+	d->items[2].gid = BTN_ESC;
 	d->items[2].text = TEXT(T_CANCEL);
 	d->items[2].fn = cancel_dialog;
 	d->items[3].type = D_END;
diff -urN links-2.3pre2-orig/bookmarks.c links-2.3pre2/bookmarks.c
--- links-2.3pre2-orig/bookmarks.c	2011-04-19 15:17:48.000000000 +0000
+++ links-2.3pre2/bookmarks.c	2011-05-13 09:04:16.036438016 +0000
@@ -370,12 +370,12 @@
 	}
 
 	d->items[a+1].type = D_BUTTON;
-	d->items[a+1].gid = B_ENTER;
+	d->items[a+1].gid = BTN_ENTER;
 	d->items[a+1].fn = ok_dialog;
 	d->items[a+1].text = TEXT(T_OK);
 	
 	d->items[a+2].type = D_BUTTON;
-	d->items[a+2].gid = B_ESC;
+	d->items[a+2].gid = BTN_ESC;
 	d->items[a+2].text = TEXT(T_CANCEL);
 	d->items[a+2].fn = cancel_dialog;
 	
diff -urN links-2.3pre2-orig/cfg.h links-2.3pre2/cfg.h
--- links-2.3pre2-orig/cfg.h	2002-05-07 10:13:18.000000000 +0000
+++ links-2.3pre2/cfg.h	2011-05-13 09:33:41.000000000 +0000
@@ -16,7 +16,7 @@
 /* no one will probably ever port svgalib on atheos or beos or port atheos
    interface to beos, but anyway: make sure they don't clash */
 
-#ifdef __BEOS__
+#if defined __BEOS__ || defined __HAIKU__
 #ifdef GRDRV_SVGALIB
 #undef GRDRV_SVGALIB
 #endif
diff -urN links-2.3pre2-orig/configure.in links-2.3pre2/configure.in
--- links-2.3pre2-orig/configure.in	2011-04-19 15:30:57.000000000 +0000
+++ links-2.3pre2/configure.in	2011-05-13 09:04:16.068681728 +0000
@@ -18,7 +18,7 @@
 dnl Checks for programs.
 AC_PROG_CC
 
-#AC_PROG_CXX
+AC_PROG_CXX
 #AC_PROG_AWK
 #AM_PROG_LEX
 #AC_PROG_YACC
@@ -33,6 +33,7 @@
 
 dnl Check for libraries
 
+AC_SEARCH_LIBS(socket, socket network)
 AC_CACHE_CHECK([for EMX], ac_cv_have_emx,
 	AC_TRY_COMPILE(, [#ifndef __EMX__
 	kill me!
@@ -220,7 +221,10 @@
 	if test "$ac_cv_lib_socket_gethostbyname" = no; then
 		AC_CHECK_LIB(nsl, gethostbyname)
 		if test "$ac_cv_lib_nsl_gethostbyname" = no; then
-			AC_ERROR([gethostbyname function not present])
+			AC_CHECK_LIB(bind, gethostbyname)
+			if test "$ac_cv_lib_bind_gethostbyname" = no; then
+				AC_ERROR([gethostbyname function not present])
+			fi
 		fi
 	fi
 fi
@@ -329,6 +333,7 @@
 fi
 #AC_CHECK_FUNC(clone, AC_DEFINE(HAVE_CLONE))
 AC_CHECK_HEADERS(atheos/threads.h)
+AC_CHECK_HEADERS(kernel/OS.h)
 AC_HAVE_FUNCS(spawn_thread)
 AC_HAVE_FUNCS(resume_thread)
 
@@ -458,6 +463,7 @@
 
 
 cf_have_atheos=no
+cf_have_beos=no
 
 if test "$cf_use_graphics" != no; then
 	AC_DEFINE(G)
@@ -469,6 +475,7 @@
 dnl AC_ARG_WITH(sdl, [  --without-sdl           compile without SDL graphics driver],[if test "$withval" = no; then disable_sdl=yes; else disable_sdl=no; fi])
 AC_ARG_WITH(pmshell, [  --without-pmshell       compile without PMShell graphics driver],[if test "$withval" = no; then disable_pmshell=yes; else disable_pmshell=no; fi])
 AC_ARG_WITH(atheos, [  --without-atheos        compile without Atheos graphics driver],[if test "$withval" = no; then disable_atheos=yes; else disable_atheos; fi])
+AC_ARG_WITH(beos, [  --without-beos        compile without BeOS/Haiku graphics driver],[if test "$withval" = no; then disable_beos=yes; else disable_beos; fi])
 
 	drivers=""
 
@@ -604,6 +611,31 @@
 	fi
 fi
 
+if test "$disable_beos" != yes ; then
+	old_ext="$ac_ext"
+	ac_ext=cpp
+	AC_CHECK_HEADERS(interface/View.h)
+	AC_CHECK_HEADERS(interface/Window.h)
+	AC_CHECK_HEADERS(interface/Screen.h)
+	AC_CHECK_HEADERS(interface/Bitmap.h)
+	AC_CHECK_HEADERS(support/Locker.h)
+	AC_CHECK_HEADERS(app/Application.h)
+	ac_ext="$old_ext"
+
+	if test "$ac_cv_header_kernel_OS_h" = yes &&
+	   test "$ac_cv_header_interface_View_h" = yes &&
+	   test "$ac_cv_header_interface_Window_h" = yes &&
+	   test "$ac_cv_header_interface_Screen_h" = yes &&
+	   test "$ac_cv_header_interface_Bitmap_h" = yes &&
+	   test "$ac_cv_header_support_Locker_h" = yes &&
+	   test "$ac_cv_header_app_Application_h" = yes; then
+		AC_PROG_CXX
+		AC_DEFINE(GRDRV_BEOS)
+		drivers="$drivers BEOS"
+		cf_have_beos=yes
+	fi
+fi
+
 	AC_CHECK_LIB(z, inflate)
 	PKG_CHECK_MODULES(LIBPNG,libpng >= 1.0.0,pkgconfig_libpng=yes,pkgconfig_libpng=no)
 	if test "$pkgconfig_libpng" = "yes"; then
@@ -681,6 +713,7 @@
 
 
 AM_CONDITIONAL(ATHEOS_GR, test "$cf_have_atheos" = yes)
+AM_CONDITIONAL(BEOS_GR, test "$cf_have_beos" = yes)
 
 test "$ac_cv_have_emx" = yes && LDFLAGS="$LDFLAGS -Zexe"
 
diff -urN links-2.3pre2-orig/default.c links-2.3pre2/default.c
--- links-2.3pre2-orig/default.c	2011-04-19 15:17:48.000000000 +0000
+++ links-2.3pre2/default.c	2011-05-13 09:04:16.099876864 +0000
@@ -449,7 +449,7 @@
 	}
 	add_to_strn(&config_file, name);
 	if ((err = write_to_config_file(config_file, c))) {
-		if (term) msg_box(term, NULL, TEXT(T_CONFIG_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_UNABLE_TO_WRITE_TO_CONFIG_FILE), ": ", get_err_msg(-err), NULL, NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		if (term) msg_box(term, NULL, TEXT(T_CONFIG_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_UNABLE_TO_WRITE_TO_CONFIG_FILE), ": ", get_err_msg(-err), NULL, NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		mem_free(c);
 		mem_free(config_file);
 		return -1;
diff -urN links-2.3pre2-orig/directfb.c links-2.3pre2/directfb.c
--- links-2.3pre2-orig/directfb.c	2008-06-10 20:53:29.000000000 +0000
+++ links-2.3pre2/directfb.c	2011-05-13 09:04:16.108527616 +0000
@@ -652,25 +652,25 @@
 
             if (event.type == DWET_BUTTONUP)
               {
-                flags = B_UP;
+                flags = BTN_UP;
                 data->window->UngrabPointer (data->window);
               }
             else
               {
-                flags = B_DOWN;
+                flags = BTN_DOWN;
                 data->window->GrabPointer (data->window);
               }
 
             switch (event.button)
               {
               case DIBI_LEFT:
-                flags |= B_LEFT;
+                flags |= BTN_LEFT;
                 break;
               case DIBI_RIGHT:
-                flags |= B_RIGHT;
+                flags |= BTN_RIGHT;
                 break;
               case DIBI_MIDDLE:
-                flags |= B_MIDDLE;
+                flags |= BTN_MIDDLE;
                 break;
               default:
                 continue;
@@ -682,8 +682,8 @@
 
         case DWET_WHEEL:
           gd->mouse_handler (gd, event.x, event.y,
-                             B_MOVE |
-                             (event.step > 0 ? B_WHEELUP : B_WHEELDOWN));
+                             BTN_MOVE |
+                             (event.step > 0 ? BTN_WHEELUP : BTN_WHEELDOWN));
 	  break;
 
         case DWET_MOTION:
@@ -698,16 +698,16 @@
             switch (event.buttons)
               {
               case DIBM_LEFT:
-                flags = B_DRAG | B_LEFT;
+                flags = BTN_DRAG | BTN_LEFT;
                 break;
               case DIBM_RIGHT:
-                flags = B_DRAG | B_RIGHT;
+                flags = BTN_DRAG | BTN_RIGHT;
                 break;
               case DIBM_MIDDLE:
-                flags = B_DRAG | B_MIDDLE;
+                flags = BTN_DRAG | BTN_MIDDLE;
                 break;
               default:
-                flags = B_MOVE;
+                flags = BTN_MOVE;
                 break;
               }
 
diff -urN links-2.3pre2-orig/drivers.c links-2.3pre2/drivers.c
--- links-2.3pre2-orig/drivers.c	2011-04-19 15:17:48.000000000 +0000
+++ links-2.3pre2/drivers.c	2011-05-13 09:04:16.130285568 +0000
@@ -31,6 +31,9 @@
 #ifdef GRDRV_ATHEOS
 extern struct graphics_driver atheos_driver;
 #endif
+#ifdef GRDRV_BEOS
+extern struct graphics_driver beos_driver;
+#endif
 #ifdef GRDRV_SDL
 extern struct graphics_driver sdl_driver;
 #endif
@@ -48,6 +51,9 @@
 #ifdef GRDRV_ATHEOS
 	&atheos_driver,
 #endif
+#ifdef GRDRV_BEOS
+	&beos_driver,
+#endif
 #ifndef SPAD
 #ifdef GRDRV_X
 	&x_driver,
diff -urN links-2.3pre2-orig/framebuffer.c links-2.3pre2/framebuffer.c
--- links-2.3pre2-orig/framebuffer.c	2011-04-19 15:17:49.000000000 +0000
+++ links-2.3pre2/framebuffer.c	2011-05-13 09:04:16.148897792 +0000
@@ -383,7 +383,7 @@
 	if (mouse_y < 0) mouse_y = 0;
 	ev.x = mouse_x;
 	ev.y = mouse_y;
-	ev.b = B_MOVE;
+	ev.b = BTN_MOVE;
 	if (!current_virtual_device) return;
 	if (current_virtual_device->mouse_handler) current_virtual_device->mouse_handler(current_virtual_device, ev.x, ev.y, ev.b);
 	redraw_mouse();
@@ -1018,26 +1018,26 @@
 
 	ev.x = mouse_x;
 	ev.y = mouse_y;
-	if (gev.buttons & GPM_B_LEFT) ev.b = B_LEFT;
-	else if (gev.buttons & GPM_B_MIDDLE) ev.b = B_MIDDLE;
-	else if (gev.buttons & GPM_B_RIGHT) ev.b = B_RIGHT;
+	if (gev.buttons & GPM_B_LEFT) ev.b = BTN_LEFT;
+	else if (gev.buttons & GPM_B_MIDDLE) ev.b = BTN_MIDDLE;
+	else if (gev.buttons & GPM_B_RIGHT) ev.b = BTN_RIGHT;
 	else ev.b = 0;
-	if (gev.type & GPM_DOWN) ev.b |= B_DOWN;
-	else if (gev.type & GPM_UP) ev.b |= B_UP;
-	else if (gev.type & GPM_DRAG) ev.b |= B_DRAG;
-	else ev.b |= B_MOVE;
+	if (gev.type & GPM_DOWN) ev.b |= BTN_DOWN;
+	else if (gev.type & GPM_UP) ev.b |= BTN_UP;
+	else if (gev.type & GPM_DRAG) ev.b |= BTN_DRAG;
+	else ev.b |= BTN_MOVE;
 
 #ifndef USE_GPM_DX
 	if (fb_msetsize < 0) {
 	} else if (fb_msetsize < 10) {
 		fb_msetsize++;
-	} else if ((ev.b & BM_ACT) == B_MOVE && !(ev.b & BM_BUTT)) {
+	} else if ((ev.b & BM_ACT) == BTN_MOVE && !(ev.b & BM_BUTT)) {
 		fb_mouse_setsize();
 		fb_msetsize = -1;
 	}
 #endif
 
-	if (((ev.b & BM_ACT) == B_MOVE && !(ev.b & BM_BUTT)) || (ev.b & BM_ACT) == B_DRAG) {
+	if (((ev.b & BM_ACT) == BTN_MOVE && !(ev.b & BM_BUTT)) || (ev.b & BM_ACT) == BTN_DRAG) {
 		if (can_read(fb_hgpm)) goto again;
 	}
 
diff -urN links-2.3pre2-orig/jsint.c links-2.3pre2/jsint.c
--- links-2.3pre2-orig/jsint.c	2008-08-15 23:37:46.000000000 +0000
+++ links-2.3pre2/jsint.c	2011-05-13 09:04:16.185860096 +0000
@@ -1272,8 +1272,8 @@
 		txt,   /* message */
 		jsid,   /* data for button functions */
 		3,   /* # of buttons */
-		TEXT(T_OK),js_upcall_confirm_ok_pressed,B_ENTER,  /* first button */
-		TEXT(T_CANCEL),js_upcall_confirm_cancel_pressed,B_ESC,  /* second button */
+		TEXT(T_OK),js_upcall_confirm_ok_pressed,BTN_ENTER,  /* first button */
+		TEXT(T_CANCEL),js_upcall_confirm_cancel_pressed,BTN_ESC,  /* second button */
 		TEXT(T_KILL_SCRIPT), js_kill_script_pressed,NULL
 	);
 
@@ -1342,7 +1342,7 @@
 		txt,   /* message */
 		jsid,   /* data for button functions */
 		2,   /* # of buttons */
-		TEXT(T_OK),js_upcall_alert_ok_pressed,B_ENTER|B_ESC,
+		TEXT(T_OK),js_upcall_alert_ok_pressed,BTN_ENTER|BTN_ESC,
 		TEXT(T_KILL_SCRIPT), js_kill_script_pressed,NULL
 	);
 
@@ -2933,8 +2933,8 @@
 			jsid->n?TEXT(T_JS_IS_ATTEMPTING_TO_OPEN_NEW_WINDOW_WITH_URL):TEXT(T_JS_IS_ATTEMPTING_TO_GO_TO_URL), " \"",jsid->string,"\".",NULL,   /* message */
 			jsid,   /* data for button functions */
 			3,   /* # of buttons */
-			TEXT(T_ALLOW),js_upcall_goto_url_ok_pressed,B_ENTER,
-			TEXT(T_REJECT),js_upcall_goto_url_cancel_pressed,B_ESC,
+			TEXT(T_ALLOW),js_upcall_goto_url_ok_pressed,BTN_ENTER,
+			TEXT(T_REJECT),js_upcall_goto_url_cancel_pressed,BTN_ESC,
 			TEXT(T_KILL_SCRIPT), js_kill_script_pressed,NULL  /* dirty trick: gimme_js_id_string and gimme_js_id begins with the same long */
 		);
 		js_mem_free(s);
@@ -3089,8 +3089,8 @@
 			TEXT(T_JS_IS_ATTEMPTING_TO_GO_INTO_HISTORY), txt, TEXT(T_TO_URL), " \"",url,"\".",NULL,   /* message */
 			jsid,   /* data for button functions */
 			3,   /* # of buttons */
-			TEXT(T_ALLOW),js_upcall_goto_history_ok_pressed,B_ENTER,
-			TEXT(T_REJECT),js_upcall_goto_url_cancel_pressed,B_ESC,
+			TEXT(T_ALLOW),js_upcall_goto_history_ok_pressed,BTN_ENTER,
+			TEXT(T_REJECT),js_upcall_goto_url_cancel_pressed,BTN_ESC,
 			TEXT(T_KILL_SCRIPT), js_kill_script_pressed,NULL  /* dirty trick: gimme_js_id_string and gimme_js_id begins with the same long */
 		);
 		js_mem_free(s);
diff -urN links-2.3pre2-orig/kbd.c links-2.3pre2/kbd.c
--- links-2.3pre2-orig/kbd.c	2011-04-19 15:17:49.000000000 +0000
+++ links-2.3pre2/kbd.c	2011-05-13 09:04:16.190054400 +0000
@@ -843,10 +843,10 @@
 						ev.y = (unsigned char)(itrm->kqueue[el+3]) - ' ' - 1 + ((int)((unsigned char)(itrm->kqueue[el+4]) - ' ' - 1) << 7);
 						if ( ev.y & (1 << 13)) ev.y = 0; /* ev.y |= ~0 << 14; */
 						switch ((itrm->kqueue[el] - ' ') ^ xterm_button) { /* Every event changhes only one bit */
-						    case TW_BUTT_LEFT:   ev.b = B_LEFT | ( (xterm_button & TW_BUTT_LEFT) ? B_UP : B_DOWN ); break; 
-						    case TW_BUTT_MIDDLE: ev.b = B_MIDDLE | ( (xterm_button & TW_BUTT_MIDDLE) ? B_UP :  B_DOWN ); break;
-						    case TW_BUTT_RIGHT:  ev.b = B_RIGHT | ( (xterm_button & TW_BUTT_RIGHT) ? B_UP : B_DOWN ); break;
-						    case 0: ev.b = B_DRAG;
+						    case TW_BUTT_LEFT:   ev.b = BTN_LEFT | ( (xterm_button & TW_BUTT_LEFT) ? BTN_UP : BTN_DOWN ); break; 
+						    case TW_BUTT_MIDDLE: ev.b = BTN_MIDDLE | ( (xterm_button & TW_BUTT_MIDDLE) ? BTN_UP :  BTN_DOWN ); break;
+						    case TW_BUTT_RIGHT:  ev.b = BTN_RIGHT | ( (xterm_button & TW_BUTT_RIGHT) ? BTN_UP : BTN_DOWN ); break;
+						    case 0: ev.b = BTN_DRAG;
 						    /* default : Twin protocol error */
 						}
 						xterm_button = itrm->kqueue[el] - ' ';
@@ -854,15 +854,15 @@
 					} else {
 						ev.x = itrm->kqueue[el+1] - ' ' - 1;
 						ev.y = itrm->kqueue[el+2] - ' ' - 1;
-						ev.b = B_DOWN;
-						if (itrm->kqueue[el] & 4) ev.b = B_DRAG;
-						if ((ev.b |= (itrm->kqueue[el] & BM_BUTT) | B_DOWN) == 3) {
-							ev.b = B_UP;
+						ev.b = BTN_DOWN;
+						if (itrm->kqueue[el] & 4) ev.b = BTN_DRAG;
+						if ((ev.b |= (itrm->kqueue[el] & BM_BUTT) | BTN_DOWN) == 3) {
+							ev.b = BTN_UP;
 							if (xterm_button != -1) ev.b |= xterm_button;
 						}  
-						/*if ((itrm->kqueue[el] & 4) && ev.b != B_UP) ev.b |= B_DRAG;*/
+						/*if ((itrm->kqueue[el] & 4) && ev.b != BTN_UP) ev.b |= BTN_DRAG;*/
 						xterm_button = -1;
-						if ((ev.b & BM_ACT) == B_DOWN) xterm_button = ev.b & BM_BUTT;
+						if ((ev.b & BM_ACT) == BTN_DOWN) xterm_button = ev.b & BM_BUTT;
 						el += 3;
 					}
 					ev.ev = EV_MOUSE;
diff -urN links-2.3pre2-orig/links-beos.rdef links-2.3pre2/links-beos.rdef
--- links-2.3pre2-orig/links-beos.rdef	1970-01-01 00:00:00.000000000 +0000
+++ links-2.3pre2/links-beos.rdef	2011-05-13 09:04:16.208928768 +0000
@@ -0,0 +1,97 @@
+/*
+** links-beos.rdef
+**
+** Automatically generated by BResourceParser on
+** Thursday, December 13, 2007 at 23:46:45.
+**
+*/
+
+resource(1, "BEOS:APP_FLAGS") (#'APPF') $"01000000";
+
+resource(1, "BEOS:APP_VERSION") #'APPV' array {
+	$"02000000010000000000000000000000210000006C696E6B7320322E31707265"
+	$"3333000000000000000000000000000000000000000000000000000000000000"
+	$"00000000000000000000000000000000000000004C696E6B732062726F777365"
+	$"7220322E31707265333300000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000"
+};
+
+resource(101, "BEOS:L:STD_ICON") #'ICON' array {
+	$"2A2A2A2A2A2A2A2A2A2A2A2A2A2A2C0000363434343434343434343434343434"
+	$"2A2A2A2A2A2A2A2A2A2A2A2A2A2A2C0000363434343434343434343434343434"
+	$"2A2A2A2B2B2B2B2B2B2B2B2B2B2B2C0000363434343434343434343434343434"
+	$"2A2A2A3200000000000000000000000000363434343434343434343434343434"
+	$"2A2A2A2FF1313200000000000131310000363434343434343434343434343434"
+	$"2A2A2A2A2A2A2A30000000002B2A2C0000363434343434343434343434343434"
+	$"2A2A2A2A2A2A2A2F000000002A2A2C0000363434343434343434343434343434"
+	$"2A2A2A2A2A2A2A2F000000002A2A2C0000363434343434343434343434343434"
+	$"2A2A2A2A2A2A2A2F000000002A2A2C0000363434343434343434343434343434"
+	$"2A2A2A2A2A2A2A2F000000002A2A2C0000363434343434343434343434343434"
+	$"2A2A2A2A2A2A2A2F000000002A2A2C0000363434343434343434343434343434"
+	$"2A2A2A2A2A2A2A2F000000002A2A2C0000363434343434343434343434343434"
+	$"2A2A2A2A2A2A2A2F000000002A2A2C0000363434343434343434343434343434"
+	$"2A2A2A2A2A2A2A2F000000002A2A2C0000363434343434343434343434343434"
+	$"2C2C2C2C2C2C2C30000000002C2C2D0000373636363636363636363636363636"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"0000000000000000000000000000000000000000000000000000000000000000"
+	$"2222222222222226000000002222230000151A1A1A1A1A1A1A1A1A1A1A1A1A1A"
+	$"20202020202020250000000020202200001A3F3F3F3F3F3F3F3F3F3F3F3F3F3F"
+	$"20202020202020250000000020202200001A3F3F3F3F3F3F3F1501113F3F3F3F"
+	$"20202020202020250000000020202200001A3F3F3F3F3F3F3F0E00133F3F3F3F"
+	$"20202020202020250000000020202200001A3F3F3F3F3F3F3F0500163F3F3F3F"
+	$"20202020202020250000000020202200001A3F3F3F3F3F3F1A0000193F3F3F3F"
+	$"20202020202020250000000020202200001A3F3F3F3F3F3F0C00001B3F3F3F3F"
+	$"20202020202020250000000020202200001A3F3F3F3F3F190000001E3F3F3F3F"
+	$"20202020202020250000000020202200001A3F3F3F3F1A030000013F3F3F3F3F"
+	$"20202020202020270000000023202200001A3F1E170C00000000043F3F3F3F3F"
+	$"2020202628292900000000000029290000040300000000000000063F3F3F3F3F"
+	$"20202027292929292929292929292900000203030303030303030B3F3F3F3F3F"
+	$"20202020202020202020202020202200001A3F3F3F3F3F3F3F3F3F3F3F3F3F3F"
+	$"20202020202020202020202020202200001A3F3F3F3F3F3F3F3F3F3F3F3F3F3F"
+	$"20202020202020202020202020202200001A3F3F3F3F3F3F3F3F3F3F3F3F3F3F"
+};
+
+resource(101, "BEOS:M:STD_ICON") #'MICN' array {
+	$"2A2A2A2A2A2A2A303A34343434343434"
+	$"2A2C3030303030F73A34343434343434"
+	$"2A2B2D300000EB323A34343434343434"
+	$"2A2A2A2C00002A303A34343434343434"
+	$"2A2A2A2C00002A303A34343434343434"
+	$"2A2A2A2C00002A303A34343434343434"
+	$"2A2A2A2C00002A303A34343434343434"
+	$"303030310000F1333D3A3A3A3A3A3A3A"
+	$"2626262700002629050D0D0D0D0D0D0D"
+	$"20202022000020260D3F3F3F1D143F3F"
+	$"20202022000020260D3F3F3F140A3F3F"
+	$"20202022000020260D3F3F3F090D3F3F"
+	$"20202022000020260D3F3F16000F3F3F"
+	$"20222427000026280710090000123F3F"
+	$"202225252525252807111111111A3F3F"
+	$"20202020202020260D3F3F3F3F3F3F3F"
+};
+
+resource(1, "BEOS:APP_SIG") (#'MIMS') "application/x-vnd.links";
+
+resource(1, "BEOS:FILE_TYPES") message {
+	"types" = "text/html",
+	"types" = "application/x-vnd.Be-bookmark",
+	"types" = "application/x-vnd.Be.URL.http"
+};
+
diff -urN links-2.3pre2-orig/links.h links-2.3pre2/links.h
--- links-2.3pre2-orig/links.h	2011-04-19 15:17:49.000000000 +0000
+++ links-2.3pre2/links.h	2011-05-13 09:04:16.239337472 +0000
@@ -989,26 +989,26 @@
 /* kbd.c */
 
 #define BM_BUTT		15
-#define B_LEFT		0
-#define B_MIDDLE	1
-#define B_RIGHT		2
-#define B_FOURTH	3
-#define B_FIFTH		4
-#define B_SIXTH		5
-#define B_WHEELUP	8
-#define B_WHEELDOWN	9
-#define B_WHEELUP1	10
-#define B_WHEELDOWN1	11
-#define B_WHEELLEFT	12
-#define B_WHEELRIGHT	13
-#define B_WHEELLEFT1	14
-#define B_WHEELRIGHT1	15
+#define BTN_LEFT		0
+#define BTN_MIDDLE	1
+#define BTN_RIGHT		2
+#define BTN_FOURTH	3
+#define BTN_FIFTH		4
+#define BTN_SIXTH		5
+#define BTN_WHEELUP	8
+#define BTN_WHEELDOWN	9
+#define BTN_WHEELUP1	10
+#define BTN_WHEELDOWN1	11
+#define BTN_WHEELLEFT	12
+#define BTN_WHEELRIGHT	13
+#define BTN_WHEELLEFT1	14
+#define BTN_WHEELRIGHT1	15
 
 #define BM_ACT		48
-#define B_DOWN		0
-#define B_UP		16
-#define B_DRAG		32
-#define B_MOVE		48
+#define BTN_DOWN		0
+#define BTN_UP		16
+#define BTN_DRAG		32
+#define BTN_MOVE		48
 
 #define KBD_ENTER	-0x100
 #define KBD_BS		-0x101
@@ -3014,15 +3014,15 @@
 #define D_FIELD_PASS	3
 #define D_BUTTON	4
 
-#define B_ENTER		1
-#define B_ESC		2
+#define BTN_ENTER		1
+#define BTN_ESC		2
 
 struct dialog_item_data;
 struct dialog_data;
 
 struct dialog_item {
 	int type;
-	int gid, gnum; /* for buttons: gid - flags B_XXX */	/* for fields: min/max */ /* for box: gid is box height */
+	int gid, gnum; /* for buttons: gid - flags BTN_XXX */	/* for fields: min/max */ /* for box: gid is box height */
 	int (*fn)(struct dialog_data *, struct dialog_item_data *);
 	struct history *history;
 	int dlen;
diff -urN links-2.3pre2-orig/listedit.c links-2.3pre2/listedit.c
--- links-2.3pre2-orig/listedit.c	2011-04-19 15:17:49.000000000 +0000
+++ links-2.3pre2/listedit.c	2011-05-13 09:04:16.272367616 +0000
@@ -734,7 +734,7 @@
 			TEXT(T_NO_ITEMS_SELECTED),  /* text */
 			NULL,  /* data */
 			1,  /* # of buttons */
-			TEXT(T_OK),NULL,B_ESC|B_ENTER  /* button1 */
+			TEXT(T_OK),NULL,BTN_ESC|BTN_ENTER  /* button1 */
 		);
 	else
 	{
@@ -916,8 +916,8 @@
 				TEXT(T_FOLDER)," \"",txt,"\" ",TEXT(T_NOT_EMPTY_SURE_DELETE),NULL,  /* text */
 				narez,  /* data for ld->delete_item */
 				2,  /* # of buttons */
-				TEXT(T_NO),NULL,B_ESC,  /* button1 */
-				TEXT(T_YES),delete_folder_recursively,B_ENTER  /* button2 */
+				TEXT(T_NO),NULL,BTN_ESC,  /* button1 */
+				TEXT(T_YES),delete_folder_recursively,BTN_ENTER  /* button2 */
 			);
 		else
 			msg_box(
@@ -928,8 +928,8 @@
 				TEXT(T_SURE_DELETE)," ",TEXT(T_fOLDER)," \"",txt,"\"?",NULL,  /* null-terminated text */
 				narez,  /* data for ld->delete_item */
 				2,  /* # of buttons */
-				TEXT(T_YES),delete_ok,B_ENTER,  /* button1 */
-				TEXT(T_NO),NULL,B_ESC  /* button2 */
+				TEXT(T_YES),delete_ok,BTN_ENTER,  /* button1 */
+				TEXT(T_NO),NULL,BTN_ESC  /* button2 */
 			);
 	}
 	else   /* item */
@@ -941,8 +941,8 @@
 			TEXT(T_SURE_DELETE)," ",TEXT(ld->item_description)," \"",txt,"\"?",NULL,  /* null-terminated text */
 			narez,  /* data for ld->delete_item */
 			2,  /* # of buttons */
-			TEXT(T_YES),delete_ok,B_ENTER,  /* button1 */
-			TEXT(T_NO),NULL,B_ESC  /* button2 */
+			TEXT(T_YES),delete_ok,BTN_ENTER,  /* button1 */
+			TEXT(T_NO),NULL,BTN_ESC  /* button2 */
 		);
 	return 0;
 }
@@ -1485,7 +1485,7 @@
 	struct session *ses=(struct session *)(dlg->dlg->udata);
 	struct list* item;
 
-	if (!ld->search_word) {msg_box(ses->term, NULL, TEXT(T_SEARCH), AL_CENTER, TEXT(T_NO_PREVIOUS_SEARCH), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC); return;}
+	if (!ld->search_word) {msg_box(ses->term, NULL, TEXT(T_SEARCH), AL_CENTER, TEXT(T_NO_PREVIOUS_SEARCH), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC); return;}
 	
 	if ((item=ld->find_item(ld->current_pos,ld->search_word,direction)))
 	{
@@ -1501,7 +1501,7 @@
 		if (!F) if (!ses->term->spec->block_cursor || ses->term->spec->braille) set_cursor(ses->term, dlg->x + DIALOG_LB, dlg->y+DIALOG_TB+ld->win_pos, dlg->x + DIALOG_LB, dlg->y+DIALOG_TB+ld->win_pos);
 	}
 	else 
-		msg_box(ses->term, NULL, TEXT(T_SEARCH), AL_CENTER, TEXT(T_SEARCH_STRING_NOT_FOUND), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		msg_box(ses->term, NULL, TEXT(T_SEARCH), AL_CENTER, TEXT(T_SEARCH_STRING_NOT_FOUND), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 	
 }
 
@@ -1739,7 +1739,7 @@
 
 		case EV_MOUSE:
 		/* toggle select item */
-		if ((ev->b&BM_ACT)==B_DOWN&&(ev->b&BM_BUTT)==B_RIGHT)
+		if ((ev->b&BM_ACT)==BTN_DOWN&&(ev->b&BM_BUTT)==BTN_RIGHT)
 		{
 			int n,a;
 			struct list *l=ld->win_offset;
@@ -1771,7 +1771,7 @@
 			return EVENT_PROCESSED;
 		}
 		/* click on item */
-		if ((ev->b&BM_ACT)==B_DOWN&&(ev->b&BM_BUTT)==B_LEFT)
+		if ((ev->b&BM_ACT)==BTN_DOWN&&(ev->b&BM_BUTT)==BTN_LEFT)
 		{
 			int n,a;
 			struct list *l=ld->win_offset;
@@ -1810,7 +1810,7 @@
 		}
 		/* scroll with the bar */
 #ifdef G
-		if (F&&((ev->b&BM_ACT)==B_DRAG&&(ev->b&BM_BUTT)==B_LEFT))
+		if (F&&((ev->b&BM_ACT)==BTN_DRAG&&(ev->b&BM_BUTT)==BTN_LEFT))
 		{
 			int total=get_total_items(ld);
 			int scroll_pos=get_scroll_pos(ld);
@@ -1854,7 +1854,7 @@
 
 		}
 #endif
-		if ((ev->b&BM_ACT)==B_DRAG&&(ev->b&BM_BUTT)==B_MIDDLE)
+		if ((ev->b&BM_ACT)==BTN_DRAG&&(ev->b&BM_BUTT)==BTN_MIDDLE)
 		{
 			long delta=(ev->y-last_mouse_y)/MOUSE_SCROLL_DIVIDER;
 
@@ -1891,12 +1891,12 @@
 
 		}
 		/* mouse wheel */
-		if ((ev->b&BM_ACT)==B_MOVE&&((ev->b&BM_BUTT)==B_WHEELUP||(ev->b&BM_BUTT)==B_WHEELDOWN||(ev->b&BM_BUTT)==B_WHEELDOWN1||(ev->b&BM_BUTT)==B_WHEELUP1))
+		if ((ev->b&BM_ACT)==BTN_MOVE&&((ev->b&BM_BUTT)==BTN_WHEELUP||(ev->b&BM_BUTT)==BTN_WHEELDOWN||(ev->b&BM_BUTT)==BTN_WHEELDOWN1||(ev->b&BM_BUTT)==BTN_WHEELUP1))
 		{
 			int button=(ev->b)&BM_BUTT;
 			last_mouse_y=ev->y;
 
-			if (button==B_WHEELDOWN||button==B_WHEELDOWN1)  /* scroll down */
+			if (button==BTN_WHEELDOWN||button==BTN_WHEELDOWN1)  /* scroll down */
 			{
 				if (next_in_tree(ld,ld->current_pos)==ld->list)return EVENT_PROCESSED;  /* already at the bottom */
 				ld->current_pos=next_in_tree(ld,ld->current_pos);
@@ -1910,7 +1910,7 @@
 				}
 				draw_to_window(dlg->win,redraw_list_line,&rd);
 			}
-			if (button==B_WHEELUP||button==B_WHEELUP1)  /* scroll up */
+			if (button==BTN_WHEELUP||button==BTN_WHEELUP1)  /* scroll up */
 			{
 				if (ld->current_pos==ld->list)return EVENT_PROCESSED;  /* already on the top */
 				ld->current_pos=prev_in_tree(ld,ld->current_pos);
@@ -2021,7 +2021,7 @@
 			TEXT(ld->already_in_use),
 			NULL,
 			1,
-			TEXT(T_OK),NULL,B_ENTER|B_ESC
+			TEXT(T_OK),NULL,BTN_ENTER|BTN_ESC
 		);
 		return 1;
 	}
@@ -2086,7 +2086,7 @@
 	d->items[a+4].fn=list_item_unselect;
 	
 	d->items[a+5].type=D_BUTTON;
-	d->items[a+5].gid=B_ESC;
+	d->items[a+5].gid=BTN_ESC;
 	d->items[a+5].fn=cancel_dialog;
 	d->items[a+5].text=TEXT(T_CLOSE);
 
diff -urN links-2.3pre2-orig/mailto.c links-2.3pre2/mailto.c
--- links-2.3pre2-orig/mailto.c	2011-04-19 15:17:49.000000000 +0000
+++ links-2.3pre2/mailto.c	2011-05-13 09:04:16.292814848 +0000
@@ -11,7 +11,7 @@
 {
 	unsigned char *prog, *cmd;
 	if (!(prog = get_prog(list)) || !*prog) {
-		msg_box(term, NULL, TEXT(T_NO_PROGRAM), AL_CENTER | AL_EXTD_TEXT, TEXT(T_NO_PROGRAM_SPECIFIED_FOR), " ", name, ".", NULL, NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		msg_box(term, NULL, TEXT(T_NO_PROGRAM), AL_CENTER | AL_EXTD_TEXT, TEXT(T_NO_PROGRAM_SPECIFIED_FOR), " ", name, ".", NULL, NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		return;
 	}
 	if ((cmd = subst_file(prog, param, 0))) {
@@ -38,7 +38,7 @@
 	fail1:
 	mem_free(user);
 	fail:
-	if (f) msg_box(ses->term, NULL, TEXT(T_BAD_URL_SYNTAX), AL_CENTER, TEXT(T_BAD_MAILTO_URL), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+	if (f) msg_box(ses->term, NULL, TEXT(T_BAD_URL_SYNTAX), AL_CENTER, TEXT(T_BAD_MAILTO_URL), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 }
 
 static void tn_func(struct session *ses, unsigned char *url, struct list_head *prog, unsigned char *t1, unsigned char *t2)
@@ -67,7 +67,7 @@
 	fail1:
 	mem_free(hh);
 	fail:
-	if (f) msg_box(ses->term, NULL, TEXT(T_BAD_URL_SYNTAX), AL_CENTER, t2, NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+	if (f) msg_box(ses->term, NULL, TEXT(T_BAD_URL_SYNTAX), AL_CENTER, t2, NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 }
 
 
@@ -91,7 +91,7 @@
 void mms_func(struct session *ses, unsigned char *url)
 {
 	if (check_shell_url(url)) {
-		msg_box(ses->term, NULL, TEXT(T_BAD_URL_SYNTAX), AL_CENTER, TEXT(T_MMS_URL_CONTAINS_INACCEPTABLE_CHARACTERS), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		msg_box(ses->term, NULL, TEXT(T_BAD_URL_SYNTAX), AL_CENTER, TEXT(T_MMS_URL_CONTAINS_INACCEPTABLE_CHARACTERS), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		return;
 	}
 	prog_func(ses->term, &mms_prog, url, TEXT(T_MMS));
diff -urN links-2.3pre2-orig/main.c links-2.3pre2/main.c
--- links-2.3pre2-orig/main.c	2011-04-19 15:17:49.000000000 +0000
+++ links-2.3pre2/main.c	2011-05-13 09:04:16.313262080 +0000
@@ -271,6 +271,7 @@
 
 void initialize_all_subsystems(void);
 void initialize_all_subsystems_2(void);
+extern void maybe_force_gr(void);
 
 static void init(void)
 {
@@ -288,6 +289,9 @@
 		retval = RET_FATAL;
 		goto ttt;
 	}
+#if defined(G) && defined(BEOS)
+	maybe_force_gr();
+#endif
 	if (!(u = parse_options(g_argc - 1, g_argv + 1))) {
 		retval = RET_SYNTAX;
 		goto ttt;
diff -urN links-2.3pre2-orig/menu.c links-2.3pre2/menu.c
--- links-2.3pre2-orig/menu.c	2011-04-19 15:17:49.000000000 +0000
+++ links-2.3pre2/menu.c	2011-05-13 09:19:13.692322304 +0000
@@ -17,17 +17,17 @@
 
 static void menu_about(struct terminal *term, void *d, struct session *ses)
 {
-	msg_box(term, NULL, TEXT(T_ABOUT), AL_CENTER, TEXT(T_LINKS__LYNX_LIKE), NULL, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+	msg_box(term, NULL, TEXT(T_ABOUT), AL_CENTER, TEXT(T_LINKS__LYNX_LIKE), NULL, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 }
 
 static void menu_keys(struct terminal *term, void *d, struct session *ses)
 {
-	msg_box(term, NULL, TEXT(T_KEYS), AL_LEFT | AL_MONO, TEXT(T_KEYS_DESC), NULL, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+	msg_box(term, NULL, TEXT(T_KEYS), AL_LEFT | AL_MONO, TEXT(T_KEYS_DESC), NULL, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 }
 
 static void menu_copying(struct terminal *term, void *d, struct session *ses)
 {
-	msg_box(term, NULL, TEXT(T_COPYING), AL_CENTER, TEXT(T_COPYING_DESC), NULL, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+	msg_box(term, NULL, TEXT(T_COPYING), AL_CENTER, TEXT(T_COPYING_DESC), NULL, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 }
 
 static void menu_manual(struct terminal *term, void *d, struct session *ses)
@@ -88,7 +88,7 @@
 void query_exit(struct session *ses)
 {
 	ses->exit_query = 1;
-	msg_box(ses->term, NULL, TEXT(T_EXIT_LINKS), AL_CENTER, (ses->term->next == ses->term->prev && are_there_downloads()) ? TEXT(T_DO_YOU_REALLY_WANT_TO_EXIT_LINKS_AND_TERMINATE_ALL_DOWNLOADS) : (!F || ses->term->next == ses->term->prev) ? TEXT(T_DO_YOU_REALLY_WANT_TO_EXIT_LINKS) : TEXT(T_DO_YOU_REALLY_WANT_TO_CLOSE_WINDOW), ses, 2, TEXT(T_YES), (void (*)(void *))really_exit_prog, B_ENTER, TEXT(T_NO), dont_exit_prog, B_ESC);
+	msg_box(ses->term, NULL, TEXT(T_EXIT_LINKS), AL_CENTER, (ses->term->next == ses->term->prev && are_there_downloads()) ? TEXT(T_DO_YOU_REALLY_WANT_TO_EXIT_LINKS_AND_TERMINATE_ALL_DOWNLOADS) : (!F || ses->term->next == ses->term->prev) ? TEXT(T_DO_YOU_REALLY_WANT_TO_EXIT_LINKS) : TEXT(T_DO_YOU_REALLY_WANT_TO_CLOSE_WINDOW), ses, 2, TEXT(T_YES), (void (*)(void *))really_exit_prog, BTN_ENTER, TEXT(T_NO), dont_exit_prog, BTN_ESC);
 }
 
 void exit_prog(struct terminal *term, void *d, struct session *ses)
@@ -215,7 +215,7 @@
 	l = 0, a15 = init_str(); add_to_str(&a15, &l, ", "); add_num_to_str(&a15, &l, formatted_info(CI_LOCKED));add_to_str(&a15, &l, " ");
 	l = 0, a16 = init_str(); add_to_str(&a16, &l, ".");
 
-	if (!F) msg_box(term, getml(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, NULL), TEXT(T_RESOURCES), AL_LEFT | AL_EXTD_TEXT, TEXT(T_RESOURCES), a1, TEXT(T_HANDLES), a2, TEXT(T_TIMERS), a3, TEXT(T_CONNECTIONS), a4, TEXT(T_cONNECTIONS), a5, TEXT(T_CONNECTING), a6, TEXT(T_tRANSFERRING), a7, TEXT(T_KEEPALIVE), a8, TEXT(T_MEMORY_CACHE), a9, TEXT(T_BYTES), a10, TEXT(T_FILES), a11, TEXT(T_LOCKED), a12, TEXT(T_LOADING), a13, TEXT(T_FORMATTED_DOCUMENT_CACHE), a14, TEXT(T_DOCUMENTS), a15, TEXT(T_LOCKED), a16, NULL, r, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+	if (!F) msg_box(term, getml(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, NULL), TEXT(T_RESOURCES), AL_LEFT | AL_EXTD_TEXT, TEXT(T_RESOURCES), a1, TEXT(T_HANDLES), a2, TEXT(T_TIMERS), a3, TEXT(T_CONNECTIONS), a4, TEXT(T_cONNECTIONS), a5, TEXT(T_CONNECTING), a6, TEXT(T_tRANSFERRING), a7, TEXT(T_KEEPALIVE), a8, TEXT(T_MEMORY_CACHE), a9, TEXT(T_BYTES), a10, TEXT(T_FILES), a11, TEXT(T_LOCKED), a12, TEXT(T_LOADING), a13, TEXT(T_FORMATTED_DOCUMENT_CACHE), a14, TEXT(T_DOCUMENTS), a15, TEXT(T_LOCKED), a16, NULL, r, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 #ifdef G
 	else msg_box(term, getml(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
 				a12, a13, b14, b15, b16, b17, a14, a15, a16,
@@ -230,7 +230,7 @@
 			TEXT(T_BYTES), b15, TEXT(T_IMAGES), b16, TEXT(T_LOCKED),
 			b17, TEXT(T_FONT_CACHE), c14, TEXT(T_BYTES), c15,
 			TEXT(T_BYTES_MAX), c16, TEXT(T_LETTERS), c17,
-			TEXT(T_FORMATTED_DOCUMENT_CACHE), a14, TEXT(T_DOCUMENTS), a15, TEXT(T_LOCKED), a16, NULL, r, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+			TEXT(T_FORMATTED_DOCUMENT_CACHE), a14, TEXT(T_DOCUMENTS), a15, TEXT(T_LOCKED), a16, NULL, r, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 #endif
 	r->win = term->windows.next;
 	((struct dialog_data *)r->win->data)->dlg->abort = refresh_abort;
@@ -259,7 +259,7 @@
 		add_to_str(&a, &l, "\n");
 		add_to_str(&a, &l, ce->url);
 	}
-	msg_box(term, getml(a, NULL), TEXT(T_CACHE_INFO), AL_LEFT | AL_EXTD_TEXT, TEXT(T_CACHE_CONTENT), a, NULL, r, 1, TEXT(T_OK), end_refresh, B_ENTER | B_ESC);
+	msg_box(term, getml(a, NULL), TEXT(T_CACHE_INFO), AL_LEFT | AL_EXTD_TEXT, TEXT(T_CACHE_CONTENT), a, NULL, r, 1, TEXT(T_OK), end_refresh, BTN_ENTER | BTN_ESC);
 	r->win = term->windows.next;
 	r->timer = install_timer(RESOURCE_INFO_REFRESH, (void (*)(void *))refresh, r);
 	/* !!! the refresh here is buggy */
@@ -311,7 +311,7 @@
 	}
 #endif
 	p = stracpy(message);
-	msg_box(term, getml(p, NULL), TEXT(T_MEMORY_INFO), AL_CENTER, p, r, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+	msg_box(term, getml(p, NULL), TEXT(T_MEMORY_INFO), AL_CENTER, p, r, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 	r->win = term->windows.next;
 	((struct dialog_data *)r->win->data)->dlg->abort = refresh_abort;
 	r->timer = install_timer(RESOURCE_INFO_REFRESH, (void (*)(void *))refresh, r);
@@ -526,11 +526,11 @@
 	d->items[9].dlen = sizeof(int);
 	d->items[9].data = (void *)&ts->braille;
 	d->items[10].type = D_BUTTON;
-	d->items[10].gid = B_ENTER;
+	d->items[10].gid = BTN_ENTER;
 	d->items[10].fn = ok_dialog;
 	d->items[10].text = TEXT(T_OK);
 	d->items[11].type = D_BUTTON;
-	d->items[11].gid = B_ESC;
+	d->items[11].gid = BTN_ESC;
 	d->items[11].fn = cancel_dialog;
 	d->items[11].text = TEXT(T_CANCEL);
 	d->items[12].type = D_END;
@@ -637,11 +637,11 @@
 	d->items[8].gid = 1024;
 	d->items[8].gnum = 30*1024;
 	d->items[9].type = D_BUTTON;
-	d->items[9].gid = B_ENTER;
+	d->items[9].gid = BTN_ENTER;
 	d->items[9].fn = ok_dialog;
 	d->items[9].text = TEXT(T_OK);
 	d->items[10].type = D_BUTTON;
-	d->items[10].gid = B_ESC;
+	d->items[10].gid = BTN_ESC;
 	d->items[10].fn = cancel_dialog;
 	d->items[10].text = TEXT(T_CANCEL);
 	d->items[11].type = D_END;
@@ -742,11 +742,11 @@
 	d->items[7].dlen = MAX_STR_LEN;
 	d->items[7].data = header->extra_header;
 	d->items[8].type = D_BUTTON;
-	d->items[8].gid = B_ENTER;
+	d->items[8].gid = BTN_ENTER;
 	d->items[8].fn = ok_dialog;
 	d->items[8].text = TEXT(T_OK);
 	d->items[9].type = D_BUTTON;
-	d->items[9].gid = B_ESC;
+	d->items[9].gid = BTN_ESC;
 	d->items[9].fn = cancel_dialog;
 	d->items[9].text = TEXT(T_CANCEL);
 	d->items[10].type = D_END;
@@ -798,11 +798,11 @@
 	d->items[7].data = (void *)&options->header;
 	d->items[7].dlen = sizeof(struct http_header_options);
 	d->items[8].type = D_BUTTON;
-	d->items[8].gid = B_ENTER;
+	d->items[8].gid = BTN_ENTER;
 	d->items[8].fn = ok_dialog;
 	d->items[8].text = TEXT(T_OK);
 	d->items[9].type = D_BUTTON;
-	d->items[9].gid = B_ESC;
+	d->items[9].gid = BTN_ESC;
 	d->items[9].fn = cancel_dialog;
 	d->items[9].text = TEXT(T_CANCEL);
 	d->items[10].type = D_END;
@@ -877,12 +877,12 @@
 	a = 3;
 #endif
 	d->items[a].type = D_BUTTON;
-	d->items[a].gid = B_ENTER;
+	d->items[a].gid = BTN_ENTER;
 	d->items[a].fn = ok_dialog;
 	d->items[a].text = TEXT(T_OK);
 	a++;
 	d->items[a].type = D_BUTTON;
-	d->items[a].gid = B_ESC;
+	d->items[a].gid = BTN_ESC;
 	d->items[a].fn = cancel_dialog;
 	d->items[a].text = TEXT(T_CANCEL);
 	a++;
@@ -1100,11 +1100,11 @@
 	d->items[13].dlen = sizeof(int);
 	d->items[13].data = (void *)&gamma_bits;
 	d->items[14].type = D_BUTTON;
-	d->items[14].gid = B_ENTER;
+	d->items[14].gid = BTN_ENTER;
 	d->items[14].fn = ok_dialog;
 	d->items[14].text = TEXT(T_OK);
 	d->items[15].type = D_BUTTON;
-	d->items[15].gid = B_ESC;
+	d->items[15].gid = BTN_ESC;
 	d->items[15].fn = cancel_dialog;
 	d->items[15].text = TEXT(T_CANCEL);
 	d->items[16].type = D_END;
@@ -1226,11 +1226,11 @@
 	d->items[4].data = (unsigned char *)&p->only_proxies;
 	d->items[4].dlen = sizeof(int);
 	d->items[5].type = D_BUTTON;
-	d->items[5].gid = B_ENTER;
+	d->items[5].gid = BTN_ENTER;
 	d->items[5].fn = ok_dialog;
 	d->items[5].text = TEXT(T_OK);
 	d->items[6].type = D_BUTTON;
-	d->items[6].gid = B_ESC;
+	d->items[6].gid = BTN_ESC;
 	d->items[6].fn = cancel_dialog;
 	d->items[6].text = TEXT(T_CANCEL);
 	d->items[7].type = D_END;
@@ -1319,11 +1319,11 @@
 	d->items[9].data = (unsigned char *)&ftp_options;
 	d->items[9].dlen = sizeof(struct ftp_options);
 	d->items[10].type = D_BUTTON;
-	d->items[10].gid = B_ENTER;
+	d->items[10].gid = BTN_ENTER;
 	d->items[10].fn = ok_dialog;
 	d->items[10].text = TEXT(T_OK);
 	d->items[11].type = D_BUTTON;
-	d->items[11].gid = B_ESC;
+	d->items[11].gid = BTN_ESC;
 	d->items[11].fn = cancel_dialog;
 	d->items[11].text = TEXT(T_CANCEL);
 	d->items[12].type = D_END;
@@ -1469,11 +1469,11 @@
 	}
 #endif
 	d->items[a].type = D_BUTTON;
-	d->items[a].gid = B_ENTER;
+	d->items[a].gid = BTN_ENTER;
 	d->items[a].fn = ok_dialog;
 	d->items[a++].text = TEXT(T_OK);
 	d->items[a].type = D_BUTTON;
-	d->items[a].gid = B_ESC;
+	d->items[a].gid = BTN_ESC;
 	d->items[a].fn = cancel_dialog;
 	d->items[a++].text = TEXT(T_CANCEL);
 	d->items[a].type = D_END;
@@ -1486,7 +1486,7 @@
 		net_options(term, xxx, yyy);
 		return;
 	}
-	msg_box(term, NULL, _("Network options"), AL_CENTER, _("Warning: configuring network will terminate all running downloads. Do you really want to configure network?"), term, 2, _("Yes"), (void (*)(void *))net_options, B_ENTER, _("No"), NULL, B_ESC);
+	msg_box(term, NULL, _("Network options"), AL_CENTER, _("Warning: configuring network will terminate all running downloads. Do you really want to configure network?"), term, 2, _("Yes"), (void (*)(void *))net_options, BTN_ENTER, _("No"), NULL, BTN_ESC);
 }*/
 
 static unsigned char mc_str[8];
@@ -1568,12 +1568,12 @@
 	d->items[a].data = (void *)&aggressive_cache;
 	a++;
 	d->items[a].type = D_BUTTON;
-	d->items[a].gid = B_ENTER;
+	d->items[a].gid = BTN_ENTER;
 	d->items[a].fn = ok_dialog;
 	d->items[a].text = TEXT(T_OK);
 	a++;
 	d->items[a].type = D_BUTTON;
-	d->items[a].gid = B_ESC;
+	d->items[a].gid = BTN_ESC;
 	d->items[a].fn = cancel_dialog;
 	d->items[a].text = TEXT(T_CANCEL);
 	a++;
@@ -1733,12 +1733,12 @@
 	a++;
 	if (!F){
 		d->items[a].type = D_BUTTON;
-		d->items[a].gid = B_ENTER;
+		d->items[a].gid = BTN_ENTER;
 		d->items[a].fn = ok_dialog;
 		d->items[a].text = TEXT(T_OK);
 		a++;
 		d->items[a].type = D_BUTTON;
-		d->items[a].gid = B_ESC;
+		d->items[a].gid = BTN_ESC;
 		d->items[a].fn = cancel_dialog;
 		d->items[a].text = TEXT(T_CANCEL);
 		a++;
@@ -1764,12 +1764,12 @@
 		d->items[a].dlen = sizeof(int);
 		a++;
 		d->items[a].type = D_BUTTON;
-		d->items[a].gid = B_ENTER;
+		d->items[a].gid = BTN_ENTER;
 		d->items[a].fn = ok_dialog;
 		d->items[a].text = TEXT(T_OK);
 		a++;
 		d->items[a].type = D_BUTTON;
-		d->items[a].gid = B_ESC;
+		d->items[a].gid = BTN_ESC;
 		d->items[a].fn = cancel_dialog;
 		d->items[a].text = TEXT(T_CANCEL);
 		a++;
@@ -2025,12 +2025,12 @@
 		}
 #endif
 	d->items[a].type = D_BUTTON;
-	d->items[a].gid = B_ENTER;
+	d->items[a].gid = BTN_ENTER;
 	d->items[a].fn = ok_dialog;
 	d->items[a].text = TEXT(T_OK);
 	a++;
 	d->items[a].type = D_BUTTON;
-	d->items[a].gid = B_ESC;
+	d->items[a].gid = BTN_ESC;
 	d->items[a].fn = cancel_dialog;
 	d->items[a].text = TEXT(T_CANCEL);
 	a++;
@@ -2098,11 +2098,11 @@
 	d->items[1].gid = 1;
 	d->items[1].gnum = 999;
 	d->items[2].type = D_BUTTON;
-	d->items[2].gid = B_ENTER;
+	d->items[2].gid = BTN_ENTER;
 	d->items[2].fn = ok_dialog;
 	d->items[2].text = TEXT(T_OK);
 	d->items[3].type = D_BUTTON;
-	d->items[3].gid = B_ESC;
+	d->items[3].gid = BTN_ESC;
 	d->items[3].fn = cancel_dialog;
 	d->items[3].text = TEXT(T_CANCEL);
 	d->items[4].type = D_END;
@@ -2495,8 +2495,8 @@
 			TEXT(T_FILE), " ", h->file, " ", TEXT(T_ALREADY_EXISTS_AS_DOWNLOAD), " ", TEXT(T_DO_YOU_WISH_TO_OVERWRITE), NULL,
 			h,
 			3,
-			TEXT(T_OVERWRITE), does_file_exist_ok, B_ENTER,
-			TEXT(T_CANCEL), does_file_exist_cancel, B_ESC,
+			TEXT(T_OVERWRITE), does_file_exist_ok, BTN_ENTER,
+			TEXT(T_CANCEL), does_file_exist_cancel, BTN_ESC,
 			TEXT(T_RENAME), does_file_exist_rename, NULL
 		);
 		return;
@@ -2525,8 +2525,8 @@
 		TEXT(T_FILE), " ", h->file, " ", TEXT(T_ALREADY_EXISTS), " ", TEXT(T_DO_YOU_WISH_TO_OVERWRITE), NULL,
 		h,
 		3,
-		TEXT(T_OVERWRITE), does_file_exist_ok, B_ENTER,
-		TEXT(T_CANCEL), does_file_exist_cancel, B_ESC,
+		TEXT(T_OVERWRITE), does_file_exist_ok, BTN_ENTER,
+		TEXT(T_CANCEL), does_file_exist_cancel, BTN_ESC,
 		TEXT(T_RENAME), does_file_exist_rename, NULL
 	);
 }
diff -urN links-2.3pre2-orig/objreq.c links-2.3pre2/objreq.c
--- links-2.3pre2-orig/objreq.c	2011-04-19 15:17:49.000000000 +0000
+++ links-2.3pre2/objreq.c	2011-05-13 09:04:16.414711808 +0000
@@ -163,12 +163,12 @@
 	d->items[1].data = a->passwd;
 
 	d->items[2].type = D_BUTTON;
-	d->items[2].gid = B_ENTER;
+	d->items[2].gid = BTN_ENTER;
 	d->items[2].fn = auth_ok;
 	d->items[2].text = TEXT(T_OK);
 
 	d->items[3].type = D_BUTTON;
-	d->items[3].gid = B_ESC;
+	d->items[3].gid = BTN_ESC;
 	d->items[3].fn = auth_cancel;
 	d->items[3].text = TEXT(T_CANCEL);
 
diff -urN links-2.3pre2-orig/os_dep.c links-2.3pre2/os_dep.c
--- links-2.3pre2-orig/os_dep.c	2011-04-19 15:17:49.000000000 +0000
+++ links-2.3pre2/os_dep.c	2011-05-13 09:04:16.451674112 +0000
@@ -1059,7 +1059,7 @@
 
 #if defined(BEOS)
 
-#include <be/kernel/OS.h>
+#include <kernel/OS.h>
 
 int thr_sem_init = 0;
 sem_id thr_sem;
@@ -1251,16 +1251,16 @@
 		ev.x = ms->col;
 		ev.y = ms->row;
 		/*debug("status: %d %d %d", ms->col, ms->row, ms->fs);*/
-		if (ms->fs & (MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN)) ev.b = status = B_DOWN | (ms->fs & MOUSE_BN1_DOWN ? B_LEFT : ms->fs & MOUSE_BN2_DOWN ? B_MIDDLE : B_RIGHT);
+		if (ms->fs & (MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN)) ev.b = status = BTN_DOWN | (ms->fs & MOUSE_BN1_DOWN ? BTN_LEFT : ms->fs & MOUSE_BN2_DOWN ? BTN_MIDDLE : BTN_RIGHT);
 		else if (ms->fs & (MOUSE_MOTION_WITH_BN1_DOWN | MOUSE_MOTION_WITH_BN2_DOWN | MOUSE_MOTION_WITH_BN3_DOWN)) {
-			int b = ms->fs & MOUSE_MOTION_WITH_BN1_DOWN ? B_LEFT : ms->fs & MOUSE_MOTION_WITH_BN2_DOWN ? B_MIDDLE : B_RIGHT;
-			if (status == -1) b |= B_DOWN;
-			else b |= B_DRAG;
+			int b = ms->fs & MOUSE_MOTION_WITH_BN1_DOWN ? BTN_LEFT : ms->fs & MOUSE_MOTION_WITH_BN2_DOWN ? BTN_MIDDLE : BTN_RIGHT;
+			if (status == -1) b |= BTN_DOWN;
+			else b |= BTN_DRAG;
 			ev.b = status = b;
 		}
 		else {
 			if (status == -1) continue;
-			ev.b = (status & BM_BUTT) | B_UP;
+			ev.b = (status & BM_BUTT) | BTN_UP;
 			status = -1;
 		}
 		if (hard_write(oms->p[1], (unsigned char *)&ev, sizeof(struct event)) != sizeof(struct event)) break;
@@ -1634,13 +1634,13 @@
 	ev.y = gev.y - 1;
 	if (ev.x < 0) ev.x = 0;
 	if (ev.y < 0) ev.y = 0;
-	if (gev.buttons & GPM_B_LEFT) ev.b = B_LEFT;
-	else if (gev.buttons & GPM_B_MIDDLE) ev.b = B_MIDDLE;
-	else if (gev.buttons & GPM_B_RIGHT) ev.b = B_RIGHT;
+	if (gev.buttons & GPM_B_LEFT) ev.b = BTN_LEFT;
+	else if (gev.buttons & GPM_B_MIDDLE) ev.b = BTN_MIDDLE;
+	else if (gev.buttons & GPM_B_RIGHT) ev.b = BTN_RIGHT;
 	else return;
-	if (gev.type & GPM_DOWN) ev.b |= B_DOWN;
-	else if (gev.type & GPM_UP) ev.b |= B_UP;
-	else if (gev.type & GPM_DRAG) ev.b |= B_DRAG;
+	if (gev.type & GPM_DOWN) ev.b |= BTN_DOWN;
+	else if (gev.type & GPM_UP) ev.b |= BTN_UP;
+	else if (gev.type & GPM_DRAG) ev.b |= BTN_DRAG;
 	else return;
 	gms->fn(gms->data, (char *)&ev, sizeof(struct event));
 }
diff -urN links-2.3pre2-orig/os_dep.h links-2.3pre2/os_dep.h
--- links-2.3pre2-orig/os_dep.h	2007-12-26 03:13:05.000000000 +0000
+++ links-2.3pre2/os_dep.h	2011-05-13 09:34:37.000000000 +0000
@@ -20,7 +20,7 @@
 #define OS2
 #elif defined(_WIN32) || defined(__CYGWIN__)
 #define WIN32
-#elif defined(__BEOS__)
+#elif defined(__BEOS__) || defined(__HAIKU__)
 #define BEOS
 #elif defined(__riscos__)
 #define RISCOS
@@ -111,11 +111,15 @@
 #define SHARED_CONFIG_DIR "/etc/"
 #define NO_FORK_ON_EXIT
 #define ASSOC_BLOCK
+#define SET_WINDOW_TITLE_UTF_8
 
 #include <sys/time.h>
 #include <sys/types.h>
-#include <net/socket.h>
+#include <sys/socket.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 int be_socket(int, int, int);
 int be_connect(int, struct sockaddr *, int);
 int be_getpeername(int, struct sockaddr *, int *);
@@ -129,6 +133,9 @@
 int be_close(int);
 int be_select(int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *);
 int be_getsockopt(int, int, int, void *, int *);
+#ifdef __cplusplus
+}
+#endif
 
 #elif defined(RISCOS)
 
diff -urN links-2.3pre2-orig/os_depx.h links-2.3pre2/os_depx.h
--- links-2.3pre2-orig/os_depx.h	2007-07-07 02:55:24.000000000 +0000
+++ links-2.3pre2/os_depx.h	2011-05-13 09:04:16.484966400 +0000
@@ -45,6 +45,8 @@
 #endif
 
 #ifdef BEOS
+#if IPPROTO_TCP != 6
+/* net_server */
 #define socket be_socket
 #define connect be_connect
 #define getpeername be_getpeername
@@ -58,16 +60,22 @@
 #define close be_close
 #define select be_select
 #define getsockopt be_getsockopt
+/*
+#ifdef errno
+#undef errno
+#endif
+#define errno 1
+*/
+#endif
 #ifndef PF_INET
 #define PF_INET AF_INET
 #endif
 #ifndef SO_ERROR
 #define SO_ERROR	10001
 #endif
-#ifdef errno
-#undef errno
+#ifndef FDSETSIZE
+#define FDSETSIZE FD_SETSIZE
 #endif
-#define errno 1
 #endif
 
 #if defined(O_SIZE) && defined(__EMX__)
@@ -83,6 +91,9 @@
 #elif defined(GRDRV_ATHEOS)
 #define loop_select ath_select
 int ath_select(int n, fd_set *r, fd_set *w, fd_set *e, struct timeval *t);
+#elif defined(GRDRV_BEOS)
+#define loop_select be_loop_select
+int be_loop_select(int n, fd_set *r, fd_set *w, fd_set *e, struct timeval *t);
 #else
 #define loop_select select
 #endif
diff -urN links-2.3pre2-orig/pmshell.c links-2.3pre2/pmshell.c
--- links-2.3pre2-orig/pmshell.c	2011-04-19 15:17:49.000000000 +0000
+++ links-2.3pre2/pmshell.c	2011-05-13 09:04:16.524025856 +0000
@@ -287,33 +287,33 @@
 		case WM_BUTTON1DOWN:
 			pm_lock;
 			if (!(win = pm_lookup_window(hwnd))) { pm_unlock; break; }
-			win->button |= 1 << B_LEFT;
+			win->button |= 1 << BTN_LEFT;
 			win->lastpos = (unsigned)mp1;
-			pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), B_DOWN | B_LEFT, 0);
+			pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), BTN_DOWN | BTN_LEFT, 0);
 			pm_unlock;
 			break;
 		case WM_BUTTON2DOWN:
 			pm_lock;
 			if (!(win = pm_lookup_window(hwnd))) { pm_unlock; break; }
-			win->button |= 1 << B_RIGHT;
+			win->button |= 1 << BTN_RIGHT;
 			win->lastpos = (unsigned)mp1;
-			pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), B_DOWN | B_RIGHT, 0);
+			pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), BTN_DOWN | BTN_RIGHT, 0);
 			pm_unlock;
 			break;
 		case WM_BUTTON3DOWN:
 			pm_lock;
 			if (!(win = pm_lookup_window(hwnd))) { pm_unlock; break; }
-			win->button |= 1 << B_MIDDLE;
+			win->button |= 1 << BTN_MIDDLE;
 			win->lastpos = (unsigned)mp1;
-			pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), B_DOWN | B_MIDDLE, 0);
+			pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), BTN_DOWN | BTN_MIDDLE, 0);
 			pm_unlock;
 			break;
 		case WM_BUTTON1UP:
 		case WM_BUTTON1MOTIONEND:
 			pm_lock;
 			if (!(win = pm_lookup_window(hwnd))) { pm_unlock; break; }
-			if (win->button & (1 << B_LEFT)) pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), B_UP | B_LEFT, 0);
-			win->button &= ~(1 << B_LEFT);
+			if (win->button & (1 << BTN_LEFT)) pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), BTN_UP | BTN_LEFT, 0);
+			win->button &= ~(1 << BTN_LEFT);
 			win->lastpos = (unsigned)mp1;
 			pm_unlock;
 			break;
@@ -321,8 +321,8 @@
 		case WM_BUTTON2MOTIONEND:
 			pm_lock;
 			if (!(win = pm_lookup_window(hwnd))) { pm_unlock; break; }
-			if (win->button & (1 << B_RIGHT)) pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), B_UP | B_RIGHT, 0);
-			win->button &= ~(1 << B_RIGHT);
+			if (win->button & (1 << BTN_RIGHT)) pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), BTN_UP | BTN_RIGHT, 0);
+			win->button &= ~(1 << BTN_RIGHT);
 			win->lastpos = (unsigned)mp1;
 			pm_unlock;
 			break;
@@ -330,8 +330,8 @@
 		case WM_BUTTON3MOTIONEND:
 			pm_lock;
 			if (!(win = pm_lookup_window(hwnd))) { pm_unlock; break; }
-			if (win->button & (1 << B_MIDDLE)) pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), B_UP | B_MIDDLE, 0);
-			win->button &= ~(1 << B_MIDDLE);
+			if (win->button & (1 << BTN_MIDDLE)) pm_send_event(win, E_MOUSE, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), BTN_UP | BTN_MIDDLE, 0);
+			win->button &= ~(1 << BTN_MIDDLE);
 			win->lastpos = (unsigned)mp1;
 			pm_unlock;
 			break;
@@ -340,19 +340,19 @@
 			if (!(win = pm_lookup_window(hwnd))) { pm_unlock; break; }
 			if (win->lastpos == (unsigned)mp1) { pm_unlock; break; }
 			win->lastpos = (unsigned)mp1;
-			pm_send_mouse_event(win, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), (win->button ? B_DRAG : B_MOVE) | (win->button & (1 << B_LEFT) ? B_LEFT : win->button & (1 << B_MIDDLE) ? B_MIDDLE : win->button & (1 << B_RIGHT) ? B_RIGHT : 0));
+			pm_send_mouse_event(win, (unsigned)mp1 & 0xffff, win->y - ((unsigned)mp1 >> 16), (win->button ? BTN_DRAG : BTN_MOVE) | (win->button & (1 << BTN_LEFT) ? BTN_LEFT : win->button & (1 << BTN_MIDDLE) ? BTN_MIDDLE : win->button & (1 << BTN_RIGHT) ? BTN_RIGHT : 0));
 			pm_unlock;
 			break;
 		case WM_VSCROLL:
 			pm_lock;
 			if (!(win = pm_lookup_window(hwnd))) { pm_unlock; break; }
-			if ((unsigned)mp2 == SB_LINEUP << 16 || (unsigned)mp2 == SB_LINEDOWN << 16) pm_send_event(win, E_MOUSE, win->lastpos & 0xffff, win->y - (win->lastpos >> 16), ((unsigned)mp2 == SB_LINEUP << 16 ? B_WHEELUP1 : B_WHEELDOWN1) | B_MOVE, 0);
+			if ((unsigned)mp2 == SB_LINEUP << 16 || (unsigned)mp2 == SB_LINEDOWN << 16) pm_send_event(win, E_MOUSE, win->lastpos & 0xffff, win->y - (win->lastpos >> 16), ((unsigned)mp2 == SB_LINEUP << 16 ? BTN_WHEELUP1 : BTN_WHEELDOWN1) | BTN_MOVE, 0);
 			pm_unlock;
 			break;
 		case WM_HSCROLL:
 			pm_lock;
 			if (!(win = pm_lookup_window(hwnd))) { pm_unlock; break; }
-			if ((unsigned)mp2 == SB_LINELEFT << 16 || (unsigned)mp2 == SB_LINERIGHT << 16) pm_send_event(win, E_MOUSE, win->lastpos & 0xffff, win->y - (win->lastpos >> 16), ((unsigned)mp2 == SB_LINELEFT << 16 ? B_WHEELLEFT1 : B_WHEELRIGHT1) | B_MOVE, 0);
+			if ((unsigned)mp2 == SB_LINELEFT << 16 || (unsigned)mp2 == SB_LINERIGHT << 16) pm_send_event(win, E_MOUSE, win->lastpos & 0xffff, win->y - (win->lastpos >> 16), ((unsigned)mp2 == SB_LINELEFT << 16 ? BTN_WHEELLEFT1 : BTN_WHEELRIGHT1) | BTN_MOVE, 0);
 			pm_unlock;
 			break;
 	}
diff -urN links-2.3pre2-orig/session.c links-2.3pre2/session.c
--- links-2.3pre2-orig/session.c	2011-04-19 15:17:50.000000000 +0000
+++ links-2.3pre2/session.c	2011-05-13 09:04:16.556269568 +0000
@@ -195,7 +195,7 @@
 	unsigned char *u = stracpy(title);
 	if (strchr(u, POST_CHAR)) *strchr(u, POST_CHAR) = 0;
 	if (!t) return;
-	msg_box(ses->term, getml(u, NULL), TEXT(T_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_ERROR_LOADING), " ", u, ":\n\n", t, NULL, ses, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC/*, _("Retry"), NULL, 0 !!! FIXME: retry */);
+	msg_box(ses->term, getml(u, NULL), TEXT(T_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_ERROR_LOADING), " ", u, ":\n\n", t, NULL, ses, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC/*, _("Retry"), NULL, 0 !!! FIXME: retry */);
 }
 
 static inline unsigned char hx(int a)
@@ -477,7 +477,7 @@
 	dlg->udata = down;
 	dlg->align = AL_CENTER;
 	dlg->items[0].type = D_BUTTON;
-	dlg->items[0].gid = B_ENTER | B_ESC;
+	dlg->items[0].gid = BTN_ENTER | BTN_ESC;
 	dlg->items[0].fn = dlg_undisplay_download;
 	dlg->items[0].text = TEXT(T_BACKGROUND);
 	dlg->items[1].type = D_BUTTON;
@@ -625,7 +625,7 @@
 		if (get_download_ses(down)) {
 			unsigned char *emsg = stracpy(errno ? strerror(errno) : "Zero returned");
 			unsigned char *msg = stracpy(down->file);
-			msg_box(get_download_ses(down)->term, getml(msg, emsg, NULL), TEXT(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_COULD_NOT_WRITE_TO_FILE), " ", msg, ": ", emsg, NULL, NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+			msg_box(get_download_ses(down)->term, getml(msg, emsg, NULL), TEXT(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_COULD_NOT_WRITE_TO_FILE), " ", msg, ": ", emsg, NULL, NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		}
 		return -1;
 	}
@@ -715,7 +715,7 @@
 			if (t) {
 				unsigned char *tt = stracpy(down->url);
 				if (strchr(tt, POST_CHAR)) *strchr(tt, POST_CHAR) = 0;
-				msg_box(get_download_ses(down)->term, getml(tt, NULL), TEXT(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_ERROR_DOWNLOADING), " ", tt, ":\n\n", t, NULL, get_download_ses(down), 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC/*, TEXT(T_RETRY), NULL, 0 !!! FIXME: retry */);
+				msg_box(get_download_ses(down)->term, getml(tt, NULL), TEXT(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_ERROR_DOWNLOADING), " ", tt, ":\n\n", t, NULL, get_download_ses(down), 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC/*, TEXT(T_RETRY), NULL, 0 !!! FIXME: retry */);
 			}
 		} else {
 			if (down->prog) {
@@ -792,7 +792,7 @@
 		if (!ses) goto x;
 		msg = stracpy(file);
 		msge = stracpy(strerror(errno));
-		msg_box(ses->term, getml(msg, msge, NULL), TEXT(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_COULD_NOT_CREATE_FILE), " ", msg, ": ", msge, NULL, NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+		msg_box(ses->term, getml(msg, msge, NULL), TEXT(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_COULD_NOT_CREATE_FILE), " ", msg, ": ", msge, NULL, NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		goto x;
 	}
 	set_bin(h);
@@ -1545,7 +1545,7 @@
 	}
 	u = stracpy(ce->url);
 	if ((uu = strchr(u, POST_CHAR))) *uu = 0;
-	msg_box(term, getml(u, NULL), TEXT(T_DECOMPRESSION_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_ERROR_DECOMPRESSING_), u, TEXT(T__wITH_), lib, ": ", msg, NULL, NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+	msg_box(term, getml(u, NULL), TEXT(T_DECOMPRESSION_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_ERROR_DECOMPRESSING_), u, TEXT(T__wITH_), lib, ": ", msg, NULL, NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 }
 #endif
 
@@ -2196,7 +2196,7 @@
 				mem_free(file);
 				goto new_name;
 			}
-			msg_box(ses->term, NULL, TEXT(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_COULD_NOT_CREATE_TEMPORARY_FILE), NULL, NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+			msg_box(ses->term, NULL, TEXT(T_DOWNLOAD_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_COULD_NOT_CREATE_TEMPORARY_FILE), NULL, NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 		}
 		if (ses->tq_prog) mem_free(file);
 		tp_cancel(ses);
@@ -2419,7 +2419,7 @@
 	i++;
 	d->items[i].type = D_BUTTON;
 	d->items[i].fn = prog_sel_cancel;
-	d->items[i].gid = B_ESC;
+	d->items[i].gid = BTN_ESC;
 	d->items[i].text = TEXT(T_CANCEL);
 	d->items[i+1].type = D_END;
 	do_dialog(ses->term, d, ml);
@@ -2445,12 +2445,12 @@
 	}
 	m1 = stracpy(ct);
 	if (!a) {
-		if (!anonymous) msg_box(ses->term, getml(m1, NULL), TEXT(T_UNKNOWN_TYPE), AL_CENTER | AL_EXTD_TEXT, TEXT(T_CONTEN_TYPE_IS), " ", m1, ".\n", TEXT(T_DO_YOU_WANT_TO_SAVE_OR_DISLPAY_THIS_FILE), NULL, ses, 3, TEXT(T_SAVE), tp_save, B_ENTER, TEXT(T_DISPLAY), tp_display, 0, TEXT(T_CANCEL), tp_cancel, B_ESC);
-		else msg_box(ses->term, getml(m1, NULL), TEXT(T_UNKNOWN_TYPE), AL_CENTER | AL_EXTD_TEXT, TEXT(T_CONTEN_TYPE_IS), " ", m1, ".\n", TEXT(T_DO_YOU_WANT_TO_SAVE_OR_DISLPAY_THIS_FILE), NULL, ses, 2, TEXT(T_DISPLAY), tp_display, B_ENTER, TEXT(T_CANCEL), tp_cancel, B_ESC);
+		if (!anonymous) msg_box(ses->term, getml(m1, NULL), TEXT(T_UNKNOWN_TYPE), AL_CENTER | AL_EXTD_TEXT, TEXT(T_CONTEN_TYPE_IS), " ", m1, ".\n", TEXT(T_DO_YOU_WANT_TO_SAVE_OR_DISLPAY_THIS_FILE), NULL, ses, 3, TEXT(T_SAVE), tp_save, BTN_ENTER, TEXT(T_DISPLAY), tp_display, 0, TEXT(T_CANCEL), tp_cancel, BTN_ESC);
+		else msg_box(ses->term, getml(m1, NULL), TEXT(T_UNKNOWN_TYPE), AL_CENTER | AL_EXTD_TEXT, TEXT(T_CONTEN_TYPE_IS), " ", m1, ".\n", TEXT(T_DO_YOU_WANT_TO_SAVE_OR_DISLPAY_THIS_FILE), NULL, ses, 2, TEXT(T_DISPLAY), tp_display, BTN_ENTER, TEXT(T_CANCEL), tp_cancel, BTN_ESC);
 	} else {
 		m2 = stracpy(a[0].label ? a[0].label : (unsigned char *)"");
-		if (!anonymous) msg_box(ses->term, getml(m1, m2, NULL), TEXT(T_WHAT_TO_DO), AL_CENTER | AL_EXTD_TEXT, TEXT(T_CONTEN_TYPE_IS), " ", m1, ".\n", TEXT(T_DO_YOU_WANT_TO_OPEN_FILE_WITH), " ", m2, ", ", TEXT(T_SAVE_IT_OR_DISPLAY_IT), NULL, ses, 4, TEXT(T_OPEN), tp_open, B_ENTER, TEXT(T_SAVE), tp_save, 0, TEXT(T_DISPLAY), tp_display, 0, TEXT(T_CANCEL), tp_cancel, B_ESC);
-		else msg_box(ses->term, getml(m1, m2, NULL), TEXT(T_WHAT_TO_DO), AL_CENTER | AL_EXTD_TEXT, TEXT(T_CONTEN_TYPE_IS), " ", m1, ".\n", TEXT(T_DO_YOU_WANT_TO_OPEN_FILE_WITH), " ", m2, ", ", TEXT(T_SAVE_IT_OR_DISPLAY_IT), NULL, ses, 3, TEXT(T_OPEN), tp_open, B_ENTER, TEXT(T_DISPLAY), tp_display, 0, TEXT(T_CANCEL), tp_cancel, B_ESC);
+		if (!anonymous) msg_box(ses->term, getml(m1, m2, NULL), TEXT(T_WHAT_TO_DO), AL_CENTER | AL_EXTD_TEXT, TEXT(T_CONTEN_TYPE_IS), " ", m1, ".\n", TEXT(T_DO_YOU_WANT_TO_OPEN_FILE_WITH), " ", m2, ", ", TEXT(T_SAVE_IT_OR_DISPLAY_IT), NULL, ses, 4, TEXT(T_OPEN), tp_open, BTN_ENTER, TEXT(T_SAVE), tp_save, 0, TEXT(T_DISPLAY), tp_display, 0, TEXT(T_CANCEL), tp_cancel, BTN_ESC);
+		else msg_box(ses->term, getml(m1, m2, NULL), TEXT(T_WHAT_TO_DO), AL_CENTER | AL_EXTD_TEXT, TEXT(T_CONTEN_TYPE_IS), " ", m1, ".\n", TEXT(T_DO_YOU_WANT_TO_OPEN_FILE_WITH), " ", m2, ", ", TEXT(T_SAVE_IT_OR_DISPLAY_IT), NULL, ses, 3, TEXT(T_OPEN), tp_open, BTN_ENTER, TEXT(T_DISPLAY), tp_display, 0, TEXT(T_CANCEL), tp_cancel, BTN_ESC);
 	}
 	if (n)mem_free(a);
 	if (ct)mem_free(ct);
@@ -2546,7 +2546,7 @@
 	ses_destroy_defered_jump(ses);
 	if ((fn = get_external_protocol_function(url))) {
 		if (proxies.only_proxies && url_bypasses_socks(url)) {
-			msg_box(ses->term, NULL, TEXT(T_ERROR), AL_CENTER, TEXT(T_NO_PROXY), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+			msg_box(ses->term, NULL, TEXT(T_ERROR), AL_CENTER, TEXT(T_NO_PROXY), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 			return;
 		}
 		fn(ses, url);
@@ -2718,7 +2718,7 @@
 	add_to_list(sessions, ses);
 	if (first_use) {
 		first_use = 0;
-		msg_box(term, NULL, TEXT(T_WELCOME), AL_CENTER | AL_EXTD_TEXT, TEXT(T_WELCOME_TO_LINKS), "\n\n", TEXT(T_BASIC_HELP), NULL, NULL, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+		msg_box(term, NULL, TEXT(T_WELCOME), AL_CENTER | AL_EXTD_TEXT, TEXT(T_WELCOME_TO_LINKS), "\n\n", TEXT(T_BASIC_HELP), NULL, NULL, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 	}
 	return ses;
 }
diff -urN links-2.3pre2-orig/svgalib.c links-2.3pre2/svgalib.c
--- links-2.3pre2-orig/svgalib.c	2011-04-19 15:17:50.000000000 +0000
+++ links-2.3pre2/svgalib.c	2011-05-13 09:04:16.565182464 +0000
@@ -1889,80 +1889,80 @@
 	/* Test movement without buttons */
 	if (!(mouse_buttons & BUTTON_MASK) && moved) {
 		mouse_aggregate_flag=1;
-		mouse_aggregate_action=B_MOVE;
+		mouse_aggregate_action=BTN_MOVE;
 	}
 			
 	/* Test presses */
 	if ((button&MOUSE_LEFTBUTTON)&&!(mouse_buttons&MOUSE_LEFTBUTTON)){
 		mouse_aggregate_flush();
-		if (mh) mh(cd,mouse_x, mouse_y,B_LEFT|B_DOWN);
+		if (mh) mh(cd,mouse_x, mouse_y,BTN_LEFT|BTN_DOWN);
 	}
 	if ((button&MOUSE_MIDDLEBUTTON)&&!(mouse_buttons&MOUSE_MIDDLEBUTTON)){
 		mouse_aggregate_flush();
-		if (mh) mh(cd,mouse_x, mouse_y,B_MIDDLE|B_DOWN);
+		if (mh) mh(cd,mouse_x, mouse_y,BTN_MIDDLE|BTN_DOWN);
 	}
 	if ((button&MOUSE_RIGHTBUTTON)&&!(mouse_buttons&MOUSE_RIGHTBUTTON)){
 		mouse_aggregate_flush();
-		if (mh) mh(cd,mouse_x, mouse_y,B_RIGHT|B_DOWN);
+		if (mh) mh(cd,mouse_x, mouse_y,BTN_RIGHT|BTN_DOWN);
 	}
 	if ((button&MOUSE_FOURTHBUTTON)&&!(mouse_buttons&MOUSE_FOURTHBUTTON)){
 		mouse_aggregate_flush();
-		if (mh) mh(cd,mouse_x, mouse_y,B_RIGHT|B_FOURTH);
+		if (mh) mh(cd,mouse_x, mouse_y,BTN_RIGHT|BTN_FOURTH);
 	}
 	if ((button&MOUSE_FIFTHBUTTON)&&!(mouse_buttons&MOUSE_FIFTHBUTTON)){
 		mouse_aggregate_flush();
-		if (mh) mh(cd,mouse_x, mouse_y,B_RIGHT|B_FIFTH);
+		if (mh) mh(cd,mouse_x, mouse_y,BTN_RIGHT|BTN_FIFTH);
 	}
 	if ((button&MOUSE_SIXTHBUTTON)&&!(mouse_buttons&MOUSE_SIXTHBUTTON)){
 		mouse_aggregate_flush();
-		/*if (mh) mh(cd,mouse_x, mouse_y,B_RIGHT|B_SIXTH);*/
+		/*if (mh) mh(cd,mouse_x, mouse_y,BTN_RIGHT|BTN_SIXTH);*/
 		switch_virtual_device(VD_NEXT);
 	}
 
 	/* Test releases */
 	if (!(button&MOUSE_LEFTBUTTON)&&(mouse_buttons&MOUSE_LEFTBUTTON)){
 		mouse_aggregate_flush();
-		if (mh) mh(cd,mouse_x, mouse_y,B_LEFT|B_UP);
+		if (mh) mh(cd,mouse_x, mouse_y,BTN_LEFT|BTN_UP);
 	}
 	if (!(button&MOUSE_MIDDLEBUTTON)&&(mouse_buttons&MOUSE_MIDDLEBUTTON)){
 		mouse_aggregate_flush();
-		if (mh) mh(cd,mouse_x, mouse_y,B_MIDDLE|B_UP);
+		if (mh) mh(cd,mouse_x, mouse_y,BTN_MIDDLE|BTN_UP);
 	}
 	if (!(button&MOUSE_RIGHTBUTTON)&&(mouse_buttons&MOUSE_RIGHTBUTTON)){
 		mouse_aggregate_flush();
-		if (mh) mh(cd,mouse_x, mouse_y,B_RIGHT|B_UP);
+		if (mh) mh(cd,mouse_x, mouse_y,BTN_RIGHT|BTN_UP);
 	}
 	if (!(button&MOUSE_FOURTHBUTTON)&&(mouse_buttons&MOUSE_FOURTHBUTTON)){
 		mouse_aggregate_flush();
-		if (mh) mh(cd,mouse_x, mouse_y,B_FOURTH|B_UP);
+		if (mh) mh(cd,mouse_x, mouse_y,BTN_FOURTH|BTN_UP);
 	}
 	if (!(button&MOUSE_FIFTHBUTTON)&&(mouse_buttons&MOUSE_FIFTHBUTTON)){
 		mouse_aggregate_flush();
-		if (mh) mh(cd,mouse_x, mouse_y,B_FIFTH|B_UP);
+		if (mh) mh(cd,mouse_x, mouse_y,BTN_FIFTH|BTN_UP);
 	}
 	if (!(button&MOUSE_SIXTHBUTTON)&&(mouse_buttons&MOUSE_SIXTHBUTTON)){
 		mouse_aggregate_flush();
-		/*if (mh) mh(cd,mouse_x, mouse_y,B_SIXTH|B_UP);*/
+		/*if (mh) mh(cd,mouse_x, mouse_y,BTN_SIXTH|BTN_UP);*/
 	}
 	
-	if (drx < 0 && mh) mh(cd, mouse_x, mouse_y, B_MOVE | B_WHEELUP);
-	if (drx > 0 && mh) mh(cd, mouse_x, mouse_y, B_MOVE | B_WHEELDOWN);
+	if (drx < 0 && mh) mh(cd, mouse_x, mouse_y, BTN_MOVE | BTN_WHEELUP);
+	if (drx > 0 && mh) mh(cd, mouse_x, mouse_y, BTN_MOVE | BTN_WHEELDOWN);
 
-	if (dry < 0 && mh) mh(cd, mouse_x, mouse_y, B_MOVE | B_WHEELLEFT);
-	if (dry > 0 && mh) mh(cd, mouse_x, mouse_y, B_MOVE | B_WHEELRIGHT);
+	if (dry < 0 && mh) mh(cd, mouse_x, mouse_y, BTN_MOVE | BTN_WHEELLEFT);
+	if (dry > 0 && mh) mh(cd, mouse_x, mouse_y, BTN_MOVE | BTN_WHEELRIGHT);
 
 	/* Test drag */
 	if (! ((button^mouse_buttons) & BUTTON_MASK ) && moved && (button &
 		BUTTON_MASK)){
 		mouse_aggregate_flag=1;
 		mouse_aggregate_action=(
-				      button&MOUSE_LEFTBUTTON?B_LEFT:
-				      button&MOUSE_RIGHTBUTTON?B_RIGHT:
-				      button&MOUSE_MIDDLEBUTTON?B_MIDDLE:
-				      button&MOUSE_FOURTHBUTTON?B_FOURTH:
-				      button&MOUSE_FIFTHBUTTON?B_FIFTH:
-				      /*button&MOUSE_SIXTHBUTTON?B_SIXTH:*/
-				      0) | B_DRAG;
+				      button&MOUSE_LEFTBUTTON?BTN_LEFT:
+				      button&MOUSE_RIGHTBUTTON?BTN_RIGHT:
+				      button&MOUSE_MIDDLEBUTTON?BTN_MIDDLE:
+				      button&MOUSE_FOURTHBUTTON?BTN_FOURTH:
+				      button&MOUSE_FIFTHBUTTON?BTN_FIFTH:
+				      /*button&MOUSE_SIXTHBUTTON?BTN_SIXTH:*/
+				      0) | BTN_DRAG;
 	}
 	mouse_buttons=button;
 }
diff -urN links-2.3pre2-orig/types.c links-2.3pre2/types.c
--- links-2.3pre2-orig/types.c	2011-04-19 15:17:50.000000000 +0000
+++ links-2.3pre2/types.c	2011-05-13 09:04:16.599523328 +0000
@@ -342,11 +342,11 @@
 	d->items[p].data = (unsigned char *)&new->accept_ftp;
 	d->items[p++].dlen = sizeof(int);
 	d->items[p].type = D_BUTTON;
-	d->items[p].gid = B_ENTER;
+	d->items[p].gid = BTN_ENTER;
 	d->items[p].fn = ok_dialog;
 	d->items[p++].text = TEXT(T_OK);
 	d->items[p].type = D_BUTTON;
-	d->items[p].gid = B_ESC;
+	d->items[p].gid = BTN_ESC;
 	d->items[p].text = TEXT(T_CANCEL);
 	d->items[p++].fn = cancel_dialog;
 	d->items[p++].type = D_END;
@@ -660,11 +660,11 @@
 	d->items[1].data = ct;
 	d->items[1].fn = check_nonempty;
 	d->items[2].type = D_BUTTON;
-	d->items[2].gid = B_ENTER;
+	d->items[2].gid = BTN_ENTER;
 	d->items[2].fn = ok_dialog;
 	d->items[2].text = TEXT(T_OK);
 	d->items[3].type = D_BUTTON;
-	d->items[3].gid = B_ESC;
+	d->items[3].gid = BTN_ESC;
 	d->items[3].text = TEXT(T_CANCEL);
 	d->items[3].fn = cancel_dialog;
 	d->items[4].type = D_END;
diff -urN links-2.3pre2-orig/view.c links-2.3pre2/view.c
--- links-2.3pre2-orig/view.c	2011-04-19 15:17:50.001048576 +0000
+++ links-2.3pre2/view.c	2011-05-13 09:04:16.624164864 +0000
@@ -2037,7 +2037,7 @@
 	*data = NULL;
 	m1 = stracpy(sv->value);
 	m2 = stracpy(strerror(errno));
-	msg_box(ses->term, getml(m1, m2, NULL), TEXT(T_ERROR_WHILE_POSTING_FORM), AL_CENTER | AL_EXTD_TEXT, TEXT(T_COULD_NOT_GET_FILE), " ", m1, ": ", m2, NULL, ses, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+	msg_box(ses->term, getml(m1, m2, NULL), TEXT(T_ERROR_WHILE_POSTING_FORM), AL_CENTER | AL_EXTD_TEXT, TEXT(T_COULD_NOT_GET_FILE), " ", m1, ": ", m2, NULL, ses, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 }
 
 void reset_form(struct f_data_c *f, int form_num)
@@ -2878,7 +2878,7 @@
 	if (!ses->search_word) {
 		if (!ses->last_search_word) {
 			no:
-			msg_box(ses->term, NULL, TEXT(T_SEARCH), AL_CENTER, TEXT(T_NO_PREVIOUS_SEARCH), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+			msg_box(ses->term, NULL, TEXT(T_SEARCH), AL_CENTER, TEXT(T_NO_PREVIOUS_SEARCH), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 			return;
 		}
 		ses->search_word = stracpy(ses->last_search_word);
@@ -2910,7 +2910,7 @@
 			p -= f->yw;
 		}
 	} while ((c += f->yw ? f->yw : 1) < f->f_data->y + f->yw);
-	msg_box(ses->term, NULL, TEXT(T_SEARCH), AL_CENTER, TEXT(T_SEARCH_STRING_NOT_FOUND), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+	msg_box(ses->term, NULL, TEXT(T_SEARCH), AL_CENTER, TEXT(T_SEARCH_STRING_NOT_FOUND), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 }
 
 void find_next_back(struct session *ses, struct f_data_c *f, int a)
@@ -3081,12 +3081,12 @@
 			x = 1;
 			fd->vs->current_link = l - fd->f_data->links;
 			fd->vs->orig_link = fd->vs->current_link;
-			if (l->type == L_LINK || l->type == L_BUTTON || l->type == L_CHECKBOX || l->type == L_SELECT) if ((ev->b & BM_ACT) == B_UP) {
+			if (l->type == L_LINK || l->type == L_BUTTON || l->type == L_CHECKBOX || l->type == L_SELECT) if ((ev->b & BM_ACT) == BTN_UP) {
 				fd->active = 1;
 				draw_to_window(ses->win, (void (*)(struct terminal *, void *))draw_doc_c, fd);
 				change_screen_status(ses);
 				print_screen_status(ses);
-				if ((ev->b & BM_BUTT) < B_MIDDLE) x = enter(ses, fd, 0);
+				if ((ev->b & BM_BUTT) < BTN_MIDDLE) x = enter(ses, fd, 0);
 				else link_menu(ses->term, NULL, ses);
 			}
 
@@ -3485,13 +3485,13 @@
 		}
 	}
 	if (ev->ev == EV_MOUSE) {
-		if (ev->b == (B_DOWN | B_FOURTH)) {
+		if (ev->b == (BTN_DOWN | BTN_FOURTH)) {
 			go_back(ses);
 			goto x;
 		}
 #ifdef G
 		if (ses->locked_link) {
-			if ((ev->b & BM_ACT) != B_MOVE) {
+			if ((ev->b & BM_ACT) != BTN_MOVE) {
 				ses->locked_link = 0;
 #ifdef JS
 				/* process onblur handler of current link */
@@ -3514,7 +3514,7 @@
 			} else return;
 		}
 #endif
-		if (ev->y < gf_val(1, G_BFU_FONT_SIZE) && (ev->b & BM_ACT) == B_DOWN) {
+		if (ev->y < gf_val(1, G_BFU_FONT_SIZE) && (ev->b & BM_ACT) == BTN_DOWN) {
 #ifdef G
 			if (F && ev->x < ses->back_size) {
 				go_back(ses);
@@ -3792,7 +3792,7 @@
 	struct f_data_c *f;
 	if (!(f = current_frame(ses)) || !f->f_data) return;
 	if ((h = create_download_file(ses, ses->term->cwd, file, 0, 0)) < 0) return;
-	if (dump_to_file(f->f_data, h)) msg_box(ses->term, NULL, TEXT(T_SAVE_ERROR), AL_CENTER, TEXT(T_ERROR_WRITING_TO_FILE), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+	if (dump_to_file(f->f_data, h)) msg_box(ses->term, NULL, TEXT(T_SAVE_ERROR), AL_CENTER, TEXT(T_ERROR_WRITING_TO_FILE), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 	close(h);
 }
 
@@ -4173,7 +4173,7 @@
 	int l = 0;
 	unsigned char *a;
 	if (!lo || !frame || !frame->vs || !frame->f_data) {
-		msg_box(term, NULL, TEXT(T_INFO), AL_LEFT, TEXT(T_YOU_ARE_NOWHERE), NULL, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+		msg_box(term, NULL, TEXT(T_INFO), AL_LEFT, TEXT(T_YOU_ARE_NOWHERE), NULL, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 		return;
 	}
 	s = init_str();
@@ -4239,7 +4239,7 @@
 		add_to_str(&s, &l, a);
 		mem_free(a);
 	}
-	msg_box(term, getml(s, NULL), TEXT(T_INFO), AL_LEFT, s, NULL, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+	msg_box(term, getml(s, NULL), TEXT(T_INFO), AL_LEFT, s, NULL, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 }
 
 void state_msg(struct session *ses)
@@ -4254,7 +4254,7 @@
 	unsigned char *s, *ss;
 	int len;
 	if (list_empty(ses->history)) {
-		msg_box(ses->term, NULL, TEXT(T_HEADER_INFO), AL_LEFT, TEXT(T_YOU_ARE_NOWHERE), NULL, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+		msg_box(ses->term, NULL, TEXT(T_HEADER_INFO), AL_LEFT, TEXT(T_YOU_ARE_NOWHERE), NULL, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 		return;
 	}
 	if (!find_in_cache(cur_loc(ses)->url, &ce)) {
@@ -4265,6 +4265,6 @@
 			while ((ss = strstr(s, "\r\n"))) memmove(ss, ss + 1, strlen(ss));
 			while (*s && s[strlen(s) - 1] == '\n') s[strlen(s) - 1] = 0;
 		}
-		msg_box(ses->term, getml(s, NULL), TEXT(T_HEADER_INFO), AL_LEFT, s, NULL, 1, TEXT(T_OK), NULL, B_ENTER | B_ESC);
+		msg_box(ses->term, getml(s, NULL), TEXT(T_HEADER_INFO), AL_LEFT, s, NULL, 1, TEXT(T_OK), NULL, BTN_ENTER | BTN_ESC);
 	}
 }
diff -urN links-2.3pre2-orig/view_gr.c links-2.3pre2/view_gr.c
--- links-2.3pre2-orig/view_gr.c	2011-04-19 15:17:50.000000000 +0000
+++ links-2.3pre2/view_gr.c	2011-05-13 09:10:56.174325760 +0000
@@ -800,7 +800,7 @@
 void g_text_mouse(struct f_data_c *fd, struct g_object_text *a, int x, int y, int b)
 {
 	int e;
-	g_set_current_link(fd, a, x, y, (b == (B_UP | B_LEFT)));
+	g_set_current_link(fd, a, x, y, (b == (BTN_UP | BTN_LEFT)));
 
 #ifdef JS
 	if (fd->vs&&fd->f_data&&fd->vs->current_link>=0&&fd->vs->current_link<fd->f_data->nlinks)
@@ -809,16 +809,16 @@
 
 		struct link *l=&(fd->f_data->links[fd->vs->current_link]);
 
-		if (l->js_event&&l->js_event->up_code&&(b&BM_ACT)==B_UP)
+		if (l->js_event&&l->js_event->up_code&&(b&BM_ACT)==BTN_UP)
 			jsint_execute_code(fd,l->js_event->up_code,strlen(l->js_event->up_code),-1,-1,-1, NULL);
 
-		if (l->js_event&&l->js_event->down_code&&(b&BM_ACT)==B_DOWN)
+		if (l->js_event&&l->js_event->down_code&&(b&BM_ACT)==BTN_DOWN)
 			jsint_execute_code(fd,l->js_event->down_code,strlen(l->js_event->down_code),-1,-1,-1, NULL);
 		
 	}
 #endif
 
-	if (b == (B_UP | B_LEFT)) {
+	if (b == (BTN_UP | BTN_LEFT)) {
 		int ix = ismap_x, iy = ismap_y, il = ismap_link;
 		ismap_x = x;
 		ismap_y = y;
@@ -835,7 +835,7 @@
 		if (e == 2) fd->f_data->locked_on = (struct g_object *)a;
 		return;
 	}
-	if (b == (B_UP | B_RIGHT)) {
+	if (b == (BTN_UP | BTN_RIGHT)) {
 		if (fd->vs->current_link != -1) link_menu(fd->ses->term, NULL, fd->ses);
 	}
 }
@@ -994,15 +994,15 @@
 	if (!fd->f_data) return 0;
 	switch (ev->ev) {
 		case EV_MOUSE:
-			if ((ev->b & BM_BUTT) == B_WHEELUP) goto up;
-			if ((ev->b & BM_BUTT) == B_WHEELDOWN) goto down;
-			if ((ev->b & BM_BUTT) == B_WHEELUP1) goto up1;
-			if ((ev->b & BM_BUTT) == B_WHEELDOWN1) goto down1;
-			if ((ev->b & BM_BUTT) == B_WHEELLEFT) goto left;
-			if ((ev->b & BM_BUTT) == B_WHEELRIGHT) goto right;
-			if ((ev->b & BM_BUTT) == B_WHEELLEFT1) goto left1;
-			if ((ev->b & BM_BUTT) == B_WHEELRIGHT1) goto right1;
-			if ((ev->b & BM_ACT) == B_MOVE) ses->scrolling = 0;
+			if ((ev->b & BM_BUTT) == BTN_WHEELUP) goto up;
+			if ((ev->b & BM_BUTT) == BTN_WHEELDOWN) goto down;
+			if ((ev->b & BM_BUTT) == BTN_WHEELUP1) goto up1;
+			if ((ev->b & BM_BUTT) == BTN_WHEELDOWN1) goto down1;
+			if ((ev->b & BM_BUTT) == BTN_WHEELLEFT) goto left;
+			if ((ev->b & BM_BUTT) == BTN_WHEELRIGHT) goto right;
+			if ((ev->b & BM_BUTT) == BTN_WHEELLEFT1) goto left1;
+			if ((ev->b & BM_BUTT) == BTN_WHEELRIGHT1) goto right1;
+			if ((ev->b & BM_ACT) == BTN_MOVE) ses->scrolling = 0;
 			if (ses->scrolling == 1) process_sb_move(fd, ses->scrolltype ? ev->x : ev->y);
 			if (ses->scrolling == 2) {
 				fd->vs->view_pos = -ev->y + ses->scrolloff;
@@ -1010,31 +1010,31 @@
 				fd->vs->orig_view_pos = fd->vs->view_pos;
 				fd->vs->orig_view_posx = fd->vs->view_posx;
 				draw_graphical_doc(fd->ses->term, fd, 1);
-				if ((ev->b & BM_ACT) == B_UP) {
+				if ((ev->b & BM_ACT) == BTN_UP) {
 					ses->scrolling = 0;
 				}
 				break;
 			}
 			if (ses->scrolling) {
-				if ((ev->b & BM_ACT) == B_UP) {
+				if ((ev->b & BM_ACT) == BTN_UP) {
 					ses->scrolling = 0;
 				}
 				break;
 			}
 
 	
-			if ((ev->b & BM_ACT) == B_DOWN && fd->f_data->vsb && ev_in_rect(ev, fd->xw - G_SCROLL_BAR_WIDTH, 0, fd->xw, fd->yw - fd->f_data->hsb * G_SCROLL_BAR_WIDTH)) {
+			if ((ev->b & BM_ACT) == BTN_DOWN && fd->f_data->vsb && ev_in_rect(ev, fd->xw - G_SCROLL_BAR_WIDTH, 0, fd->xw, fd->yw - fd->f_data->hsb * G_SCROLL_BAR_WIDTH)) {
 				process_sb_event(fd, ev->y, 0);
 				break;
 			}
-			if ((ev->b & BM_ACT) == B_DOWN && fd->f_data->hsb && ev_in_rect(ev, 0, fd->yw - G_SCROLL_BAR_WIDTH, fd->xw - fd->f_data->vsb * G_SCROLL_BAR_WIDTH, fd->yw)) {
+			if ((ev->b & BM_ACT) == BTN_DOWN && fd->f_data->hsb && ev_in_rect(ev, 0, fd->yw - G_SCROLL_BAR_WIDTH, fd->xw - fd->f_data->vsb * G_SCROLL_BAR_WIDTH, fd->yw)) {
 				process_sb_event(fd, ev->x, 1);
 				break;
 			}
 			if (fd->f_data->vsb && ev_in_rect(ev, fd->xw - G_SCROLL_BAR_WIDTH, 0, fd->xw, fd->yw)) return 0;
 			if (fd->f_data->hsb && ev_in_rect(ev, 0, fd->yw - G_SCROLL_BAR_WIDTH, fd->xw, fd->yw)) return 0;
 
-			if ((ev->b & BM_ACT) == B_DOWN && (ev->b & BM_BUTT) == B_MIDDLE) {
+			if ((ev->b & BM_ACT) == BTN_DOWN && (ev->b & BM_BUTT) == BTN_MIDDLE) {
 				scrll:
 				ses->scrolltype = ev->x + fd->vs->view_posx;
 				ses->scrolloff = ev->y + fd->vs->view_pos;
@@ -1047,7 +1047,7 @@
 				fd->vs->g_display_link = 0;
 				if (fd->vs->current_link >= 0 && fd->vs->current_link < fd->f_data->nlinks) redraw_link(fd, fd->vs->current_link);
 			}
-			if (!(ev->b == (B_LEFT | B_UP) && fd->f_data->hlt_len && fd->f_data->start_highlight_x == -1)) {
+			if (!(ev->b == (BTN_LEFT | BTN_UP) && fd->f_data->hlt_len && fd->f_data->start_highlight_x == -1)) {
 				fd->vs->current_link = -1;
 				fd->vs->orig_link = fd->vs->current_link;
 				fd->f_data->root->mouse_event(fd, fd->f_data->root, ev->x + fd->vs->view_posx, ev->y + fd->vs->view_pos, ev->b);
@@ -1057,14 +1057,14 @@
 			}
 
 			/* highlight text */
-			if ((ev->b & BM_ACT) == B_DOWN && (ev->b & BM_BUTT) == B_LEFT) {   /* start highlighting */
+			if ((ev->b & BM_ACT) == BTN_DOWN && (ev->b & BM_BUTT) == BTN_LEFT) {   /* start highlighting */
 				fd->f_data->start_highlight_x = ev->x;
 				fd->f_data->start_highlight_y = ev->y;
 				fd->f_data->hlt_len = 0;
 				fd->f_data->hlt_pos = -1;
 				return 1;
 			}
-			if (((ev->b & BM_ACT) == B_DRAG || (ev->b & BM_ACT) == B_UP) && (ev->b & BM_BUTT) == B_LEFT) {	/* stop highlighting */
+			if (((ev->b & BM_ACT) == BTN_DRAG || (ev->b & BM_ACT) == BTN_UP) && (ev->b & BM_BUTT) == BTN_LEFT) {	/* stop highlighting */
 				struct g_object_text *t;
 				if (fd->f_data->start_highlight_x != -1) {
 					if (abs(ev->x - fd->f_data->start_highlight_x) < 8 && abs(ev->y - fd->f_data->start_highlight_y) < 8) goto skip_hl;
@@ -1088,7 +1088,7 @@
 					g_get_search_data(fd->f_data);
 					end=t->srch_pos+g_find_text_pos(t, ev->x+fd->vs->view_posx);
 					fd->f_data->hlt_len=end-fd->f_data->hlt_pos;
-					if ((ev->b & BM_ACT) == B_UP || (ev->b & BM_ACT) == B_DRAG) {
+					if ((ev->b & BM_ACT) == BTN_UP || (ev->b & BM_ACT) == BTN_DRAG) {
 						unsigned char *m = memacpy(fd->f_data->srch_string + fd->f_data->hlt_pos + (fd->f_data->hlt_len > 0 ? 0 : fd->f_data->hlt_len), fd->f_data->hlt_len > 0 ? fd->f_data->hlt_len : -fd->f_data->hlt_len);
 						if (m) {
 							unsigned char *p = m;
@@ -1118,7 +1118,7 @@
 			}
 #endif
 
-			if ((ev->b & BM_ACT) == B_DOWN && (ev->b & BM_BUTT) == B_RIGHT && fd->vs->current_link == -1) goto scrll;
+			if ((ev->b & BM_ACT) == BTN_DOWN && (ev->b & BM_BUTT) == BTN_RIGHT && fd->vs->current_link == -1) goto scrll;
 			break;
 		case EV_KBD:
 			if (ses->locked_link && fd->vs->current_link >= 0 && fd->vs->current_link < fd->f_data->nlinks && (fd->f_data->links[fd->vs->current_link].type == L_FIELD || fd->f_data->links[fd->vs->current_link].type == L_AREA)) {
@@ -1507,7 +1507,7 @@
 	g_get_search_data(f->f_data);
 	g_get_search(f->f_data, f->ses->search_word);
 	search_word = f->ses->search_word;
-	if (!f->f_data->n_search_positions) msg_box(f->ses->term, NULL, TEXT(T_SEARCH), AL_CENTER, TEXT(T_SEARCH_STRING_NOT_FOUND), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);
+	if (!f->f_data->n_search_positions) msg_box(f->ses->term, NULL, TEXT(T_SEARCH), AL_CENTER, TEXT(T_SEARCH_STRING_NOT_FOUND), NULL, 1, TEXT(T_CANCEL), NULL, BTN_ENTER | BTN_ESC);
 
 	highlight_positions = f->f_data->search_positions;
 	highlight_lengths = f->f_data->search_lengths;
diff -urN links-2.3pre2-orig/x.c links-2.3pre2/x.c
--- links-2.3pre2-orig/x.c	2011-04-19 15:17:50.000000000 +0000
+++ links-2.3pre2/x.c	2011-05-13 09:04:16.722993152 +0000
@@ -571,28 +571,28 @@
 #endif
 			gd=x_find_gd(&(last_event.xmotion.window));
 			if (!gd)break;
-			a=B_LEFT;
-			b=B_MOVE;
+			a=BTN_LEFT;
+			b=BTN_MOVE;
 			if ((last_event.xmotion.state)&Button1Mask)
 			{
-				a=B_LEFT;
-				b=B_DRAG;
+				a=BTN_LEFT;
+				b=BTN_DRAG;
 #ifdef X_DEBUG
 				MESSAGE("left button/drag\n");
 #endif
 			}
 			if ((last_event.xmotion.state)&Button2Mask)
 			{
-				a=B_MIDDLE;
-				b=B_DRAG;
+				a=BTN_MIDDLE;
+				b=BTN_DRAG;
 #ifdef X_DEBUG	
 				MESSAGE("middle button/drag\n");
 #endif
 			}
 			if ((last_event.xmotion.state)&Button3Mask)
 			{
-				a=B_RIGHT;
-				b=B_DRAG;
+				a=BTN_RIGHT;
+				b=BTN_DRAG;
 #ifdef X_DEBUG
 				MESSAGE("right button/drag\n");
 #endif
@@ -718,15 +718,15 @@
 				switch(event.xbutton.button)
 				{
 					case 1:
-					a=B_LEFT;
+					a=BTN_LEFT;
 					break;
 
 					case 3:
-					a=B_RIGHT;
+					a=BTN_RIGHT;
 					break;
 
 					case 2:
-					a=B_MIDDLE;
+					a=BTN_MIDDLE;
 					break;
 
 					default:
@@ -735,7 +735,7 @@
 				}
 				x_clip_number(&(event.xmotion.x),gd->size.x1,gd->size.x2);
 				x_clip_number(&(event.xmotion.y),gd->size.y1,gd->size.y2);
-				gd->mouse_handler(gd,event.xbutton.x,event.xbutton.y,a|B_UP);
+				gd->mouse_handler(gd,event.xbutton.x,event.xbutton.y,a|BTN_UP);
 				r_xx:;
 			}
 			break;
@@ -757,31 +757,31 @@
 				switch(event.xbutton.button)
 				{
 					case 1:
-					a=B_LEFT;
+					a=BTN_LEFT;
 					break;
 
 					case 3:
-					a=B_RIGHT;
+					a=BTN_RIGHT;
 					break;
 
 					case 2:
-					a=B_MIDDLE;
+					a=BTN_MIDDLE;
 					break;
 
 					case 4:
-					a=B_WHEELUP;
+					a=BTN_WHEELUP;
 					break;
 
 					case 5:
-					a=B_WHEELDOWN;
+					a=BTN_WHEELDOWN;
 					break;
 
 					case 6:
-					a=B_WHEELLEFT;
+					a=BTN_WHEELLEFT;
 					break;
 
 					case 7:
-					a=B_WHEELRIGHT;
+					a=BTN_WHEELRIGHT;
 					break;
 
 					default:
@@ -789,7 +789,7 @@
 				}
 				x_clip_number(&(event.xmotion.x),gd->size.x1,gd->size.x2);
 				x_clip_number(&(event.xmotion.y),gd->size.y1,gd->size.y2);
-				gd->mouse_handler(gd,event.xbutton.x,event.xbutton.y,a|(a != B_WHEELDOWN && a != B_WHEELUP && a != B_WHEELLEFT && a != B_WHEELRIGHT ? B_DOWN : B_MOVE));
+				gd->mouse_handler(gd,event.xbutton.x,event.xbutton.y,a|(a != BTN_WHEELDOWN && a != BTN_WHEELUP && a != BTN_WHEELLEFT && a != BTN_WHEELRIGHT ? BTN_DOWN : BTN_MOVE));
 				p_xx:;
 			}
 			break;
@@ -858,28 +858,28 @@
 #endif
 		gd=x_find_gd(&(last_event.xmotion.window));
 		if (!gd)goto ret;
-		a=B_LEFT;
-		b=B_MOVE;
+		a=BTN_LEFT;
+		b=BTN_MOVE;
 		if ((last_event.xmotion.state)&Button1Mask)
 		{
-			a=B_LEFT;
-			b=B_DRAG;
+			a=BTN_LEFT;
+			b=BTN_DRAG;
 #ifdef X_DEBUG
 			MESSAGE("left button/drag\n");
 #endif
 		}
 		if ((last_event.xmotion.state)&Button2Mask)
 		{
-			a=B_MIDDLE;
-			b=B_DRAG;
+			a=BTN_MIDDLE;
+			b=BTN_DRAG;
 #ifdef X_DEBUG	
 			MESSAGE("middle button/drag\n");
 #endif
 		}
 		if ((last_event.xmotion.state)&Button3Mask)
 		{
-			a=B_RIGHT;
-			b=B_DRAG;
+			a=BTN_RIGHT;
+			b=BTN_DRAG;
 #ifdef X_DEBUG
 			MESSAGE("right button/drag\n");
 #endif
