diff --git a/Portfile b/Portfile
index f5292ef..d9b2427 100644
--- a/Portfile
+++ b/Portfile
@@ -5,7 +5,7 @@ PortSystem                  1.0
 PortGroup                   xcodeversion 1.0
 
 name                        gnuplot
-version                     4.4.4
+version                     4.6.0
 categories                  math science
 # the license has some inconvenient requirements that we're not meeting
 # to be allowed to distribute binaries
@@ -31,11 +31,11 @@ dist_subdir                 ${name}/${version}
 distfiles-append            ${name}.pdf
 extract.only                ${distname}.tar.gz
 checksums                   ${distname}.tar.gz \
-                            rmd160  7e1d039c05c46fa38b53a3c4afbd328509da901d \
-                            sha256  d228599d08d5f87bcb79af8af8bb432c77d942802b1643f920c7baaeaf1ddbfd \
+                            rmd160  2c06500f45fb81850b45713a2cd0e38f0021b065 \
+                            sha256  6e60adb5039a3541f407c2ade670004178b376754c424c13f0be24c7960c17be \
                             ${name}.pdf \
-                            rmd160  f8bd424418bbf87e405c0f3d7eb2bf759c4770d5 \
-                            sha256  3495b65604239d78cdad5ac3b34864572382c09ddf8ea202bddafce9133a1adf
+                            rmd160  374614145a7b78e263b0cfbb695eb22d07dede9a \
+                            sha256  57bd4d88e1321968ba06f29dfa322b4cd9e6beb4e0f42e1a4775d9c9a41af170
 
 depends_lib                 port:expat \
                             port:fontconfig \
@@ -49,11 +49,23 @@ depends_lib                 port:expat \
                             port:xpm \
                             port:zlib
 
-patchfiles                  patch-src-variable_c.diff
+patchfiles                  patch-src-variable_c.diff \
+                            patch-upstream-compilerwarnings.diff \
+                            patch-upstream-wxt-scroll.diff \
+                            patch-upstream-qt.diff \
+                            patch-configure-qt.diff
+
+# upstream patches:
+#
+# - patch-upstream-compilerwarnings.diff
+#   2012-03-18 17:30:42 Hans-Bernhard Broeker (cvs commit:broeker)
+# - patch-upstream-wxt-scroll.diff
+#   2012-02-29 19:29:25 Mojca Miklavec (cvs commit:sfeam)
+# - patch-upstream-qt.diff
+#   2012-04-01 08:49:45 Jérôme Lodewyck (cvs commit:lodewyck)
 
 platform darwin {
     depends_lib-append      port:aquaterm
-    configure.cflags-append -DDEFAULTTERM='"aqua"'
 }
 
 minimum_xcodeversions       {9 3.1}
@@ -81,8 +93,23 @@ variant no_x11 {
     configure.args-append   --without-x
 }
 
-variant wxwidgets description "Enable wxWidgets front-end" {
-    depends_lib-append      port:wxWidgets
+variant luaterm description "Enable lua-based terminals" {
+    depends_lib-append      port:lua
+    configure.args-delete   --without-lua
+    configure.args-append   --with-lua
+}
+
+variant pangocairo description "Enable cairo-based terminals" {
+    depends_lib-append      path:lib/pkgconfig/pango.pc:pango
+    configure.args-delete   --without-cairo
+}
+
+# One can in principle choose between wxWidgets and wxWidgets-devel,
+# but only 2.9 allows building 64-bit binaries.
+# If it is acceptable to depend on wxWidgets-devel only,
+# one could delete the variant that depends on wxWidgets 2.8.
+variant wxwidgets conflicts wxwidgets_devel description "Enable wxt terminal (wxWidgets 2.8, 32-bit only)" {
+    depends_lib-append      port:wxWidgets path:lib/pkgconfig/pango.pc:pango
     configure.args-delete   --disable-wxwidgets
     configure.args-append   --with-wx-config=${prefix}/bin/wx-config
 }
@@ -92,15 +119,21 @@ if {[variant_isset wxwidgets]} {
     supported_archs         i386 ppc
 }
 
-variant luaterm description "Enable Lua terminal" {
-    depends_lib-append      port:lua
-    configure.args-delete   --without-lua
-    configure.args-append   --with-lua
+variant wxwidgets_devel conflicts wxwidgets description "Enable wxt terminal (using wxWidgets 2.9, supports 64-bit)" {
+    depends_lib-append      port:wxWidgets-devel path:lib/pkgconfig/pango.pc:pango
+    configure.args-delete   --disable-wxwidgets
+    configure.args-append   --with-wx-config=${prefix}/bin/wx-config
+}
+if {[variant_isset wxwidgets_devel]} {
+    # http://trac.wxwidgets.org/ticket/13565
+    if {${configure.compiler} == "clang"} {
+        configure.compiler llvm-gcc-4.2
+    }
 }
 
-variant pangocairo description "Enable cairo-based terminals" {
-    depends_lib-append      path:lib/pkgconfig/pango.pc:pango
-    configure.args-delete   --without-cairo
+variant qt description "Enable qt terminal" {
+    depends_lib-append      port:qt4-mac
+    configure.args-append   --enable-qt
 }
 
 variant tutorial description "Build the tutorial (requires a tex install)" {
diff --git a/files/patch-configure-qt.diff b/files/patch-configure-qt.diff
new file mode 100644
index 0000000..0f92580
--- /dev/null
+++ b/files/patch-configure-qt.diff
@@ -0,0 +1,96 @@
+--- configure.orig
++++ configure
+@@ -7828,7 +7828,7 @@ else
+ 	char b[false == 0 ? 1 : -1];
+ 	char c[__bool_true_false_are_defined == 1 ? 1 : -1];
+ 	char d[(bool) 0.5 == true ? 1 : -1];
+-	bool e = &s;
++	/* See body of main program for 'e'.  */
+ 	char f[(_Bool) 0.0 == false ? 1 : -1];
+ 	char g[true];
+ 	char h[sizeof (_Bool)];
+@@ -7839,25 +7839,6 @@ else
+ 	_Bool n[m];
+ 	char o[sizeof n == m * sizeof n[0] ? 1 : -1];
+ 	char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
+-#	if defined __xlc__ || defined __GNUC__
+-	 /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
+-	    reported by James Lemley on 2005-10-05; see
+-	    http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
+-	    This test is not quite right, since xlc is allowed to
+-	    reject this program, as the initializer for xlcbug is
+-	    not one of the forms that C requires support for.
+-	    However, doing the test right would require a runtime
+-	    test, and that would make cross-compilation harder.
+-	    Let us hope that IBM fixes the xlc bug, and also adds
+-	    support for this kind of constant expression.  In the
+-	    meantime, this test will reject xlc, which is OK, since
+-	    our stdbool.h substitute should suffice.  We also test
+-	    this with GCC, where it should work, to detect more
+-	    quickly whether someone messes up the test in the
+-	    future.  */
+-	 char digs[] = "0123456789";
+-	 int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
+-#	endif
+ 	/* Catch a bug in an HP-UX C compiler.  See
+ 	   http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
+ 	   http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
+@@ -7869,6 +7850,7 @@ int
+ main ()
+ {
+ 
++	bool e = &s;
+ 	*pq |= q;
+ 	*pq |= ! q;
+ 	/* Refer to every declared value, to avoid compiler optimizations.  */
+@@ -13010,7 +12992,7 @@ fi
+   CXXFLAGS="$CXXFLAGS $QT_CXXFLAGS"
+ 
+     if test "$is_apple" = yes; then
+-    CXXFLAGS="$CXXFLAGS -ObjC"
++    LIBS="$LIBS -framework Carbon"
+   fi
+ 
+   QT4LOC=`$PKG_CONFIG --variable=exec_prefix QtCore`
+--- configure.in.orig
++++ configure.in
+@@ -1146,7 +1146,7 @@ if test "${enable_qt_ok}" = yes ; then
+ 
+   dnl Compile Objective C Cocoa headers on Mac to hide the gnuplot icon from the dock
+   if test "$is_apple" = yes; then
+-    CXXFLAGS="$CXXFLAGS -ObjC"
++    LIBS="$LIBS -framework Carbon"
+   fi
+ 
+   QT4LOC=`$PKG_CONFIG --variable=exec_prefix QtCore`
+--- src/qtterminal/qt_term.cpp.orig
++++ src/qtterminal/qt_term.cpp
+@@ -46,7 +46,7 @@
+ #include <QtNetwork>
+ 
+ #ifdef Q_WS_MAC
+-	#include <Cocoa/Cocoa.h>
++	#include <Carbon/Carbon.h>
+ #endif
+ 
+ extern "C" {
+@@ -308,10 +308,15 @@ void qt_init()
+ 	QApplication* application = new QApplication(argc, (char**)( NULL));
+ 
+ #ifdef Q_WS_MAC
+-	// Don't display this application in the MAC OS X dock
+-	ProcessSerialNumber psn;
+-	if (GetCurrentProcess(&psn) == noErr)
+-		TransformProcessType(&psn, kProcessTransformToBackgroundApplication);
++	#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
++		#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
++			// Don't display this application in the MAC OS X dock
++			// kProcessTransformToBackgroundApplication only works on Mac OS X 10.7 and later
++			ProcessSerialNumber psn;
++			if (GetCurrentProcess(&psn) == noErr)
++				TransformProcessType(&psn, kProcessTransformToBackgroundApplication);
++		#endif
++	#endif
+ #endif
+ 
+ 	// The creation of a QApplication mangled our locale settings
diff --git a/files/patch-src-variable_c.diff b/files/patch-src-variable_c.diff
index eb2abce..95eae92 100644
--- a/files/patch-src-variable_c.diff
+++ b/files/patch-src-variable_c.diff
@@ -1,6 +1,6 @@
---- src/variable.c.orig	2010-10-18 15:41:53.000000000 +0200
-+++ src/variable.c	2010-10-18 15:42:11.000000000 +0200
-@@ -244,13 +244,13 @@
+--- src/variable.c.orig
++++ src/variable.c
+@@ -250,13 +250,13 @@
  };
  #endif
  
diff --git a/files/patch-upstream-compilerwarnings.diff b/files/patch-upstream-compilerwarnings.diff
new file mode 100644
index 0000000..03b8163
--- /dev/null
+++ b/files/patch-upstream-compilerwarnings.diff
@@ -0,0 +1,91 @@
+--- src/color.c.orig
++++ src/color.c
+@@ -515,7 +515,7 @@ cbtick_callback(
+ 	    if (axis_array[axis].manual_justify)
+ 		just = axis_array[axis].label.pos;
+ 	    write_multiline(x2+offsetx, y3+offsety, text,
+-			    just, CENTRE, hrotate,
++			    just, JUST_CENTRE, hrotate,
+ 			    axis_array[axis].ticdef.font);
+ 	    if (hrotate)
+ 		(*term->text_angle)(0);
+@@ -526,7 +526,7 @@ cbtick_callback(
+ 	    if (axis_array[axis].manual_justify)
+ 		just = axis_array[axis].label.pos;	    
+ 	    write_multiline(x3+offsetx, y2+offsety, text,
+-			    just, CENTRE, 0.0,
++			    just, JUST_CENTRE, 0.0,
+ 			    axis_array[axis].ticdef.font);
+ 	}
+ 	term_apply_lp_properties(&border_lp);	/* border linetype */
+--- src/gplt_x11.c.orig
++++ src/gplt_x11.c
+@@ -2897,22 +2897,22 @@ exec_cmd(plot_struct *plot, char *command)
+ 
+ 		    case PseudoColor:
+ 			fprintf(stderr, ERROR_NOTICE("PseudoColor"));
+-			fprintf(stderr, display_error_text_after);
++			fprintf(stderr, "%s", display_error_text_after);
+ 			break;
+ 
+ 		    case GrayScale:
+ 			fprintf(stderr, ERROR_NOTICE("GrayScale"));
+-			fprintf(stderr, display_error_text_after);
++			fprintf(stderr, "%s", display_error_text_after);
+ 			break;
+ 
+ 		    case StaticColor:
+ 			fprintf(stderr, ERROR_NOTICE("StaticColor"));
+-			fprintf(stderr, display_error_text_after);
++			fprintf(stderr, "%s", display_error_text_after);
+ 			break;
+ 
+ 		    case StaticGray:
+ 			fprintf(stderr, ERROR_NOTICE("StaticGray"));
+-			fprintf(stderr, display_error_text_after);
++			fprintf(stderr, "%s", display_error_text_after);
+ 			break;
+ 
+ 		    case DirectColor:
+--- src/graphics.c.orig
++++ src/graphics.c
+@@ -1734,7 +1734,7 @@ do_plot(struct curve_points *plots, int pcount)
+ 	ignore_enhanced(axis_array[FIRST_X_AXIS].label.noenhanced);
+ 	apply_pm3dcolor(&(axis_array[FIRST_X_AXIS].label.textcolor), t);
+ 	write_multiline(x, y, axis_array[FIRST_X_AXIS].label.text,
+-			JUST_CENTRE, JUST_TOP, 0,
++			CENTRE, JUST_TOP, 0,
+ 			axis_array[FIRST_X_AXIS].label.font);
+ 	reset_textcolor(&(axis_array[FIRST_X_AXIS].label.textcolor), t);
+ 	ignore_enhanced(FALSE);
+--- src/plot2d.c.orig
++++ src/plot2d.c
+@@ -2120,7 +2120,7 @@ eval_plots()
+ 
+ 		    if (this_plot->labels == NULL) {
+ 			this_plot->labels = new_text_label(-1);
+-			this_plot->labels->pos = JUST_CENTRE;
++			this_plot->labels->pos = CENTRE;
+ 			this_plot->labels->layer = LAYER_PLOTLABELS;
+ 		    }
+ 		    parse_label_options(this_plot->labels);
+@@ -2309,7 +2309,7 @@ eval_plots()
+ 	    if (this_plot->plot_style == LABELPOINTS) {
+ 		if (this_plot->labels == NULL) {
+ 		    this_plot->labels = new_text_label(-1);
+-		    this_plot->labels->pos = JUST_CENTRE;
++		    this_plot->labels->pos = CENTRE;
+ 		    this_plot->labels->layer = LAYER_PLOTLABELS;
+ 		}
+ 		this_plot->labels->place.scalex =
+--- src/plot3d.c.orig
++++ src/plot3d.c
+@@ -1555,7 +1555,7 @@ eval_3dplots()
+ 		    int stored_token = c_token;
+ 		    if (this_plot->labels == NULL) {
+ 			this_plot->labels = new_text_label(-1);
+-			this_plot->labels->pos = JUST_CENTRE;
++			this_plot->labels->pos = CENTRE;
+ 			this_plot->labels->layer = LAYER_PLOTLABELS;
+ 		    }
+ 		    parse_label_options(this_plot->labels);
diff --git a/files/patch-upstream-qt.diff b/files/patch-upstream-qt.diff
new file mode 100644
index 0000000..573932c
--- /dev/null
+++ b/files/patch-upstream-qt.diff
@@ -0,0 +1,86 @@
+--- src/qtterminal/QtGnuplotScene.cpp.orig
++++ src/qtterminal/QtGnuplotScene.cpp
+@@ -56,7 +56,7 @@ QtGnuplotScene::QtGnuplotScene(QtGnuplotEventHandler* eventHandler, QObject* par
+ 	m_eventHandler = eventHandler;
+ 	m_lastModifierMask = 0;
+ 	m_textAngle = 0.;
+-	m_textAlignment == Qt::AlignLeft;
++	m_textAlignment = Qt::AlignLeft;
+ 	m_currentZ = 1.;
+ 	m_currentPointSize = 1.;
+ 	m_enhanced = 0;
+--- src/qtterminal/QtGnuplotWidget.cpp.orig
++++ src/qtterminal/QtGnuplotWidget.cpp
+@@ -169,6 +169,15 @@ void QtGnuplotWidget::resizeEvent(QResizeEvent* event)
+ 	QWidget::resizeEvent(event);
+ }
+ 
++QPainter::RenderHints QtGnuplotWidget::renderHints() const
++{
++	QPainter::RenderHints hint = QPainter::TextAntialiasing;
++	if (m_antialias)
++		hint |= QPainter::Antialiasing;
++
++	return hint;
++}
++
+ /////////////////////////////////////////////////
+ // Slots
+ 
+@@ -178,7 +187,7 @@ QPixmap QtGnuplotWidget::createPixmap()
+ 	pixmap.fill();
+ 	QPainter painter(&pixmap);
+ 	painter.translate(0.5, 0.5);
+-	painter.setRenderHint(m_antialias ? QPainter::Antialiasing : QPainter::TextAntialiasing);
++	painter.setRenderHints(renderHints());
+ 	m_scene->render(&painter);
+ 	painter.end();
+ 	return pixmap;
+@@ -195,7 +204,7 @@ void QtGnuplotWidget::print()
+ 	if (QPrintDialog(&printer).exec() == QDialog::Accepted)
+ 	{
+ 		QPainter painter(&printer);
+-		painter.setRenderHint(m_antialias ? QPainter::Antialiasing : QPainter::TextAntialiasing);
++		painter.setRenderHints(renderHints());
+ 		m_scene->render(&painter);
+ 	}
+ }
+@@ -211,8 +220,10 @@ void QtGnuplotWidget::exportToPdf()
+ 	QPrinter printer;
+ 	printer.setOutputFormat(QPrinter::PdfFormat);
+ 	printer.setOutputFileName(fileName);
++	printer.setPaperSize(QSizeF(m_scene->width(), m_scene->height()), QPrinter::Point);
++	printer.setPageMargins(0, 0, 0, 0, QPrinter::Point);
+ 	QPainter painter(&printer);
+-	painter.setRenderHint(m_antialias ? QPainter::Antialiasing : QPainter::TextAntialiasing);
++	painter.setRenderHints(renderHints());
+ 	m_scene->render(&painter);
+ }
+ 
+@@ -266,7 +277,7 @@ void QtGnuplotWidget::loadSettings()
+ 
+ void QtGnuplotWidget::applySettings()
+ {
+-	m_view->setRenderHints(m_antialias ? QPainter::Antialiasing : QPainter::TextAntialiasing);
++	m_view->setRenderHints(renderHints());
+ 	m_view->setBackgroundBrush(m_backgroundColor);
+ }
+ 
+--- src/qtterminal/QtGnuplotWidget.h.orig
++++ src/qtterminal/QtGnuplotWidget.h
+@@ -47,6 +47,7 @@
+ #include "QtGnuplotEvent.h"
+ 
+ #include <QWidget>
++#include <QPainter>
+ 
+ class QtGnuplotScene;
+ class QGraphicsView;
+@@ -93,6 +94,7 @@ private:
+ 	void loadSettings();
+ 	void applySettings();
+ 	void saveSettings();
++	QPainter::RenderHints renderHints() const;
+ 
+ private:
+ 	int m_id;
diff --git a/files/patch-upstream-wxt-scroll.diff b/files/patch-upstream-wxt-scroll.diff
new file mode 100644
index 0000000..212b4f3
--- /dev/null
+++ b/files/patch-upstream-wxt-scroll.diff
@@ -0,0 +1,23 @@
+--- src/wxterminal/wxt_gui.cpp.orig
++++ src/wxterminal/wxt_gui.cpp
+@@ -1003,11 +1003,16 @@ void wxtPanel::OnRightUp( wxMouseEvent& event )
+ /* mouse wheel event */
+ void wxtPanel::OnMouseWheel( wxMouseEvent& event )
+ {
+-	UpdateModifiers(event);
++	int mouse_button;
+ 
+-	wxt_exec_event(GE_buttonpress, 0, 0, 
+-			event.GetWheelRotation() > 0 ? 4 : 5, 
+-			0, this->GetId());
++	UpdateModifiers(event);
++	mouse_button = (event.GetWheelRotation() > 0 ? 4 : 5);
++#if wxCHECK_VERSION(2, 9, 0)
++	/* GetWheelAxis: 0 is the Y axis, 1 is the X axis. */
++	if (event.GetWheelAxis() > 0)
++	    mouse_button += 2;
++#endif
++	wxt_exec_event(GE_buttonpress, 0, 0, mouse_button, 0, this->GetId());
+ }
+ 
+ /* the state of the modifiers is checked each time a key is pressed instead of
