diff --git a/.gitignore b/.gitignore
index d2ca1d72a8b22e47632ea37a6de43267c9907a28..e72561ed34bed49788bee9722a4a1bc315d47487 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,7 +6,7 @@ ext/fox16_c/*_wrap.cpp
 ext/fox16_c/*.o
 ext/fox16_c/conftest.dSYM
 ext/fox16_c/include/inlinestubs.h
-ext/fox16_c/librb.c
+ext/fox16_c/swigruby.h
 ext/fox16_c/fox16.bundle
 ext/fox16_c/mkmf.log
 lib/fox16/kwargs.rb
diff --git a/Rakefile b/Rakefile
index 9348b70cd12a00793a1dacf26c6eb1a354e00b56..ec15a7b9b1d59b18fc5627894823b44a8fd3417a 100755
--- a/Rakefile
+++ b/Rakefile
@@ -22,8 +22,8 @@ PKG_VERSION = Fox.fxrubyversion
 # TODO: Don't depend on cross compilation task
 FXSCINTILLA_INSTALL_DIR = Pathname( CrossLibraries.first.static_libfxscintilla_builddir ).expand_path
 
-SWIG = (RUBY_PLATFORM =~ /mingw/) ? "swig-1.3.22.exe" : "swig-1.3.22"
-SWIGFLAGS = "-fcompact -noruntime -c++ -ruby -no_default -I../fox-includes"
+SWIG = (RUBY_PLATFORM =~ /mingw/) ? "swig.exe" : "swig"
+SWIGFLAGS = "-fcompact -c++ -ruby -nodefaultdtor -nodefaultctor -w302 -features compactdefaultargs -I../fox-includes"
 SWIG_LIB = `#{SWIG} -swiglib`.chomp
 SWIG_MODULES = {
   "core.i" => "core_wrap.cpp",
@@ -70,7 +70,7 @@ hoe = Hoe.spec "fxruby" do
   spec_extras[:files] = File.read_utf("Manifest.txt").split(/\r?\n\r?/).reject{|f| f=~/^fox-includes|^web/ }
   spec_extras[:files] += SWIG_MODULES.values.map{|f| File.join("ext/fox16_c", f) }
   spec_extras[:files] << 'ext/fox16_c/include/inlinestubs.h'
-  spec_extras[:files] << 'ext/fox16_c/librb.c'
+  spec_extras[:files] << 'ext/fox16_c/swigruby.h'
   spec_extras[:files] << 'doap.rdf'
   spec_extras[:files] << 'lib/fox16/kwargs.rb'
 end
@@ -145,20 +145,14 @@ namespace :swig do
     sed wrapper_src_file_name
   end
 
-  task :swig_librb => ["ext/fox16_c/librb.c"]
-  file "ext/fox16_c/librb.c" do |task|
+  task :swigruby_h => ["ext/fox16_c/swigruby.h"]
+  file "ext/fox16_c/swigruby.h" do |task|
     puts "generate #{task.name}"
-    File.open(task.name, "w") do |io|
-      io.puts "#define SWIG_GLOBAL 1"
-      io.write(IO.read(File.join(SWIG_LIB, "ruby", "precommon.swg")))
-      io.write(IO.read(File.join(SWIG_LIB, "common.swg")))
-      io.write(IO.read(File.join(SWIG_LIB, "ruby", "rubyhead.swg")))
-      io.write(IO.read(File.join(SWIG_LIB, "ruby", "rubydef.swg")))
-    end
+    system "#{SWIG} -ruby -external-runtime #{task.name}"
   end
 
   desc "Run SWIG to generate the wrapper files."
-  task :swig => [:swig_librb] + SWIG_MODULES.map{|ifile, cppfile| File.join("ext/fox16_c", cppfile) }
+  task :swig => [:swigruby_h] + SWIG_MODULES.map{|ifile, cppfile| File.join("ext/fox16_c", cppfile) }
 
   # add dependencies for compile *.i to *_wrap.cpp
   SWIG_MODULES.each do |ifile, cppfile|
@@ -218,7 +212,7 @@ namespace :fxruby do
     make_impl
   end
 
-  file "ext/fox16_c/extconf.rb" => ['ext/fox16_c/librb.c', 'ext/fox16_c/impl.cpp', 'ext/fox16_c/include/inlinestubs.h'] +
+  file "ext/fox16_c/extconf.rb" => ['ext/fox16_c/swigruby.h', 'ext/fox16_c/impl.cpp', 'ext/fox16_c/include/inlinestubs.h'] +
       SWIG_MODULES.map{|ifile, cppfile| File.join("ext/fox16_c", cppfile) }
 
   task :scintilla => 'lib/fox16/scintilla.rb'
diff --git a/ext/fox16_c/FXRuby.cpp b/ext/fox16_c/FXRuby.cpp
index 7ef9f06eec276bd52efba05e8761da51cdf7e2c1..260d74d572626b7b1ed299889db54464244ad531 100644
--- a/ext/fox16_c/FXRuby.cpp
+++ b/ext/fox16_c/FXRuby.cpp
@@ -31,6 +31,9 @@
 #include "FXRbCommon.h"
 #include "impl.h"
 
+// SWIG runtime functions we need
+#include "swigruby.h"
+
 #ifdef __CYGWIN__
 #include <io.h>		// for get_osf_handle()
 #endif
@@ -63,7 +66,7 @@ swig_type_info *FXRbTypeQuery(const char *desc){
   static st_table *types=st_init_strtable();
   swig_type_info *typeinfo=0;
   if(st_lookup(types,reinterpret_cast<st_data_t>(const_cast<char*>(desc)),reinterpret_cast<st_data_t *>(&typeinfo))==0){
-    typeinfo=SWIG_Ruby_TypeQuery(desc);
+    typeinfo=SWIG_TypeQuery(desc);
     st_insert(types,reinterpret_cast<st_data_t>(strdup(desc)),reinterpret_cast<st_data_t>(typeinfo));
     }
   FXASSERT(typeinfo!=0);
@@ -168,12 +171,12 @@ bool FXRbIsInGC(const void* ptr){
 
 
 /**
- * FXRbConvertPtr() is just a wrapper around SWIG_Ruby_ConvertPtr().
+ * FXRbConvertPtr() is just a wrapper around SWIG_ConvertPtr().
  */
 
 void* FXRbConvertPtr(VALUE obj,swig_type_info* ty){
   void *ptr;
-  SWIG_Ruby_ConvertPtr(obj,&ptr,ty,1);
+  SWIG_ConvertPtr(obj,&ptr,ty,1);
   return ptr;
   }
 
@@ -1018,7 +1021,7 @@ void* FXRbGetExpectedData(VALUE recv,FXSelector key,VALUE value){
     case SEL_DND_MOTION:
     case SEL_DND_REQUEST:
     case SEL_PICKED:
-      SWIG_Ruby_ConvertPtr(value,&ptr,FXRbTypeQuery("FXEvent *"),1);
+      SWIG_ConvertPtr(value,&ptr,FXRbTypeQuery("FXEvent *"),1);
       return ptr;
     case SEL_IO_READ:
     case SEL_IO_WRITE:
@@ -1195,14 +1198,14 @@ void* FXRbGetExpectedData(VALUE recv,FXSelector key,VALUE value){
 
   if(type==SEL_CHANGED){
 	  if(obj->isMemberOf(FXMETACLASS(FXPicker))){
-			SWIG_Ruby_ConvertPtr(value,&ptr,FXRbTypeQuery("FXPoint *"),1);
+			SWIG_ConvertPtr(value,&ptr,FXRbTypeQuery("FXPoint *"),1);
 			return ptr;
 	    }
 		return 0;
     }
 
 	if(type==SEL_DRAGGED){
-	    SWIG_Ruby_ConvertPtr(value,&ptr,FXRbTypeQuery("FXEvent *"),1);
+	    SWIG_ConvertPtr(value,&ptr,FXRbTypeQuery("FXEvent *"),1);
 	    return ptr;
 	    }
 
diff --git a/ext/fox16_c/include/FXRuby.h b/ext/fox16_c/include/FXRuby.h
index 111c11efab3d842fdbba735e43d65484b43f56d4..6f6b2335fc82b77d69b16835740c340d9050eab1 100644
--- a/ext/fox16_c/include/FXRuby.h
+++ b/ext/fox16_c/include/FXRuby.h
@@ -53,17 +53,18 @@ struct swig_type_info;
 
 // SWIG runtime functions we need
 extern "C" {
-const char *     SWIG_Ruby_TypeName(const swig_type_info *ty);
-swig_type_info * SWIG_Ruby_TypeQuery(const char *);
-VALUE            SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int own);
-int              SWIG_Ruby_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flags);
+static const char * SWIG_TypeName(const swig_type_info *ty);
+static VALUE SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int own);
+#define SWIG_ConvertPtr(obj, pptr, type, flags)         SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, 0)
+typedef void (*ruby_owntype)(void*);
+static int SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, ruby_owntype *own);
 }
 
 // Helper for overloaded show() functions
 template <class TYPE>
 VALUE showHelper(VALUE self, int argc, VALUE *argv, TYPE *p, swig_type_info *typeinfo) {
   TYPE *win;
-  SWIG_Ruby_ConvertPtr(self,(void**)&win,typeinfo,1);
+  SWIG_ConvertPtr(self,(void**)&win,typeinfo,1);
   if (argc == 0) {
     win->_show();
     }
diff --git a/swig-interfaces/FXWindow.i b/swig-interfaces/FXWindow.i
index e8e596b7e85bfcc1a29ab3b5a295df8f724c07f6..81d8e2e22c95bc89a74c3be2d67e09ba7bd043b2 100644
--- a/swig-interfaces/FXWindow.i
+++ b/swig-interfaces/FXWindow.i
@@ -599,7 +599,7 @@ public:
       if(numtypes>0){
         types=new FXDragType[numtypes];
         for(FXuint i=0;i<numtypes;i++){
-          types[i]=(FXDragType) NUM2USHRT(rb_ary_entry(typesArray,i));
+          types[i]=(FXDragType) NUM2UINT(rb_ary_entry(typesArray,i));
           }
       }
       bool result=self->acquireSelection(types,numtypes);
@@ -623,7 +623,7 @@ public:
       if(numtypes>0){
         types=new FXDragType[numtypes];
         for(FXuint i=0;i<numtypes;i++){
-          types[i]=(FXDragType) NUM2USHRT(rb_ary_entry(typesArray,i));
+          types[i]=(FXDragType) NUM2UINT(rb_ary_entry(typesArray,i));
           }
       }
       bool result=self->acquireClipboard(types,numtypes);
@@ -650,7 +650,7 @@ public:
       if(numtypes>0){
         types=new FXDragType[numtypes];
         for(FXuint i=0;i<numtypes;i++){
-          types[i]=(FXDragType) NUM2USHRT(rb_ary_entry(typesArray,i));
+          types[i]=(FXDragType) NUM2UINT(rb_ary_entry(typesArray,i));
           }
       }
       bool result=self->beginDrag(types,numtypes);
diff --git a/swig-interfaces/fxdefs.i b/swig-interfaces/fxdefs.i
index 3b1e496c6dd5c6c7c7b1d18eb003bb8e9c251deb..d0983ebcb98fc37f2efdf149fbcbcd15ea502a3a 100644
--- a/swig-interfaces/fxdefs.i
+++ b/swig-interfaces/fxdefs.i
@@ -253,8 +253,20 @@ typedef FXint                  FXInputHandle;
 
 
 /**********************************  Macros  ***********************************/
+/// Make int out of two shorts
+%rename(MKUINT) _MKUINT;
 
-%{
+/// Make selector from message type and message id
+%rename(FXSEL) _FXSEL;
+
+/// Get type from selector
+%rename(FXSELTYPE) _FXSELTYPE;
+
+/// Get ID from selector
+%rename(FXSELID) _FXSELID;
+
+
+%inline %{
 static FXuint _MKUINT(FXushort l,FXushort h){
   return MKUINT(l,h);
   }
@@ -272,20 +284,29 @@ static FXushort _FXSELID(FXuint s){
   }
 %}
 
-/// Make int out of two shorts
-%name(MKUINT) FXuint _MKUINT(FXushort l,FXushort h);
+/// Make RGB color
+%rename(FXRGB) _FXRGB;
 
-/// Make selector from message type and message id
-%name(FXSEL) FXuint _FXSEL(FXushort type,FXushort id);
+/// Make RGBA color
+%rename(FXRGBA) _FXRGBA;
 
-/// Get type from selector
-%name(FXSELTYPE) FXushort _FXSELTYPE(FXuint s);
+/// Get red value from RGBA color
+%rename(FXREDVAL) _FXREDVAL;
 
-/// Get ID from selector
-%name(FXSELID) FXushort _FXSELID(FXuint s);
+/// Get green value from RGBA color
+%rename(FXGREENVAL) _FXGREENVAL;
+
+/// Get blue value from RGBA color
+%rename(FXBLUEVAL) _FXBLUEVAL;
+
+/// Get alpha value from RGBA color
+%rename(FXALPHAVAL) _FXALPHAVAL;
+
+/// Get component value of RGBA color
+%rename(FXRGBACOMPVAL) _FXRGBACOMPVAL;
 
 // The order in memory is [R G B A] matches that in FXColor
-%{
+%inline %{
 static FXuint _FXRGB(FXuchar r,FXuchar g,FXuchar b){
   return FXRGB(r,g,b);
   }
@@ -315,27 +336,6 @@ static FXuchar _FXRGBACOMPVAL(FXuint rgba,FXuchar comp){
   }
 %}
 
-/// Make RGB color
-%name(FXRGB) FXuint _FXRGB(FXuchar r,FXuchar g,FXuchar b);
-
-/// Make RGBA color
-%name(FXRGBA) FXuint _FXRGBA(FXuchar r,FXuchar g,FXuchar b,FXuchar a);
-
-/// Get red value from RGBA color
-%name(FXREDVAL) FXuchar _FXREDVAL(FXuint rgba);
-
-/// Get green value from RGBA color
-%name(FXGREENVAL) FXuchar _FXGREENVAL(FXuint rgba);
-
-/// Get blue value from RGBA color
-%name(FXBLUEVAL) FXuchar _FXBLUEVAL(FXuint rgba);
-
-/// Get alpha value from RGBA color
-%name(FXALPHAVAL) FXuchar _FXALPHAVAL(FXuint rgba);
-
-/// Get component value of RGBA color
-%name(FXRGBACOMPVAL) FXuchar _FXRGBACOMPVAL(FXuint rgba,FXuchar comp);
-
 /**********************************  Globals  **********************************/
 
 
@@ -404,7 +404,8 @@ VALUE fxparsegeometry(const FXchar *string){
 /// True if executable with given path is a console application
 FXbool fxisconsole(const FXchar *path);
 
-%{
+%rename(fxversion) _fxversion;
+%inline %{
 /// Version number that the library has been compiled with
 VALUE _fxversion(){
   FXString version=FXStringFormat("%d.%d.%d",fxversion[0],fxversion[1],fxversion[2]);
@@ -412,8 +413,5 @@ VALUE _fxversion(){
   }
 %}
 
-%name(fxversion) VALUE _fxversion();
-
 /// Controls tracing level
 unsigned int fxTraceLevel;
-
diff --git a/swig-interfaces/ruby-typemaps.i b/swig-interfaces/ruby-typemaps.i
index 79015a0bb1ca70fec51abe3e3e402aa8e1845b1c..368bef23965f73a01cf9aab3f66fe874dcdf6fe9 100644
--- a/swig-interfaces/ruby-typemaps.i
+++ b/swig-interfaces/ruby-typemaps.i
@@ -127,6 +127,9 @@ inline FXbool to_FXbool(VALUE obj){
     $1 = NULL;
   }
 }
+%typecheck(SWIG_TYPECHECK_VOIDPTR) const void * pix {
+  $1 = (NIL_P($input) || TYPE($input) == T_STRING) ? 1 : 0;
+}
 
 /**
  * Used by constructors for icons and images that require an array
@@ -140,9 +143,9 @@ inline FXbool to_FXbool(VALUE obj){
     if(FXMALLOC(&$1,FXColor,RARRAY_LEN($input))){
       for(long i=0; i<RARRAY_LEN($input); i++){
         $1[i]=static_cast<FXColor>(NUM2UINT(rb_ary_entry($input,i)));
-	}
       }
     }
+  }
 }
 
 /**