From 91b8de8dee3e7ae3c4edc0ab0923b84bba20d9c4 Mon Sep 17 00:00:00 2001
From: Robert Roebling <robert@roebling.de>
Date: Sun, 13 Jun 1999 15:24:01 +0000
Subject: [PATCH]   Added OS/2 patches to wxGTK.   Updated docs.   Added wxMask
 code.   Added Sylvain's newest tree ctrl code and sample.   Corrected wxDC
 background colour (now as wrong as wxMSW).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 acconfig.h                    |   1 +
 configure.in                  |   3 +
 distrib/gtk/copy_src          |   1 +
 docs/gtk/install.txt          | 330 +++++++-----------------
 docs/latex/wx/body.tex        |  31 ++-
 docs/latex/wx/manual.tex      |   6 +-
 docs/latex/wx/mask.tex        |  12 +-
 include/wx/confbase.h         |   6 +-
 include/wx/defs.h             |   3 +-
 include/wx/generic/treectrl.h |  49 +++-
 include/wx/gtk/bitmap.h       |   4 +
 include/wx/gtk1/bitmap.h      |   4 +
 include/wx/string.h           |  14 +-
 samples/image/image.cpp       |   1 +
 samples/treectrl/treetest.cpp |  61 ++++-
 samples/treectrl/treetest.h   |   2 +
 src/common/http.cpp           |   2 +-
 src/common/timercmn.cpp       |  18 +-
 src/common/utilscmn.cpp       |   6 +
 src/generic/treectrl.cpp      | 459 +++++++++++++++++++++++-----------
 src/gtk/app.cpp               |   8 +-
 src/gtk/bitmap.cpp            |  82 ++++--
 src/gtk/dcclient.cpp          |   6 +
 src/gtk/utilsgtk.cpp          |  19 +-
 src/gtk1/app.cpp              |   8 +-
 src/gtk1/bitmap.cpp           |  82 ++++--
 src/gtk1/dcclient.cpp         |   6 +
 src/gtk1/utilsgtk.cpp         |  19 +-
 src/unix/utilsunx.cpp         |  11 +
 29 files changed, 761 insertions(+), 493 deletions(-)

diff --git a/acconfig.h b/acconfig.h
index c27c455c42..2e7bb5b891 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -55,6 +55,7 @@
 #undef __VMS__
 #undef __ULTRIX__
 #undef __DATA_GENERAL__
+#undef __EMX__
 
 /* ------------------------------------------------------------------------ */
 /* compiler options                                                         */
diff --git a/configure.in b/configure.in
index 27c0017d3f..0baafa2141 100644
--- a/configure.in
+++ b/configure.in
@@ -179,6 +179,9 @@ case "${host}" in
     AC_DEFINE(__SVR4__)
     DEFAULT_DEFAULT_wxUSE_MOTIF=1
   ;;
+  *-pc-os2_emx )
+    AC_DEFINE(__EMX__)
+  ;;
   *)
     AC_MSG_ERROR(unknown system type $(host).)
 esac
diff --git a/distrib/gtk/copy_src b/distrib/gtk/copy_src
index ca607d6b66..6e5097b0b6 100755
--- a/distrib/gtk/copy_src
+++ b/distrib/gtk/copy_src
@@ -37,6 +37,7 @@ echo Docs..
 cd docs/gtk
 cp COPYING.LIB ~/wxgtk_dist/wxGTK
 cp install.txt ~/wxgtk_dist/wxGTK/INSTALL.txt
+cp changes.txt ~/wxgtk_dist/wxGTK/CHANGES.txt
 cp licence.txt ~/wxgtk_dist/wxGTK/LICENCE.txt
 cp readme.txt ~/wxgtk_dist/wxGTK/README.txt
 cp todo.txt ~/wxgtk_dist/wxGTK/TODO.txt
diff --git a/docs/gtk/install.txt b/docs/gtk/install.txt
index 706b753d49..25b890d49a 100644
--- a/docs/gtk/install.txt
+++ b/docs/gtk/install.txt
@@ -1,14 +1,13 @@
 
-  !!! When sending bug reports tell us what version of
-      wxWindows you are using (including the beta) and
-      what compiler on what system. One example:
-      wxGTK 2.1 beta 6, egcs 1.1.1, Redhat 5.0 !!!
+  !!! When sending bug reports tell us what version of wxWindows you are 
+      using (including the beta) and what compiler on what system. One 
+      example: wxGTK 2.1 beta 6, egcs 1.1.1, Redhat 5.0 !!!
 
 * The most simple case
 -----------------------
 
-If you compile wxWindows on Unix for the first time and don't 
-like to read install instructions just do (in the base dir):
+If you compile wxWindows on Unix for the first time and don't like to read 
+install instructions just do (in the base dir):
 
 ./configure
 make
@@ -27,17 +26,15 @@ exit
 * The expert case
 -----------------
 
-If you want to do some more serious cross-platform programming
-with wxWindows, such as for GTK and Motif, you can now build
-two complete libraries and use them concurretly. For this end,
-you have to create a directory for each build of wxWindows -
-you may also want to create different versions of wxWindows
-and test them concurrently. Most typically, this would be a
-version configured with --enable-debug_flag and one without.
-Note, that only one build can currenty be installed, so you'd
-have to use local version of the library for that purpose.
-For building three version, one GTK, one Motif and a debug
-version of the GTK source, you'd do this:
+If you want to do some more serious cross-platform programming with wxWindows, 
+such as for GTK and Motif, you can now build two complete libraries and use 
+them concurretly. For this end, you have to create a directory for each build 
+of wxWindows - you may also want to create different versions of wxWindows
+and test them concurrently. Most typically, this would be a version configured 
+with --enable-debug_flag and one without. Note, that only one build can currently 
+be installed, so you'd have to use local version of the library for that purpose.
+For building three version, one GTK, one Motif and a debug version of the GTK 
+source, you'd do this:
 
 md buildmotif
 cd buildmotif
@@ -60,84 +57,70 @@ cd ..
 * The most simple errors
 ------------------------
 
-configure reports, that you don't have GTK 1.X installed
-although you are certainly sure you have. Well, you have
-installed it, but you also have another version of the
-GTK installed, which you may need to removed including
-other versions of glib (and its headers). Also, look
-for the PATH variable and check if it includes the path
-to the correct gtk-config! The check your LDPATH if 
-it points to the correct library. There is no way to
-compile wxGTK if configure doesn't pass this test as
-all this test does is compile and link a GTK program.
-
-You get errors during compilation: The reason is that you
-probably have a broken compiler, which includes almost
-everything that is called gcc. If you use gcc 2.8 you
-have to disable optimsation as the compiler will give
-up with an internal compiler error.
-
-If there is just any way for you to use egcs, use egcs. 
-We are sorry, but we cannot fix gcc.
-
-You get immediate segfault when starting any sample
-or application: This is either due to having compiled
-the library with different flags or options than your
-program - typically you might have the __WXDEBUG__ option
-set for the library but not for your program - or due
-to using a broken compiler (and its optimisation) such
-as GCC 2.8.
+configure reports, that you don't have GTK 1.X installed although you are 
+certainly sure you have. Well, you have installed it, but you also have another 
+version of the GTK installed, which you may need to removed including other 
+versions of glib (and its headers). Also, look for the PATH variable and check 
+if it includes the path to the correct gtk-config! The check your LDPATH if it 
+points to the correct library. There is no way to compile wxGTK if configure 
+doesn't pass this test as all this test does is compile and link a GTK program.
+
+You get errors during compilation: The reason is that you probably have a broken 
+compiler, which includes almost everything that is called gcc. If you use gcc 2.8 
+you have to disable optimsation as the compiler will give up with an internal 
+compiler error.
+
+If there is just any way for you to use egcs, use egcs. We cannot fix gcc.
+
+You get immediate segfault when starting any sample or application: This is either 
+due to having compiled the library with different flags or options than your program - 
+typically you might have the __WXDEBUG__ option set for the library but not for your 
+program - or due to using a broken compiler (and its optimisation) such as GCC 2.8.
 
 * The most simple program
 -------------------------
 
-Now create your super-application myfoo.app and compile anywhere 
-with
+Now create your super-application myfoo.app and compile anywhere with
 
 g++ myfoo.cpp `wx-config --libs --cflags` -o myfoo
 
 * General
 -----------------------
 
-The Unix variants of wxWindows use GNU configure. If you have 
-problems with your make use GNU make instead.
+The Unix variants of wxWindows use GNU configure. If you have problems with your 
+make use GNU make instead.
 
-If you have general problems with installation, read my 
-homepage at 
+If you have general problems with installation, read my homepage at 
 
   http://wesley.informatik.uni-freiburg.de/~wxxt
   
-for newest information. If you still don't have any success,
-please send a bug report to one of our mailing lists (see
-my homepage) INCLUDING A DESCRIPTION OF YOUR SYSTEM AND 
-YOUR PROBLEM, SUCH AS YOUR VERSION OF GTK, WXGTK, WHAT
-DISTRIBUTION YOU USE AND WHAT ERROR WAS REPORTED. I know 
-this has no effect, but I tried...
+for newest information. If you still don't have any success, please send a bug 
+report to one of our mailing lists (see my homepage) INCLUDING A DESCRIPTION OF 
+YOUR SYSTEM AND YOUR PROBLEM, SUCH AS YOUR VERSION OF GTK, WXGTK, WHAT DISTRIBUTION 
+YOU USE AND WHAT ERROR WAS REPORTED. I know this has no effect, but I tried...
 
 * GUI libraries
 -----------------------
 
-wxWindows/GTK requires the GTK+ library to be installed on your system.
-It has to be a stable version, preferebly version 1.2.3. You can use
-GTK 1.0 in connection with wxWindows, but only without Drag'n'Drop.
-wxWindows does work with the 1.1.X versions of the GTK+ library.
+wxWindows/GTK requires the GTK+ library to be installed on your system. It has to 
+be a stable version, preferebly version 1.2.3. You can use GTK 1.0 in connection 
+with wxWindows, but only without Drag'n'Drop. wxWindows does work with the 1.1.X 
+versions of the GTK+ library.
+
+You can get the newest version of the GTK+ from the GTK homepage at:
 
-You can get the newest version of the GTK+ from the GTK homepage
-at
   http://www.gtk.org
   
-We also mirror GTK+ 1.2.1 at my ftp site soon. You'll find information
-about downloading at my homepage.
+We also mirror GTK+ 1.2.1 at my ftp site soon. You'll find information about downloading 
+at my homepage.
   
 * Additional libraries
 -----------------------
 
-wxWindows/Gtk requires a thread library and X libraries
-known to work with threads. This is the case on all
-commercial Unix-Variants and all Linux-Versions that
-are based on glibc 2 except RedHat 5.0 which is broken
-in many aspects. As of writing this, these Linux 
-distributions have correct glibc 2 support:
+wxWindows/Gtk requires a thread library and X libraries known to work with threads. 
+This is the case on all commercial Unix-Variants and all Linux-Versions that are 
+based on glibc 2 except RedHat 5.0 which is broken in many aspects. As of writing 
+this, these Linux distributions have correct glibc 2 support:
 
  - RedHat 5.1
  - Debian 2.0
@@ -154,22 +137,33 @@ make install
 ldconfig
 exit
   
-NB: DO NOT COMPILE WXGTK WITH GCC AND THREADS, SINCE
-ALL PROGRAMS WILL CRASH UPON START-UP! Just always
-use egcs and be happy.
+NB: DO NOT COMPILE WXGTK WITH GCC AND THREADS, SINCE ALL PROGRAMS WILL CRASH UPON 
+START-UP! Just always use egcs and be happy.
 
-* Create your configuration
------------------------------
+* Building wxGTK on OS/2
+--------------------------
 
-Usage:
-	./configure options
+Please send comments and question about the OS/2 installation
+to Andrea Venturoli <a.ventu@flashnet.it> and patches to
+make the installation work (better) to me (Robert Roebling).
 
-If you want to use system's C and C++ compiler,
-set environment variables CC and CCC as
+You'll need OS/2 Warp (4.00FP#6), X-Free86/2 (3.3.3), 
+gtk+ (?), emx (0.9d fix 1), flex (2.5.4), yacc (1.8), 
+korn shell (5.2.13), Autoconf (?),  GNU file utilities (3.6), 
+GNU text utilities (1.3), GNU shell utilites (1.12), m4 (1.4), 
+sed (2.05), grep (2.0), Awk (3.0.3), GNU Make (3.76.1).
 
-	% setenv CC cc
-	% setenv CCC CC
-	% ./configure options
+Open an OS/2 prompt and switch to the directory above.
+First set some global environment variables we need:
+
+SET CXXFLAGS=-Zmtd -D__ST_MT_ERRNO__
+SET OSTYPE=OS2X              
+SET COMSPEC=sh
+
+Notice you can choose whatever you want, if you don't like OS2X.
+
+* Building wxGTK on SGI
+--------------------------
 
 Using the SGI native compilers, it is recommended that you
 also set CFLAGS and CXXFLAGS before running configure. These 
@@ -186,6 +180,19 @@ untested).
 
 The SGI native compiler support has only been tested on Irix 6.5.
 
+* Create your configuration
+-----------------------------
+
+Usage:
+	./configure options
+
+If you want to use system's C and C++ compiler,
+set environment variables CC and CCC as
+
+	% setenv CC cc
+	% setenv CCC CC
+	% ./configure options
+
 to see all the options please use:
 
 	./configure --help
@@ -331,8 +338,6 @@ in the various directories will do the work for you.
 * Creating a new Project
 --------------------------
 
-There are two ways to create your own project:
-
 1) The first way uses the installed libraries and header files
 automatically using wx-config
 
@@ -371,163 +376,10 @@ GNU cc
 and if you have all this then you probably know enough to
 go ahead yourself :-)
 
-** Something about Makefiles
-------------------------------
-
-On general principle it should only contain ONE line, which is as follows:
-
-	include ../../setup/general/makeapp
-
-this will include all the necessary definitions for creating the applications
-
-the only case where you might want to add another line is the following:
-this version of configure also supports creation of source archives of the
-application for easy distribution and updates to newer version of wxWindows.
-    For this purpose all files in the application-directory will be put into
-a gziped tar-file in the full notation user/<your application>/*
-if you want to include some other files that you want "more visible", like
-a README.<yourApp> or a shell script for easy 
-compilation/installation/distribution, then you have to add a variable
-
-	DISTRIBUTE_ADDITIONAL=<your files>
-
-to the Makefile.
-So it would look like this:
-
-	DISTRIBUTE_ADDITIONAL=README.TheApp
-	include ../../setup/general/makeapp
-
-As we have already talked about distribution the command to create a 
-distribution is:
-
-	make distrib
-
-NOTE: If you are in the base directory of wxWindows it will create 
-distribution packages for wxWindows as well as for all packages in the
-user directory.
-    So if you want to create only packages for the files in user,
-then go to the directory other and type:
-
-	make distrib
-
-or if you only want one application to be created then
-enter the specific directory and type there:
-make distrib
-
-All the distribution files will be put in the directory
-distrib at the base of the wxWindows-tree (where also configure
-and template.mak can be found).
-
-** Something about Makefile.in
---------------------------------
-
-As you have already seen with Makefile, configure makes a lot of use
-if the include statement in make to keep the Makefiles as simple as 
-possible.
-
-So basically there are only variables to define and then a include command.
-Exception to this rule is if you have special rules for some stuff...
-These rules should go AFTER the include statement!!!
-
-so the general header looks like this:
-
-	# wxWindows base directory
-	WXBASEDIR=@WXBASEDIR@
-	# set the OS type for compilation
-	OS=@OS@
-	# compile a library only
-	RULE=bin
-
-and the general footer will look like this:
-
-	# include the definitions now
-	include ../../../template.mak
-
-the key variable is RULE, which defines what make should create
-in this directory.
-
-here are some examples:
-
-  RULE	  description              
-  ===========================================================================
-  bin	  creates a local binary (for a global binary prefix bin with g)
-  	  additional variables needed:
-  		BIN_TARGET	this gives the name of your application
-  		BIN_OBJ		this gives the object files needed to
-  				link the application
-  	  optional variables are:
-  		BIN_SRC		this gives the list of c/c++ files for
-  				which dependencies will be checked.
-  				(This can be achieved with: make depend)
-  		BIN_LINK	this gives commands for additional
-  				libraries needed to link the application
-  ---------------------------------------------------------------------------
-  bin2	  creates two local binaries (for global binaries prefix bin2 with g)
-  	  in addition to the variables specified above you MUST also
-  	  provide the same variables with BIN2_ instead of BIN_
-  ---------------------------------------------------------------------------
-  lib	  creates a local library (for a global binary prefix bin with g)
-  	  additional variables needed:
-  		LIB_TARGET	this gives the name of your library
-  		LIB_OBJ		this gives the object files needed for
-  				the library to be build.
-  	  optional variables are:
-  		LIB_SRC		this gives the list of c/c++ files for
-  				which dependencies will be checked.
-  	  libbin and libgbin are also possible and will need in addition
-  	  the variables from bin
-  ---------------------------------------------------------------------------
-  gslib	  is similar to lib, but it creates a shared library if the system
-  	  supports it.
-  	  additional variables needed:
-  		LIB_MAJOR	major number of the shared library
-  		LIB_MINOR	minor number of the shared library
-  ---------------------------------------------------------------------------
-  other additional variables:
-
-  	  ADD_COMPILE	   define additional includes/defines that
-  			   are needed to compile the object files
-  			   (if you need to reference some directory
-  			   utils - like wxGrid -, then please 
-  			   reference them with the variables defined
-  			   in template.mak - e.g.: $(SRCDIR),$(UTILS),
-  			   $(SAMPLES),$(OTHERS))
-
-  	  NEEDED_DEFINES   lists all the defines that HAVE to be set in
-  			   /include/wx/setup.h to compile correctly.
-
-	  SRC_DIR	   lists all directories that are needed to
-			   compile. (i.e: lists all the directories,
-			   where there are source-files.) But it is 
-			   also needed to clean an object and for 
-			   machines, for which make does not support 
-			   VPATH
-
-currently there are the following compiling rules provided:
-object files are created for the following file extensions:
-.c .cc .cpp
-
-Please have a closer look at the Makefiles in this distribution.
-
-* Platforms configure is working with
----------------------------------------
-
-Please report build succes on any machine. Especially non-
-Linux operating systems (which I don't have).
-
-Original author of the autoconf system for wxxt-1.66 and for this INSTALL
-file:
-
-	Martin Sperl	sperl@dsn.ast.univie.ac.at
-	
-Ported to wxGTK 0.1:
-
-	Wolfram Gloger  wmglo@dent.med.uni-muenchen.de
-
-Thanks alot to both of them.
+----------------------
 
 In the hope that it will be useful,
 
-        Robert Roebling roebling@sun2.ruf.uni-freiburg.de
+        Robert Roebling <roebling@sun2.ruf.uni-freiburg.de>
 	
 	
diff --git a/docs/latex/wx/body.tex b/docs/latex/wx/body.tex
index 36511120a4..bd979202d7 100644
--- a/docs/latex/wx/body.tex
+++ b/docs/latex/wx/body.tex
@@ -8,13 +8,14 @@
 wxWindows is a C++ framework providing GUI (Graphical User
 Interface) and other facilities on more than one platform.  Version 2.0 currently
 supports MS Windows (16-bit, Windows 95 and Windows NT), Unix with GTK+, and Unix with Motif.
-A Mac port is in an advanced state.
+A Mac port is in an advanced state, an OS/2 port and a port to the MGL graphics library
+have been started.
 
 wxWindows was originally developed at the Artificial Intelligence
 Applications Institute, University of Edinburgh, for internal use.
 wxWindows has been released into the public domain in the hope
 that others will also find it useful. Version 2.0 is written and
-maintained by Julian Smart, Robert Roebling and others.
+maintained by Julian Smart, Robert Roebling, Vadim Zeitlin and others.
 
 This manual discusses wxWindows in the context of multi-platform
 development.\helpignore{For more detail on the wxWindows version 2.0 API
@@ -182,8 +183,8 @@ Metrowerks CodeWarrior.
 (b) Unix:
 
 \begin{enumerate}\itemsep=0pt
-\item Almost any C++ compiler, including GNU C++.
-\item Almost any Unix workstation, and one of: GTK+ 1.0, Motif 1.2 or higher, Lesstif.
+\item Almost any C++ compiler, including GNU C++ (EGCS 1.1.1 or above).
+\item Almost any Unix workstation, and one of: GTK+ 1.0, GTK+ 1.2, Motif 1.2 or higher, Lesstif.
 \item At least 60 MB of disk space.
 \end{enumerate}
 
@@ -356,7 +357,7 @@ STACKSIZE    8192
 The only lines which will usually have to be changed per application are
 NAME and DESCRIPTION.
 
-\subsection{Allocating and deleting wxWindows objects}
+\section{Allocating and deleting wxWindows objects}
 
 In general, classes derived from wxWindow must dynamically allocated
 with {\it new} and deleted with {\it delete}. If you delete a window,
@@ -386,6 +387,26 @@ make calls like wxDC::SetPen(wxNullPen) or wxDC::SelectObject(wxNullBitmap) befo
 a drawing object that may be in use. Code that doesn't do this will probably work
 fine on some platforms, and then fail under Windows.
 
+\section{Architecture dependency}
+
+A problem which sometimes arises from writing multi-platform programs is that
+the basic C types are not defiend the same on all platforms. This holds true
+for both the length in bits of the standard types (such as int and long) as 
+well as their byte order, which might be little endian (typically
+on Intel computers) or big endian (typically on some Unix workstations). wxWindows
+defines types and macros that make it easy to write architecture independent
+code. The types are:
+
+wxInt32, wxInt16, wxInt8, wxUint32, wxUint16 = wxWord, wxUint8 = wxByte
+
+where wxInt32 stands for a 32-bit signed integer type etc. You can also check
+which architecture the program is compiled on using the wxBYTE\_ORDER define
+which is either wxBIG\_ENDIAN or wxLITTLE\_ENDIAN (in the future maybe wxPDP\_ENDIAN
+as well).
+
+The macros handling bit-swapping with respect to the applications endianness
+are described in the \helpref{Macros}{macros} section.
+
 \section{Conditional compilation}
 
 One of the purposes of wxWindows is to reduce the need for conditional
diff --git a/docs/latex/wx/manual.tex b/docs/latex/wx/manual.tex
index 300ed8d6a1..2d156ddd2b 100644
--- a/docs/latex/wx/manual.tex
+++ b/docs/latex/wx/manual.tex
@@ -25,12 +25,12 @@
 %\special{!/@scaleunit 1 def}
 \parskip=10pt
 \parindent=0pt
-\title{User Manual for wxWindows 2.0: a portable C++ GUI toolkit}
+\title{User Manual for wxWindows 2.1: a portable C++ GUI toolkit}
 \winhelponly{\author{by Julian Smart et al
 %\winhelponly{\\$$\image{1cm;0cm}{wxwin.wmf}$$}
 }}
-\winhelpignore{\author{Julian Smart et al}
-\date{February 28th 1999}
+\winhelpignore{\author{Julian Smart, Robert Roebling, Vadim Zeitlin et al}
+\date{June 12th 1999}
 }
 \makeindex
 \begin{document}
diff --git a/docs/latex/wx/mask.tex b/docs/latex/wx/mask.tex
index 8933486d1c..cfe8fc68d1 100644
--- a/docs/latex/wx/mask.tex
+++ b/docs/latex/wx/mask.tex
@@ -35,11 +35,13 @@ Constructs a mask from a monochrome bitmap.
 
 \func{}{wxMask}{\param{const wxBitmap\& }{bitmap}, \param{const wxColour\& }{colour}}
 
-Constructs a mask from a bitmap and a colour that indicates the background.
+Constructs a mask from a bitmap and a colour that indicates the background. Not
+yet implemented for GTK.
 
 \func{}{wxMask}{\param{const wxBitmap\& }{bitmap}, \param{int}{ index}}
 
-Constructs a mask from a bitmap and a palette index that indicates the background.
+Constructs a mask from a bitmap and a palette index that indicates the background. Not
+yet implemented for GTK.
 
 \wxheading{Parameters}
 
@@ -63,11 +65,13 @@ Constructs a mask from a monochrome bitmap.
 
 \func{bool}{Create}{\param{const wxBitmap\& }{bitmap}, \param{const wxColour\& }{colour}}
 
-Constructs a mask from a bitmap and a colour that indicates the background.
+Constructs a mask from a bitmap and a colour that indicates the background. Not
+yet implemented for GTK.
 
 \func{bool}{Create}{\param{const wxBitmap\& }{bitmap}, \param{int}{ index}}
 
-Constructs a mask from a bitmap and a palette index that indicates the background.
+Constructs a mask from a bitmap and a palette index that indicates the background. Not
+yet implemented for GTK.
 
 \wxheading{Parameters}
 
diff --git a/include/wx/confbase.h b/include/wx/confbase.h
index 7e6cfeacf2..483c9d0a80 100644
--- a/include/wx/confbase.h
+++ b/include/wx/confbase.h
@@ -246,11 +246,11 @@ public:
 
 protected:
   static bool IsImmutable(const wxString& key)
-  #ifndef __WXMAC__
+#if !defined(__WXMAC__) && !defined(__EMX__)
     { return !key.IsEmpty() && key[0u] == wxCONFIG_IMMUTABLE_PREFIX; }
-  #else
+#else
     { return !key.IsEmpty() && key[0ul] == wxCONFIG_IMMUTABLE_PREFIX; }
-  #endif
+#endif
 
 private:
   // are we doing automatic environment variable expansion?
diff --git a/include/wx/defs.h b/include/wx/defs.h
index 9bdeb7b0f6..f0d84c9a8b 100644
--- a/include/wx/defs.h
+++ b/include/wx/defs.h
@@ -28,7 +28,8 @@
 // OS
 #if defined(__unix) || defined(__unix__) || defined(____SVR4____) || \
     defined(__LINUX__) || defined(__sgi ) || \
-    defined(__hpux) || defined(sun) || defined(__SUN__) || defined(_AIX)
+    defined(__hpux) || defined(sun) || defined(__SUN__) || defined(_AIX) || \
+    defined(__EMX__)
 
     #ifndef __UNIX__
         #define __UNIX__
diff --git a/include/wx/generic/treectrl.h b/include/wx/generic/treectrl.h
index 9e57b50785..6a8a31c707 100644
--- a/include/wx/generic/treectrl.h
+++ b/include/wx/generic/treectrl.h
@@ -29,6 +29,14 @@ WXDLLEXPORT_DATA(extern const char*) wxTreeCtrlNameStr;
 #include "wx/scrolwin.h"
 #include "wx/textctrl.h"
 #include "wx/pen.h"
+#include "wx/dynarray.h"
+
+#ifndef wxTR_SINGLE
+#define wxTR_SINGLE                 0x0000
+#define wxTR_MULTIPLE               0x0020
+#define wxTR_EXTENDED               0x0040
+#define wxTR_HAS_VARIABLE_ROW_HIGHT 0x0080
+#endif
 
 // -----------------------------------------------------------------------------
 // constants
@@ -36,11 +44,31 @@ WXDLLEXPORT_DATA(extern const char*) wxTreeCtrlNameStr;
 
 // values for the `flags' parameter of wxTreeCtrl::HitTest() which determine
 // where exactly the specified point is situated:
+
+static const int wxTREE_HITTEST_ABOVE            = 0x0001;
+static const int wxTREE_HITTEST_BELOW            = 0x0002;
 static const int wxTREE_HITTEST_NOWHERE          = 0x0004;
+    // on the button associated with an item.
+static const int wxTREE_HITTEST_ONITEMBUTTON     = 0x0008;
     // on the bitmap associated with an item.
-static const int wxTREE_HITTEST_ONITEMICON       = 0x0020;
+static const int wxTREE_HITTEST_ONITEMICON       = 0x0010;
+    // on the ident associated with an item.
+static const int wxTREE_HITTEST_ONITEMIDENT      = 0x0020;
+    // on the label (string) associated with an item.
+static const int wxTREE_HITTEST_ONITEMLABEL      = 0x0040;
+    // on the right of the label associated with an item.
+static const int wxTREE_HITTEST_ONITEMRIGHT      = 0x0080;
     // on the label (string) associated with an item.
-static const int wxTREE_HITTEST_ONITEMLABEL      = 0x0080;
+//static const int wxTREE_HITTEST_ONITEMSTATEICON  = 0x0100;
+    // on the left of the wxTreeCtrl.
+static const int wxTREE_HITTEST_TOLEFT           = 0x0200;
+    // on the right of the wxTreeCtrl.
+static const int wxTREE_HITTEST_TORIGHT          = 0x0400;
+    // on the upper part (first half) of the item.
+static const int wxTREE_HITTEST_ONITEMUPPERPART  = 0x0800;
+    // on the lower part (second half) of the item.
+static const int wxTREE_HITTEST_ONITEMLOWERPART  = 0x1000;
+
     // anywhere on the item
 static const int wxTREE_HITTEST_ONITEM  = wxTREE_HITTEST_ONITEMICON |
                                           wxTREE_HITTEST_ONITEMLABEL;
@@ -84,6 +112,8 @@ public:
     wxGenericTreeItem *m_pItem;
 };
 
+WX_DECLARE_OBJARRAY(wxTreeItemId, wxArrayTreeItemIds);
+
 // ----------------------------------------------------------------------------
 // wxTreeItemData is some (arbitrary) user class associated with some item.
 //
@@ -324,7 +354,7 @@ public:
     wxTreeItemId GetSelection() const { return m_current; }
 
         // get the items currently selected, return the number of such item
-  //size_t GetSelections(wxArrayTreeItems*) const;
+    size_t GetSelections(wxArrayTreeItemIds&) const;
 
         // get the parent of this item (may return NULL if root)
     wxTreeItemId GetParent(const wxTreeItemId& item) const;
@@ -405,7 +435,7 @@ public:
     void Unselect();
     void UnselectAll();
         // select this item
-    void SelectItem(const wxTreeItemId& item, bool unselect_others=TRUE, bool extended_select=FALSE);
+    void SelectItem(const wxTreeItemId& item, bool unselect_others=true, bool extended_select=false);
         // make sure this item is visible (expanding the parent item and/or
         // scrolling to this item if necessary)
     void EnsureVisible(const wxTreeItemId& item);
@@ -454,9 +484,15 @@ public:
     // implementation
     void SendDeleteEvent(wxGenericTreeItem *itemBeingDeleted);
 
+    // Draw Special Information
+    void DrawBorder(wxTreeItemId& item);
+    void DrawLine(wxTreeItemId& item, bool below);
+    
 protected:
+    friend class wxGenericTreeItem;
+
     wxGenericTreeItem   *m_anchor;
-    wxGenericTreeItem   *m_current;
+    wxGenericTreeItem   *m_current, *m_key_current;
     bool                 m_hasFocus;
     bool                 m_dirty;
     int                  m_xScroll,m_yScroll;
@@ -480,15 +516,18 @@ protected:
                               wxTreeItemData *data);
 
     void AdjustMyScrollbars();
+    int  GetLineHeight(wxGenericTreeItem *item) const;
     void PaintLevel( wxGenericTreeItem *item, wxDC& dc, int level, int &y );
     void PaintItem( wxGenericTreeItem *item, wxDC& dc);
 
     void CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y );
     void CalculatePositions();
+    void CalculateSize( wxGenericTreeItem *item, wxDC &dc );
 
     void RefreshSubtree( wxGenericTreeItem *item );
     void RefreshLine( wxGenericTreeItem *item );
 
+    void FillArray(wxGenericTreeItem*, wxArrayTreeItemIds&) const;
     void SelectItemRange( wxGenericTreeItem *item1, wxGenericTreeItem *item2 );
     bool TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select);
     bool TagNextChildren(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select);
diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h
index 61245d92c1..b49423e6b1 100644
--- a/include/wx/gtk/bitmap.h
+++ b/include/wx/gtk/bitmap.h
@@ -41,6 +41,10 @@ public:
   wxMask( const wxBitmap& bitmap, int paletteIndex );
   wxMask( const wxBitmap& bitmap );
   ~wxMask();
+  
+  bool Create( const wxBitmap& bitmap, const wxColour& colour );
+  bool Create( const wxBitmap& bitmap, int paletteIndex );
+  bool Create( const wxBitmap& bitmap );
 
  // implementation
 
diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h
index 61245d92c1..b49423e6b1 100644
--- a/include/wx/gtk1/bitmap.h
+++ b/include/wx/gtk1/bitmap.h
@@ -41,6 +41,10 @@ public:
   wxMask( const wxBitmap& bitmap, int paletteIndex );
   wxMask( const wxBitmap& bitmap );
   ~wxMask();
+  
+  bool Create( const wxBitmap& bitmap, const wxColour& colour );
+  bool Create( const wxBitmap& bitmap, int paletteIndex );
+  bool Create( const wxBitmap& bitmap );
 
  // implementation
 
diff --git a/include/wx/string.h b/include/wx/string.h
index 8948591e53..ec5cc09910 100644
--- a/include/wx/string.h
+++ b/include/wx/string.h
@@ -20,6 +20,10 @@
     #include <ctype.h>
 #endif
 
+#ifdef __EMX__
+    #include <std.h>
+#endif
+
 #include <string.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -89,17 +93,19 @@ inline size_t WXDLLEXPORT Strlen(const char *psz)
 // portable strcasecmp/_stricmp
 inline int WXDLLEXPORT Stricmp(const char *psz1, const char *psz2)
 {
-#if     defined(__VISUALC__) || ( defined(__MWERKS__) && defined(__INTEL__) )
+#if defined(__VISUALC__) || ( defined(__MWERKS__) && defined(__INTEL__) )
   return _stricmp(psz1, psz2);
-#elif     defined(__SC__)
+#elif defined(__SC__)
   return _stricmp(psz1, psz2);
-#elif     defined(__SALFORDC__)
+#elif defined(__SALFORDC__)
   return stricmp(psz1, psz2);
 #elif defined(__BORLANDC__)
   return stricmp(psz1, psz2);
 #elif defined(__WATCOMC__)
   return stricmp(psz1, psz2);
-#elif   defined(__UNIX__) || defined(__GNUWIN32__)
+#elif defined(__EMX__)
+  return stricmp(psz1, psz2);
+#elif defined(__UNIX__) || defined(__GNUWIN32__)
   return strcasecmp(psz1, psz2);
 #elif defined(__MWERKS__) && !defined(__INTEL__)
   register char c1, c2;
diff --git a/samples/image/image.cpp b/samples/image/image.cpp
index 36879ba4c8..80d07d6a17 100644
--- a/samples/image/image.cpp
+++ b/samples/image/image.cpp
@@ -200,6 +200,7 @@ void MyCanvas::CreateAntiAliasedBitmap()
   dc.DrawText( "And a Rectangle.", 20, 60 );
   
   dc.SetBrush( *wxRED_BRUSH );
+  dc.SetPen( *wxTRANSPARENT_PEN );
   dc.DrawRoundedRectangle( 20, 100, 200, 180, 20 );
   
   wxImage original( bitmap );
diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp
index 93d51cd80d..9aeb981421 100644
--- a/samples/treectrl/treetest.cpp
+++ b/samples/treectrl/treetest.cpp
@@ -25,15 +25,9 @@
   #include "wx/wx.h"
 #endif
 
-// under Windows the icons are in the .rc file
-#ifndef __WXMSW__
-  #include "icon1.xpm"
-  #include "icon2.xpm"
-  #include "mondrian.xpm"
-#endif
-
 #include "wx/log.h"
 
+#include "wx/image.h"
 #include "wx/imaglist.h"
 #include "wx/treectrl.h"
 
@@ -41,6 +35,18 @@
 
 #include "treetest.h"
 
+#define USE_TR_HAS_VARIABLE_ROW_HIGHT 1
+
+// under Windows the icons are in the .rc file
+#ifndef __WXMSW__
+#if !USE_TR_HAS_VARIABLE_ROW_HIGHT
+  #include "icon1.xpm"
+#endif
+  #include "icon2.xpm"
+  #include "mondrian.xpm"
+#endif
+
+
 // verify that the item is ok and insult the user if it is not
 #define CHECK_ITEM( item ) if ( !item.IsOk() ) {                            \
                              wxMessageBox("Please select some item first!", \
@@ -54,6 +60,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(TreeTest_Quit, MyFrame::OnQuit)
     EVT_MENU(TreeTest_About, MyFrame::OnAbout)
     EVT_MENU(TreeTest_Dump, MyFrame::OnDump)
+    EVT_MENU(TreeTest_Dump_Selected, MyFrame::OnDumpSelected)
     EVT_MENU(TreeTest_Rename, MyFrame::OnRename)
     EVT_MENU(TreeTest_Sort, MyFrame::OnSort)
     EVT_MENU(TreeTest_SortRev, MyFrame::OnSortRev)
@@ -146,9 +153,11 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
     tree_menu->Append(TreeTest_IncSpacing, "Add 5 points to spacing\tCtrl-I");
     tree_menu->Append(TreeTest_DecSpacing, "Reduce spacing by 5 points\tCtrl-R");
 
-    item_menu->Append(TreeTest_Dump, "&Dump item children");
     item_menu->AppendSeparator();
+    item_menu->Append(TreeTest_Dump, "&Dump item children");
+    item_menu->Append(TreeTest_Dump_Selected, "Dump selected items\tAlt-S");
     item_menu->Append(TreeTest_Rename, "&Rename item...");
+
     item_menu->AppendSeparator();
     item_menu->Append(TreeTest_Bold, "Make item &bold");
     item_menu->Append(TreeTest_UnBold, "Make item &not bold");
@@ -161,9 +170,12 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
 
     m_treeCtrl = new MyTreeCtrl(this, TreeTest_Ctrl,
                                 wxDefaultPosition, wxDefaultSize,
-                                wxTR_HAS_BUTTONS | wxSUNKEN_BORDER
-				| wxTR_MULTIPLE
-				);
+                                wxTR_HAS_BUTTONS | 
+				wxTR_MULTIPLE |
+#if USE_TR_HAS_VARIABLE_ROW_HIGHT
+				wxTR_HAS_VARIABLE_ROW_HIGHT |
+#endif
+				wxSUNKEN_BORDER);
     wxTextCtrl *textCtrl = new wxTextCtrl(this, -1, "",
                                 wxDefaultPosition, wxDefaultSize,
                                 wxTE_MULTILINE | wxSUNKEN_BORDER);
@@ -250,6 +262,18 @@ void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event))
     m_treeCtrl->GetItemsRecursively(root, -1);
 }
 
+void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event))
+{
+    wxArrayTreeItemIds array;
+
+    m_treeCtrl->GetSelections(array);
+    size_t nos=array.Count();
+    wxLogMessage(wxString("items selected : ")<< (int)nos);
+
+    for (size_t n=0; n<nos; ++n)
+      wxLogMessage(m_treeCtrl->GetItemText(array.Item(n)));
+}
+
 void MyFrame::DoSetBold(bool bold)
 {
     wxTreeItemId item = m_treeCtrl->GetSelection();
@@ -346,6 +370,13 @@ MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id,
                        long style)
           : wxTreeCtrl(parent, id, pos, size, style)
 {
+#if USE_TR_HAS_VARIABLE_ROW_HIGHT
+    wxImage::AddHandler(new wxJPEGHandler); 
+    wxImage image;
+
+    image.LoadFile(wxString("horse.jpg"), wxBITMAP_TYPE_JPEG );
+#endif
+
     m_reverseSort = FALSE;
 
     // Make an image list containing small icons
@@ -355,10 +386,18 @@ MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id,
 #if defined(__WXMSW__) && defined(__WIN16__)
     // This is required in 16-bit Windows mode only because we can't load a specific (16x16)
     // icon image, so it comes out stretched
+#  if USE_TR_HAS_VARIABLE_ROW_HIGHT
+    m_imageListNormal->Add(image.ConvertToBitmap());
+#  else
     m_imageListNormal->Add(wxBitmap("bitmap1", wxBITMAP_TYPE_BMP_RESOURCE));
+#  endif
     m_imageListNormal->Add(wxBitmap("bitmap2", wxBITMAP_TYPE_BMP_RESOURCE));
 #else
+#  if USE_TR_HAS_VARIABLE_ROW_HIGHT
+    m_imageListNormal->Add(image.ConvertToBitmap());
+#  else
     m_imageListNormal->Add(wxICON(icon1));
+#  endif
     m_imageListNormal->Add(wxICON(icon2));
 #endif
 
diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h
index c3ce883347..fdd2e9c720 100644
--- a/samples/treectrl/treetest.h
+++ b/samples/treectrl/treetest.h
@@ -102,6 +102,7 @@ public:
     void OnAbout(wxCommandEvent& event);
 
     void OnDump(wxCommandEvent& event);
+    void OnDumpSelected(wxCommandEvent& event);
     void OnDelete(wxCommandEvent& event);
     void OnDeleteChildren(wxCommandEvent& event);
     void OnDeleteAll(wxCommandEvent& event);
@@ -141,6 +142,7 @@ enum
     TreeTest_Quit,
     TreeTest_About,
     TreeTest_Dump,
+    TreeTest_Dump_Selected,
     TreeTest_Sort,
     TreeTest_SortRev,
     TreeTest_Bold,
diff --git a/src/common/http.cpp b/src/common/http.cpp
index 779472541d..771f024806 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -130,7 +130,7 @@ bool wxHTTP::ParseHeaders()
       break;
 
     tokenzr.SetString(line, " :\t\n\r");
-    if (!tokenzr.HasMoreToken())
+    if (!tokenzr.HasMoreTokens())
       return FALSE;
 
     wxString left_str = tokenzr.GetNextToken();
diff --git a/src/common/timercmn.cpp b/src/common/timercmn.cpp
index 7c1f7ccdc3..3a0f166553 100644
--- a/src/common/timercmn.cpp
+++ b/src/common/timercmn.cpp
@@ -44,7 +44,7 @@
 
 #if defined(__linux__) || defined(__SVR4__) || defined(__SYSV__) || defined(__SGI__) || \
     defined(__ALPHA__) || defined(__GNUWIN32__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
-    defined(__SALFORDC__)
+    defined(__SALFORDC__) || defined(__EMX__)
 #include <sys/time.h>
 #endif
 
@@ -73,15 +73,17 @@ extern "C" int gettimeofday(struct timeval *tp, void *);
 long wxStartTime = 0;
 void wxStartTimer(void)
 {
-#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
+#if defined(__EMX__) || defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || \
+    (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
   struct timeval tp;
-#if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
+#if defined(__EMX__) || defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
   gettimeofday(&tp, (struct timezone *)NULL);
 #else
   gettimeofday(&tp);
 #endif
   wxStartTime = 1000*tp.tv_sec + tp.tv_usec/1000;
-#elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__) || defined(__MWERKS__) || defined(__FreeBSD__) ) 
+#elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || \
+       defined(__MINGW32__) || defined(__MWERKS__) || defined(__FreeBSD__) ) 
   time_t t0;
   struct tm *tp;
   time(&t0);
@@ -97,7 +99,8 @@ void wxStartTimer(void)
 // Returns elapsed time in milliseconds
 long wxGetElapsedTime(bool resetTimer)
 {
-#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
+#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || \
+    (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
   struct timeval tp;
 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
   gettimeofday(&tp, (struct timezone *)NULL);
@@ -108,7 +111,8 @@ long wxGetElapsedTime(bool resetTimer)
   long newTime = 1000*tp.tv_sec + tp.tv_usec / 1000;
   if (resetTimer)
     wxStartTime = newTime;
-#elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__)|| defined(__MWERKS__) || defined(__FreeBSD__))
+#elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || \
+  defined(__MINGW32__)|| defined(__MWERKS__) || defined(__FreeBSD__))
   time_t t0;
   struct tm *tp;
   time(&t0);
@@ -150,7 +154,7 @@ bool wxGetLocalTime(long *timeZone, int *dstObserved)
   *dstObserved = tp->tm_isdst;
 #else
 
-#if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__))\
+#if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__)) \
    && !defined(__GNUWIN32__) && !defined(__MWERKS__) )
 #if defined(__BORLANDC__)
   /* Borland uses underscores */
diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp
index 8ad2a9d596..68f0d945f5 100644
--- a/src/common/utilscmn.cpp
+++ b/src/common/utilscmn.cpp
@@ -168,6 +168,12 @@ int strncasecmp(const char *str_1, const char *str_2, size_t maxchar)
 #endif
 
 #else
+
+#ifdef __EMX__
+#define strcasecmp stricmp
+#define strncasecmp strnicmp
+#endif
+
 // This declaration is missing in SunOS!
 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp
index b3bdc84ab7..181c65b069 100644
--- a/src/generic/treectrl.cpp
+++ b/src/generic/treectrl.cpp
@@ -34,6 +34,7 @@
 #include "wx/log.h"
 #include "wx/intl.h"
 #include "wx/dynarray.h"
+#include "wx/arrimpl.cpp"
 #include "wx/dcclient.h"
 #include "wx/msgdlg.h"
 
@@ -43,7 +44,8 @@
 
 class WXDLLEXPORT wxGenericTreeItem;
 
-WX_DEFINE_ARRAY(wxGenericTreeItem *, wxArrayTreeItems);
+WX_DEFINE_ARRAY(wxGenericTreeItem *, wxArrayGenericTreeItems);
+WX_DEFINE_OBJARRAY(wxArrayTreeItemIds);
 
 // -----------------------------------------------------------------------------
 // private classes
@@ -64,14 +66,14 @@ public:
   ~wxGenericTreeItem();
 
   // trivial accessors
-  wxArrayTreeItems& GetChildren() { return m_children; }
+  wxArrayGenericTreeItems& GetChildren() { return m_children; }
 
   const wxString& GetText() const { return m_text; }
   int GetImage() const { return m_image; }
   int GetSelectedImage() const { return m_selImage; }
   wxTreeItemData *GetData() const { return m_data; }
 
-  void SetText( const wxString &text, wxDC& dc );
+  void SetText( const wxString &text );
   void SetImage(int image) { m_image = image; }
   void SetSelectedImage(int image) { m_selImage = image; }
   void SetData(wxTreeItemData *data) { m_data = data; }
@@ -83,11 +85,16 @@ public:
   int GetX() const { return m_x; }
   int GetY() const { return m_y; }
 
-  void SetHeight(int h) { m_text_height = h; }
-
   void SetX(int x) { m_x = x; }
   void SetY(int y) { m_y = y; }
 
+  int  GetHeight() const { return m_height; }
+  int  GetWidth()  const { return m_width; }
+
+  void SetHeight(int h) { m_height = h; }
+  void SetWidth(int w) { m_width = w; }
+
+
   wxGenericTreeItem *GetParent() const { return m_parent; }
 
   // operations
@@ -104,12 +111,12 @@ public:
     { m_children.Insert(child, index); }
 
   void SetCross( int x, int y );
-  void GetSize( int &x, int &y );
+  void GetSize( int &x, int &y, const wxTreeCtrl* );
 
   // return the item at given position (or NULL if no item), onButton is TRUE
   // if the point belongs to the item's button, otherwise it lies on the
   // button's label
-  wxGenericTreeItem *HitTest( const wxPoint& point, bool &onButton );
+  wxGenericTreeItem *HitTest( const wxPoint& point, const wxTreeCtrl *, int &flags);
 
   void Expand() { m_isCollapsed = FALSE; }
   void Collapse() { m_isCollapsed = TRUE; }
@@ -139,10 +146,10 @@ private:
   int                 m_isBold      :1; // render the label in bold font
 
   int                 m_x, m_y;
-  long                m_text_height, m_text_width;
+  long                m_height, m_width;
   int                 m_xCross, m_yCross;
   int                 m_level;
-  wxArrayTreeItems    m_children;
+  wxArrayGenericTreeItems m_children;
   wxGenericTreeItem  *m_parent;
 };
 
@@ -150,6 +157,7 @@ private:
 // implementation
 // =============================================================================
 
+#define PIXELS_PER_UNIT 10
 // -----------------------------------------------------------------------------
 // wxTreeEvent
 // -----------------------------------------------------------------------------
@@ -189,7 +197,11 @@ wxGenericTreeItem::wxGenericTreeItem(wxGenericTreeItem *parent,
 
   m_parent = parent;
 
-  dc.GetTextExtent( m_text, &m_text_width, &m_text_height );
+  dc.GetTextExtent( m_text, &m_width, &m_height );
+  // TODO : Add the width of the image
+  // PB   : We don't know which image is shown (image, selImage)
+  //        We don't even know imageList from the treectrl this item belongs to !!!
+  // At this point m_width doesn't mean much, this can be remove !
 }
 
 wxGenericTreeItem::~wxGenericTreeItem()
@@ -218,11 +230,9 @@ void wxGenericTreeItem::DeleteChildren(wxTreeCtrl *tree)
   m_children.Empty();
 }
 
-void wxGenericTreeItem::SetText( const wxString &text, wxDC& dc )
+void wxGenericTreeItem::SetText( const wxString &text )
 {
   m_text = text;
-
-  dc.GetTextExtent( m_text, &m_text_width, &m_text_height );
 }
 
 void wxGenericTreeItem::Reset()
@@ -232,7 +242,7 @@ void wxGenericTreeItem::Reset()
   m_selImage = -1;
   m_data = NULL;
   m_x = m_y =
-  m_text_height = m_text_width = 0;
+  m_height = m_width = 0;
   m_xCross =
   m_yCross = 0;
 
@@ -251,7 +261,7 @@ size_t wxGenericTreeItem::GetChildrenCount(bool recursively) const
     return count;
 
   size_t total = count;
-  for ( size_t n = 0; n < count; n++ )
+  for ( size_t n = 0; n < count; ++n )
   {
     total += m_children[n]->GetChildrenCount();
   }
@@ -265,47 +275,60 @@ void wxGenericTreeItem::SetCross( int x, int y )
   m_yCross = y;
 }
 
-void wxGenericTreeItem::GetSize( int &x, int &y )
+void wxGenericTreeItem::GetSize( int &x, int &y, const wxTreeCtrl *theTree )
 {
-  if ( y < m_y ) y = m_y;
-  int width = m_x +  m_text_width;
-  if (width > x) x = width;
+  int bottomY=m_y+theTree->GetLineHeight(this);
+  if ( y < bottomY ) y = bottomY;
+  int width = m_x +  m_width;
+  if ( x < width ) x = width;
 
   if (IsExpanded())
   {
     size_t count = m_children.Count();
-    for ( size_t n = 0; n < count; n++ )
+    for ( size_t n = 0; n < count; ++n )
     {
-      m_children[n]->GetSize( x, y );
+      m_children[n]->GetSize( x, y, theTree );
     }
   }
 }
 
 wxGenericTreeItem *wxGenericTreeItem::HitTest( const wxPoint& point,
-                                               bool &onButton )
+					       const wxTreeCtrl *theTree,
+					       int &flags)
 {
-  if ((point.y > m_y) && (point.y < m_y + m_text_height))
+  if ((point.y > m_y) && (point.y < m_y + theTree->GetLineHeight(this)))
   {
+    if (point.y<m_y+theTree->GetLineHeight(this)/2) flags|=wxTREE_HITTEST_ONITEMUPPERPART;
+    else flags|=wxTREE_HITTEST_ONITEMLOWERPART;
+
     // FIXME why +5?
     //  Because that is the size of the plus sign, RR
     if ((point.x > m_xCross-5) && (point.x < m_xCross+5) &&
         (point.y > m_yCross-5) && (point.y < m_yCross+5) &&
         (IsExpanded() || HasPlus()))
     {
-      onButton = TRUE;
+      flags|=wxTREE_HITTEST_ONITEMBUTTON;
       return this;
     }
 
-    /* TODO: we should do a query here like
-         m_imageListNormal->GetSize( item->GetImage(), image_w, image_h );  */
-    int w = m_text_width;
-    if (m_image != -1) w += 24;
-
-    if ((point.x > m_x) && (point.x < m_x+w))
+    if ((point.x >= m_x) && (point.x <= m_x+m_width))
     {
-      onButton = FALSE;
+      int image_w,image_h;
+      
+      // assuming every image (normal and selected ) has the same size !
+      theTree->m_imageListNormal->GetSize(m_image, image_w, image_h);
+      if (point.x<=m_x+image_w+1)
+	flags|=wxTREE_HITTEST_ONITEMICON;
+      else 
+	flags|=wxTREE_HITTEST_ONITEMLABEL;
+
       return this;
     }
+
+    if (point.x < m_x)         flags|=wxTREE_HITTEST_ONITEMIDENT;
+    if (point.x > m_x+m_width) flags|=wxTREE_HITTEST_ONITEMRIGHT;
+
+    return this;
   }
   else
   {
@@ -314,13 +337,14 @@ wxGenericTreeItem *wxGenericTreeItem::HitTest( const wxPoint& point,
       size_t count = m_children.Count();
       for ( size_t n = 0; n < count; n++ )
       {
-        wxGenericTreeItem *res = m_children[n]->HitTest( point, onButton );
+        wxGenericTreeItem *res = m_children[n]->HitTest( point, theTree, flags );
         if ( res != NULL )
           return res;
       }
     }
   }
 
+  flags|=wxTREE_HITTEST_NOWHERE;
   return NULL;
 }
 
@@ -342,9 +366,11 @@ END_EVENT_TABLE()
 // -----------------------------------------------------------------------------
 // construction/destruction
 // -----------------------------------------------------------------------------
+
 void wxTreeCtrl::Init()
 {
-  m_current =
+  m_current = 
+  m_key_current =
   m_anchor = (wxGenericTreeItem *) NULL;
   m_hasFocus = FALSE;
   m_dirty = FALSE;
@@ -460,7 +486,8 @@ void wxTreeCtrl::SetItemText(const wxTreeItemId& item, const wxString& text)
 
   wxClientDC dc(this);
   wxGenericTreeItem *pItem = item.m_pItem;
-  pItem->SetText(text, dc);
+  pItem->SetText(text);
+  CalculateSize(pItem, dc);
   RefreshLine(pItem);
 }
 
@@ -468,8 +495,10 @@ void wxTreeCtrl::SetItemImage(const wxTreeItemId& item, int image)
 {
   wxCHECK_RET( item.IsOk(), _T("invalid tree item") );
 
+  wxClientDC dc(this);
   wxGenericTreeItem *pItem = item.m_pItem;
   pItem->SetImage(image);
+  CalculateSize(pItem, dc);
   RefreshLine(pItem);
 }
 
@@ -477,8 +506,10 @@ void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId& item, int image)
 {
   wxCHECK_RET( item.IsOk(), _T("invalid tree item") );
 
+  wxClientDC dc(this);
   wxGenericTreeItem *pItem = item.m_pItem;
   pItem->SetSelectedImage(image);
+  CalculateSize(pItem, dc);
   RefreshLine(pItem);
 }
 
@@ -573,7 +604,7 @@ wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) co
 {
   wxCHECK_MSG( item.IsOk(), wxTreeItemId(), _T("invalid tree item") );
 
-  wxArrayTreeItems& children = item.m_pItem->GetChildren();
+  wxArrayGenericTreeItems& children = item.m_pItem->GetChildren();
   if ( (size_t)cookie < children.Count() )
   {
     return children.Item(cookie++);
@@ -589,7 +620,7 @@ wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
 {
   wxCHECK_MSG( item.IsOk(), wxTreeItemId(), _T("invalid tree item") );
 
-  wxArrayTreeItems& children = item.m_pItem->GetChildren();
+  wxArrayGenericTreeItems& children = item.m_pItem->GetChildren();
   return (children.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children.Last()));
 }
 
@@ -605,7 +636,7 @@ wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const
     return wxTreeItemId();
   }
 
-  wxArrayTreeItems& siblings = parent->GetChildren();
+  wxArrayGenericTreeItems& siblings = parent->GetChildren();
   int index = siblings.Index(i);
   wxASSERT( index != wxNOT_FOUND ); // I'm not a child of my parent?
 
@@ -625,7 +656,7 @@ wxTreeItemId wxTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const
     return wxTreeItemId();
   }
 
-  wxArrayTreeItems& siblings = parent->GetChildren();
+  wxArrayGenericTreeItems& siblings = parent->GetChildren();
   int index = siblings.Index(i);
   wxASSERT( index != wxNOT_FOUND ); // I'm not a child of my parent?
 
@@ -707,8 +738,8 @@ wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text,
     data->m_pItem = m_anchor;
   }
 
-  AdjustMyScrollbars();
   Refresh();
+  AdjustMyScrollbars();
 
   return m_anchor;
 }
@@ -737,7 +768,7 @@ wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parentId,
   int index = parent->GetChildren().Index(idPrevious.m_pItem);
   wxASSERT_MSG( index != wxNOT_FOUND,
                 _T("previous item in wxTreeCtrl::InsertItem() is not a sibling") );
-  return DoInsertItem(parentId, (size_t)index, text, image, selImage, data);
+  return DoInsertItem(parentId, (size_t)++index, text, image, selImage, data);
 }
 
 wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parentId,
@@ -848,7 +879,7 @@ void wxTreeCtrl::Collapse(const wxTreeItemId& itemId)
 
   item->Collapse();
 
-  wxArrayTreeItems& children = item->GetChildren();
+  wxArrayGenericTreeItems& children = item->GetChildren();
   size_t count = children.Count();
   for ( size_t n = 0; n < count; n++ )
   {
@@ -895,7 +926,7 @@ void wxTreeCtrl::UnselectAllChildren(wxGenericTreeItem *item)
   
   if (item->HasChildren())
     {
-      wxArrayTreeItems& children = item->GetChildren();
+      wxArrayGenericTreeItems& children = item->GetChildren();
       size_t count = children.Count();
       for ( size_t n = 0; n < count; ++n )
 	UnselectAllChildren(children[n]);
@@ -909,10 +940,10 @@ void wxTreeCtrl::UnselectAll()
 
 // Recursive function !
 // To stop we must have crt_item<last_item
-// Algorithm = 
+// Algorithm :
 // Tag all next children, when no more children,
 // Move to parent (not to tag) 
-// Keep going, if we found last_item, we stop
+// Keep going... if we found last_item, we stop.
 bool wxTreeCtrl::TagNextChildren(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select)
 {
     wxGenericTreeItem *parent = crt_item->GetParent();
@@ -920,13 +951,13 @@ bool wxTreeCtrl::TagNextChildren(wxGenericTreeItem *crt_item, wxGenericTreeItem
     if ( parent == NULL ) // This is root item
       return TagAllChildrenUntilLast(crt_item, last_item, select);
 
-    wxArrayTreeItems& children = parent->GetChildren();
+    wxArrayGenericTreeItems& children = parent->GetChildren();
     int index = children.Index(crt_item);
     wxASSERT( index != wxNOT_FOUND ); // I'm not a child of my parent?
 
     size_t count = children.Count();
     for (size_t n=(size_t)(index+1); n<count; ++n)
-      if (TagAllChildrenUntilLast(children[n], last_item, select)) return TRUE;
+      if (TagAllChildrenUntilLast(children[n], last_item, select)) return true;
 
     return TagNextChildren(parent, last_item, select);
 }
@@ -936,17 +967,17 @@ bool wxTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericT
   crt_item->SetHilight(select);
   RefreshLine(crt_item);
   
-  if (crt_item==last_item) return TRUE;
+  if (crt_item==last_item) return true;
 
   if (crt_item->HasChildren())
     {
-      wxArrayTreeItems& children = crt_item->GetChildren();
+      wxArrayGenericTreeItems& children = crt_item->GetChildren();
       size_t count = children.Count();
       for ( size_t n = 0; n < count; ++n )
-	if (TagAllChildrenUntilLast(children[n], last_item, select)) return TRUE;
+	if (TagAllChildrenUntilLast(children[n], last_item, select)) return true;
     }
 	
-  return FALSE;
+  return false;
 }
 
 void wxTreeCtrl::SelectItemRange(wxGenericTreeItem *item1, wxGenericTreeItem *item2)
@@ -970,9 +1001,6 @@ void wxTreeCtrl::SelectItemRange(wxGenericTreeItem *item1, wxGenericTreeItem *it
   
   if (TagAllChildrenUntilLast(first,last,select)) return;
 
-/*
-  cout << first->GetText() << " " << last->GetText() << " " << (int) select << endl;
-*/
   TagNextChildren(first,last,select);  
 }
 
@@ -988,8 +1016,8 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId,
     // to keep going anyhow !!!
     if (is_single) 
     {
-        unselect_others=TRUE;
-        extended_select=FALSE;
+        unselect_others=true;
+        extended_select=false;
     }
 
     wxGenericTreeItem *item = itemId.m_pItem;
@@ -998,21 +1026,11 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId,
     event.m_item = item;
     event.m_itemOld = m_current;
     event.SetEventObject( this );
-    // Here we don't send any selection mode yet ! TO SEE 
+    // TODO : Here we don't send any selection mode yet !
     
-/*
-    if (m_current)
-      cout << m_current->GetText() << " " << (int)m_current->HasHilight() << endl;
-*/
-
     if ( GetEventHandler()->ProcessEvent( event ) && event.WasVetoed() )
       return;
 
-/*
-    if (m_current)
-      cout << m_current->GetText() << " " << (int)m_current->HasHilight() << endl;
-*/
-
     // ctrl press
     if (unselect_others)
     {
@@ -1023,19 +1041,19 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId,
     // shift press
     if (extended_select) 
     {
-        if (m_current == NULL) m_current=GetRootItem().m_pItem;
+        if (m_current == NULL) m_current=m_key_current=GetRootItem().m_pItem;
         // don't change the mark (m_current)
         SelectItemRange(m_current, item);
     }
     else
     {
-        bool select=TRUE; // the default
+        bool select=true; // the default
 
 	// Check if we need to toggle hilight (ctrl mode)
 	if (!unselect_others)
 	  select=!item->HasHilight();
 
-        m_current = item;
+        m_current = m_key_current = item;
 	m_current->SetHilight(select);
 	RefreshLine( m_current );
     }
@@ -1044,8 +1062,31 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId,
     GetEventHandler()->ProcessEvent( event );
 }
 
-void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
+void wxTreeCtrl::FillArray(wxGenericTreeItem *item, wxArrayTreeItemIds &array) const
 {
+  if (item->HasHilight()) array.Add(wxTreeItemId(item));
+
+  if (item->HasChildren())
+    {
+      wxArrayGenericTreeItems& children = item->GetChildren();
+      size_t count = children.Count();
+      for ( size_t n = 0; n < count; ++n )
+	FillArray(children[n],array);
+    }
+}
+
+size_t wxTreeCtrl::GetSelections(wxArrayTreeItemIds &array) const
+{
+  array.Empty();
+  FillArray(GetRootItem().m_pItem, array);
+
+  return array.Count();
+}
+
+void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
+{  
+    if (!item.IsOk()) return;
+
     wxGenericTreeItem *gitem = item.m_pItem;
 
     // first expand all parent branches
@@ -1057,13 +1098,24 @@ void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
         parent = parent->GetParent();
     }
 
+    if (parent) CalculatePositions();
+
+    ScrollTo(item);
+}
+
+void wxTreeCtrl::ScrollTo(const wxTreeItemId &item)
+{
+    if (!item.IsOk()) return;
+
+    wxGenericTreeItem *gitem = item.m_pItem;
+
     // now scroll to the item
     int item_y = gitem->GetY();
 
     int start_x = 0;
     int start_y = 0;
     ViewStart( &start_x, &start_y );
-    start_y *= 10;
+    start_y *= PIXELS_PER_UNIT;
 
     int client_h = 0;
     int client_w = 0;
@@ -1071,29 +1123,29 @@ void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
 
     if (item_y < start_y+3)
     {
+        // going down
         int x = 0;
         int y = 0;
-        m_anchor->GetSize( x, y );
-        y += 2*m_lineHeight;
+        m_anchor->GetSize( x, y, this );
+        y += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
         int x_pos = GetScrollPos( wxHORIZONTAL );
-        SetScrollbars( 10, 10, x/10, y/10, x_pos, (item_y-client_h/2)/10 );
+	// Item should appear at top
+        SetScrollbars( PIXELS_PER_UNIT, PIXELS_PER_UNIT, x/PIXELS_PER_UNIT, y/PIXELS_PER_UNIT, x_pos, item_y/PIXELS_PER_UNIT );
     }
-    else if (item_y > start_y+client_h-16)
+    else if (item_y+GetLineHeight(gitem) > start_y+client_h)
     {
+       // going up
        int x = 0;
        int y = 0;
-       m_anchor->GetSize( x, y );
-       y += 2*m_lineHeight;
+       m_anchor->GetSize( x, y, this );
+       y += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
+       item_y += PIXELS_PER_UNIT+2;
        int x_pos = GetScrollPos( wxHORIZONTAL );
-       SetScrollbars( 10, 10, x/10, y/10, x_pos, (item_y-client_h/2)/10 );
+	// Item should appear at bottom
+       SetScrollbars( PIXELS_PER_UNIT, PIXELS_PER_UNIT, x/PIXELS_PER_UNIT, y/PIXELS_PER_UNIT, x_pos, (item_y+GetLineHeight(gitem)-client_h)/PIXELS_PER_UNIT );
     }
 }
 
-void wxTreeCtrl::ScrollTo(const wxTreeItemId& WXUNUSED(item))
-{
-    wxFAIL_MSG(_T("not implemented"));
-}
-
 wxTextCtrl *wxTreeCtrl::EditLabel( const wxTreeItemId& WXUNUSED(item),
                                    wxClassInfo* WXUNUSED(textCtrlClass) )
 {
@@ -1140,7 +1192,7 @@ void wxTreeCtrl::SortChildren(const wxTreeItemId& itemId)
     wxCHECK_RET( !s_treeBeingSorted,
                  _T("wxTreeCtrl::SortChildren is not reentrant") );
 
-    wxArrayTreeItems& children = item->GetChildren();
+    wxArrayGenericTreeItems& children = item->GetChildren();
     if ( children.Count() > 1 )
     {
         s_treeBeingSorted = this;
@@ -1165,9 +1217,12 @@ wxImageList *wxTreeCtrl::GetStateImageList() const
 void wxTreeCtrl::SetImageList(wxImageList *imageList)
 {
    m_imageListNormal = imageList;
-   // calculate a m_lineHeight value from the image sizes
+
+   // Calculate a m_lineHeight value from the image sizes.
+   // May be toggle off. Then wxTreeCtrl will spread when
+   // necessary (which might look ugly).
+#if 1
    wxPaintDC dc(this);
-   PrepareDC( dc );
    m_lineHeight = (int)(dc.GetCharHeight() + 4);
    int
       width = 0,
@@ -1176,9 +1231,13 @@ void wxTreeCtrl::SetImageList(wxImageList *imageList)
    for(int i = 0; i < n ; i++)
    {
       m_imageListNormal->GetSize(i, width, height);
-      height += height/5;  //20% extra spacing
       if(height > m_lineHeight) m_lineHeight = height;
-   }
+   }  
+
+   if (m_lineHeight<40) m_lineHeight+=4; // at least 4 pixels (odd such that a line can be drawn in between)
+   else m_lineHeight+=m_lineHeight/10;   // otherwise 10% extra spacing
+
+#endif
 }
 
 void wxTreeCtrl::SetStateImageList(wxImageList *imageList)
@@ -1196,11 +1255,12 @@ void wxTreeCtrl::AdjustMyScrollbars()
     {
         int x = 0;
         int y = 0;
-        m_anchor->GetSize( x, y );
-        y += 2*m_lineHeight;
+        m_anchor->GetSize( x, y, this );
+        //y += GetLineHeight(m_anchor);
+	y += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
         int x_pos = GetScrollPos( wxHORIZONTAL );
         int y_pos = GetScrollPos( wxVERTICAL );
-        SetScrollbars( 10, 10, x/10, y/10, x_pos, y_pos );
+        SetScrollbars( PIXELS_PER_UNIT, PIXELS_PER_UNIT, x/PIXELS_PER_UNIT, y/PIXELS_PER_UNIT, x_pos, y_pos );
     }
     else
     {
@@ -1208,6 +1268,14 @@ void wxTreeCtrl::AdjustMyScrollbars()
     }
 }
 
+int wxTreeCtrl::GetLineHeight(wxGenericTreeItem *item) const
+{
+  if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HIGHT)
+    return item->GetHeight();
+  else
+    return m_lineHeight;  
+}
+
 void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
 {
     // render bold items in bold
@@ -1250,10 +1318,9 @@ void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
         image_w += 4;
     }
 
-    int total_h = (image_h > text_h) ? image_h : text_h;
-    if(m_lineHeight > total_h) total_h = m_lineHeight;
-    
-    dc.DrawRectangle( item->GetX()-2, item->GetY(), image_w+text_w+4, total_h );
+    int total_h = GetLineHeight(item);
+
+    dc.DrawRectangle( item->GetX()-2, item->GetY(), item->GetWidth()+2, total_h );
 
     if ((item->IsExpanded()) && (item->GetSelectedImage() != -1))
     {
@@ -1285,22 +1352,23 @@ void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
     }
 }
 
+// Now y stands for the top of the item, whereas it used to stand for middle !
 void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y )
 {
     int horizX = level*m_indent;
 
     item->SetX( horizX+m_indent+m_spacing );
-    item->SetY( y-m_lineHeight/2 );
-    item->SetHeight( m_lineHeight );
-
-    item->SetCross( horizX+m_indent, y );
+    item->SetY( y );
 
     int oldY = y;
+    y+=GetLineHeight(item)/2;
+
+    item->SetCross( horizX+m_indent, y );
 
     int exposed_x = dc.LogicalToDeviceX( 0 );
     int exposed_y = dc.LogicalToDeviceY( item->GetY()-2 );
 
-    if (IsExposed( exposed_x, exposed_y, 10000, m_lineHeight+4 ))  // 10000 = very much
+    if (IsExposed( exposed_x, exposed_y, 10000, GetLineHeight(item)+4 ))  // 10000 = very much
     {
         int startX = horizX;
         int endX = horizX + (m_indent-5);
@@ -1352,35 +1420,78 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &
             dc.SetPen( *wxBLACK_PEN );
         }
     }
+    
+    y = oldY+GetLineHeight(item);
 
     if (item->IsExpanded())
     {
-        int semiOldY = y;
+        oldY+=GetLineHeight(item)/2;
+        int semiOldY=y; // (=y) for stupid compilator
 
-        wxArrayTreeItems& children = item->GetChildren();
-        size_t count = children.Count();
-        for ( size_t n = 0; n < count; n++ )
-        {
-            y += m_lineHeight;
-            semiOldY = y;
-            PaintLevel( children[n], dc, level+1, y );
-        }
+        wxArrayGenericTreeItems& children = item->GetChildren();
+        size_t n, count = children.Count();
+        for ( n = 0; n < count; ++n )
+	{
+	    semiOldY=y;
+	    PaintLevel( children[n], dc, level+1, y );
+	}
 
         // it may happen that the item is expanded but has no items (when you
         // delete all its children for example) - don't draw the vertical line
         // in this case
         if (count > 0)
+	  {
+	    semiOldY+=GetLineHeight(children[--n])/2;
             dc.DrawLine( horizX+m_indent, oldY+5, horizX+m_indent, semiOldY );
+	  }
     }
 }
 
+void wxTreeCtrl::DrawBorder(wxTreeItemId &item)
+{
+  if (!item) return;
+
+    wxGenericTreeItem *i=item.m_pItem;
+
+    wxPaintDC dc(this);
+    PrepareDC( dc );
+    dc.SetLogicalFunction(wxINVERT);
+
+    int w,h,x;
+    ViewStart(&x,&h);     // we only need x
+    GetClientSize(&w,&h); // we only need w
+
+    h=GetLineHeight(i)+1;
+    // 2 white column at border
+    dc.DrawRectangle( PIXELS_PER_UNIT*x+2, i->GetY()-1, w-6, h);
+}
+
+void wxTreeCtrl::DrawLine(wxTreeItemId &item, bool below)
+{
+  if (!item) return;
+
+    wxGenericTreeItem *i=item.m_pItem;
+
+    wxPaintDC dc(this);
+    PrepareDC( dc );
+    dc.SetLogicalFunction(wxINVERT);
+    
+    int w,h,y;
+    GetSize(&w,&h);
+
+    if (below) y=i->GetY()+GetLineHeight(i)-1;
+    else y=i->GetY();
+
+    dc.DrawLine( 0, y, w, y);
+}
+
 // -----------------------------------------------------------------------------
 // wxWindows callbacks
 // -----------------------------------------------------------------------------
 
 void wxTreeCtrl::OnPaint( wxPaintEvent &WXUNUSED(event) )
 {
-    if ( !m_anchor )
+    if ( !m_anchor)
         return;
 
     wxPaintDC dc(this);
@@ -1389,10 +1500,10 @@ void wxTreeCtrl::OnPaint( wxPaintEvent &WXUNUSED(event) )
     dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ) );
 
     dc.SetPen( m_dottedPen );
-    if(GetImageList() == NULL)
-       m_lineHeight = (int)(dc.GetCharHeight() + 4);
+    //if(GetImageList() == NULL)
+    // m_lineHeight = (int)(dc.GetCharHeight() + 4);
 
-    int y = m_lineHeight / 2 + 2;
+    int y = 2;
     PaintLevel( m_anchor, dc, 0, y );
 }
 
@@ -1417,7 +1528,7 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
     te.SetEventObject( this );
     GetEventHandler()->ProcessEvent( te );
 
-    if (m_current == 0)
+    if ( (m_current == 0) || (m_key_current == 0) )
     {
         event.Skip();
         return;
@@ -1465,19 +1576,20 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
             // it's expanded
         case WXK_UP:
             {
-                wxTreeItemId prev = GetPrevSibling( m_current );
+                wxTreeItemId prev = GetPrevSibling( m_key_current );
                 if (!prev)
                 {
-                    prev = GetParent( m_current );
+                    prev = GetParent( m_key_current );
 		    if (prev)
 		    {
                         long cockie = 0;
-                        wxTreeItemId current = m_current;
+                        wxTreeItemId current = m_key_current;
                         if (current == GetFirstChild( prev, cockie ))
                         {
                             // otherwise we return to where we came from
                             SelectItem( prev, unselect_others, extended_select );
-                            EnsureVisible( prev );
+			    m_key_current=prev.m_pItem;
+			    EnsureVisible( prev );
                             break;
 			}
                     }
@@ -1494,6 +1606,7 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
                     }
 
                     SelectItem( prev, unselect_others, extended_select );
+		    m_key_current=prev.m_pItem;
                     EnsureVisible( prev );
                 }
             }
@@ -1519,19 +1632,20 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
 
         case WXK_DOWN:
             {
-                if (IsExpanded(m_current) && HasChildren(m_current))
+                if (IsExpanded(m_key_current) && HasChildren(m_key_current))
                 {
                     long cookie = 0;
-                    wxTreeItemId child = GetFirstChild( m_current, cookie );
+                    wxTreeItemId child = GetFirstChild( m_key_current, cookie );
                     SelectItem( child, unselect_others, extended_select );
+		    m_key_current=child.m_pItem;
                     EnsureVisible( child );
                 }
                 else
                 {
-                    wxTreeItemId next = GetNextSibling( m_current );
+                    wxTreeItemId next = GetNextSibling( m_key_current );
                     if (next == 0)
                     {
-                        wxTreeItemId current = m_current;
+                        wxTreeItemId current = m_key_current;
                         while (current && !next)
                         {
                             current = GetParent( current );
@@ -1541,6 +1655,7 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
                     if (next != 0)
                     {
                         SelectItem( next, unselect_others, extended_select );
+			m_key_current=next.m_pItem;
                         EnsureVisible( next );
                     }
                 }
@@ -1590,22 +1705,29 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
     }
 }
 
-wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& WXUNUSED(flags))
+wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
 {
     wxClientDC dc(this);
     PrepareDC(dc);
     long x = dc.DeviceToLogicalX( (long)point.x );
     long y = dc.DeviceToLogicalY( (long)point.y );
-
-    bool onButton = FALSE;
-    return m_anchor->HitTest( wxPoint(x, y), onButton );
+    int w, h;
+    GetSize(&w, &h);
+
+    flags=0;
+    if (point.x<0) flags|=wxTREE_HITTEST_TOLEFT;
+    if (point.x>w) flags|=wxTREE_HITTEST_TORIGHT;
+    if (point.y<0) flags|=wxTREE_HITTEST_ABOVE;
+    if (point.y>h) flags|=wxTREE_HITTEST_BELOW;
+    
+    return m_anchor->HitTest( wxPoint(x, y), this, flags);
 }
 
 void wxTreeCtrl::OnMouse( wxMouseEvent &event )
 {
     if (!event.LeftIsDown()) m_dragCount = 0;
 
-    if ( !(event.LeftDown() || event.LeftDClick() || event.Dragging()) ) return;
+    if ( !(event.LeftUp() || event.LeftDClick() || event.Dragging()) ) return;
 
     if ( !m_anchor ) return;
 
@@ -1614,8 +1736,9 @@ void wxTreeCtrl::OnMouse( wxMouseEvent &event )
     long x = dc.DeviceToLogicalX( (long)event.GetX() );
     long y = dc.DeviceToLogicalY( (long)event.GetY() );
 
-    bool onButton = FALSE;
-    wxGenericTreeItem *item = m_anchor->HitTest( wxPoint(x,y), onButton );
+    int flags=0;
+    wxGenericTreeItem *item = m_anchor->HitTest( wxPoint(x,y), this, flags);
+    bool onButton = flags & wxTREE_HITTEST_ONITEMBUTTON;
 
     if (item == NULL) return;  /* we hit the blank area */
 
@@ -1641,6 +1764,12 @@ void wxTreeCtrl::OnMouse( wxMouseEvent &event )
     bool extended_select=(event.ShiftDown() && is_multiple);
     bool unselect_others=!(extended_select || (event.ControlDown() && is_multiple));
 
+    if (onButton)
+    {
+        Toggle( item );
+	if (is_multiple) return;
+    }
+
     SelectItem(item, unselect_others, extended_select);
 
     if (event.LeftDClick())
@@ -1651,11 +1780,6 @@ void wxTreeCtrl::OnMouse( wxMouseEvent &event )
         event.SetEventObject( this );
         GetEventHandler()->ProcessEvent( event );
     }
-
-    if (onButton)
-    {
-        Toggle( item );
-    }
 }
 
 void wxTreeCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
@@ -1669,19 +1793,57 @@ void wxTreeCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
     m_dirty = FALSE;
 
     CalculatePositions();
-
+    Refresh();
     AdjustMyScrollbars();
 }
 
-// -----------------------------------------------------------------------------
+void wxTreeCtrl::CalculateSize( wxGenericTreeItem *item, wxDC &dc )
+{  
+    long text_w = 0;
+    long text_h = 0;
+    // TODO : check for boldness. Here with suppose that font normal and bold
+    //        have the same height !
+    // TODO : bug here, text_w is sometime not the correct answer !!!
+    dc.GetTextExtent( item->GetText(), &text_w, &text_h );
+    text_h+=4;
+
+    int image_h = 0;
+    int image_w = 0;
+    if ((item->IsExpanded()) && (item->GetSelectedImage() != -1))
+    {
+        m_imageListNormal->GetSize( item->GetSelectedImage(), image_w, image_h );
+        image_w += 4;
+    }
+    else if (item->GetImage() != -1)
+    {
+        m_imageListNormal->GetSize( item->GetImage(), image_w, image_h );
+        image_w += 4;
+    }
+
+    int total_h = (image_h > text_h) ? image_h : text_h;
+
+    if (total_h<40) total_h+=4; // at least 4 pixels
+    else total_h+=total_h/10;   // otherwise 10% extra spacing
+
+    item->SetHeight(total_h);
+    if (total_h>m_lineHeight) m_lineHeight=total_h;
 
+    item->SetWidth(image_w+text_w+2);
+}
+
+// -----------------------------------------------------------------------------
+// for developper : y is now the top of the level
+// not the middle of it !
 void wxTreeCtrl::CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y )
 {
     int horizX = level*m_indent;
 
+    CalculateSize( item, dc );
+  
+    // set its position
     item->SetX( horizX+m_indent+m_spacing );
-    item->SetY( y-m_lineHeight/2 );
-    item->SetHeight( m_lineHeight );
+    item->SetY( y );
+    y+=GetLineHeight(item);
 
     if ( !item->IsExpanded() )
     {
@@ -1689,13 +1851,10 @@ void wxTreeCtrl::CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, i
         return;
     }
 
-    wxArrayTreeItems& children = item->GetChildren();
-    size_t count = children.Count();
-    for ( size_t n = 0; n < count; n++ )
-    {
-        y += m_lineHeight;
-        CalculateLevel( children[n], dc, level+1, y );  // recurse
-    }
+    wxArrayGenericTreeItems& children = item->GetChildren();
+    size_t n, count = children.Count();
+    for (n = 0; n < count; ++n )
+      CalculateLevel( children[n], dc, level+1, y );  // recurse
 }
 
 void wxTreeCtrl::CalculatePositions()
@@ -1708,10 +1867,10 @@ void wxTreeCtrl::CalculatePositions()
     dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ) );
 
     dc.SetPen( m_dottedPen );
-    if(GetImageList() == NULL)
-       m_lineHeight = (int)(dc.GetCharHeight() + 4);
+    //if(GetImageList() == NULL)
+    // m_lineHeight = (int)(dc.GetCharHeight() + 4);
 
-    int y = m_lineHeight / 2 + 2;
+    int y = 2; //GetLineHeight(m_anchor) / 2 + 2;
     CalculateLevel( m_anchor, dc, 0, y ); // start recursion
 }
 
@@ -1742,9 +1901,9 @@ void wxTreeCtrl::RefreshLine( wxGenericTreeItem *item )
 
     wxRect rect;
     rect.x = dc.LogicalToDeviceX( item->GetX() - 2 );
-    rect.y = dc.LogicalToDeviceY( item->GetY() - 2 );
+    rect.y = dc.LogicalToDeviceY( item->GetY());
     rect.width = 1000;
-    rect.height = dc.GetCharHeight() + 6;
+    rect.height = GetLineHeight(item); //dc.GetCharHeight() + 6;
 
     Refresh( TRUE, &rect );
 }
diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp
index 85b8b53fb6..1af8165327 100644
--- a/src/gtk/app.cpp
+++ b/src/gtk/app.cpp
@@ -28,13 +28,15 @@
 #include "wx/module.h"
 #include "wx/image.h"
 
+#if wxUSE_THREADS
 #include "wx/thread.h"
+#endif
 
 #include "unistd.h"
 
-#include <glib.h>
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
+#include "glib.h"
+#include "gdk/gdk.h"
+#include "gtk/gtk.h"
 
 #include "wx/gtk/win_gtk.h"
 
diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp
index 80ecdcddac..5af0c4c336 100644
--- a/src/gtk/bitmap.cpp
+++ b/src/gtk/bitmap.cpp
@@ -31,16 +31,19 @@ wxMask::wxMask()
     m_bitmap = (GdkBitmap *) NULL;
 }
 
-wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), const wxColour& WXUNUSED(colour) )
+wxMask::wxMask( const wxBitmap& bitmap, const wxColour& colour )
 {
+    Create( bitmap, colour );
 }
 
-wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), int WXUNUSED(paletteIndex) )
+wxMask::wxMask( const wxBitmap& bitmap, int paletteIndex )
 {
+    Create( bitmap, paletteIndex );
 }
 
-wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap) )
+wxMask::wxMask( const wxBitmap& bitmap )
 {
+    Create( bitmap );
 }
 
 wxMask::~wxMask()
@@ -48,7 +51,58 @@ wxMask::~wxMask()
     if (m_bitmap) gdk_bitmap_unref( m_bitmap );
 }
 
-GdkBitmap *wxMask::GetBitmap(void) const
+bool wxMask::Create( const wxBitmap& bitmap, const wxColour& colour )
+{
+    if (m_bitmap)
+    { 
+        gdk_bitmap_unref( m_bitmap );
+	m_bitmap = (GdkBitmap*) NULL;
+    }
+    
+    wxFAIL_MSG( "TODO" );
+    
+    return FALSE;
+}
+
+bool wxMask::Create( const wxBitmap& WXUNUSED(bitmap), int WXUNUSED(paletteIndex) )
+{
+    if (m_bitmap)
+    { 
+        gdk_bitmap_unref( m_bitmap );
+	m_bitmap = (GdkBitmap*) NULL;
+    }
+    
+    wxFAIL_MSG( "not implemented" );
+    
+    return FALSE;
+}
+
+bool wxMask::Create( const wxBitmap& bitmap )
+{
+    if (m_bitmap)
+    { 
+        gdk_bitmap_unref( m_bitmap );
+	m_bitmap = (GdkBitmap*) NULL;
+    }
+    
+    if (!bitmap.Ok()) return FALSE;
+    
+    wxCHECK_MSG( bitmap.GetBitmap(), FALSE, "Cannot create mask from colour bitmap" );
+    
+    m_bitmap = gdk_pixmap_new( (GdkWindow*) &gdk_root_parent, bitmap.GetWidth(), bitmap.GetHeight(), 1 );
+    
+    if (!m_bitmap) return FALSE;
+    
+    GdkGC *gc = gdk_gc_new( m_bitmap );
+    
+    gdk_draw_bitmap( m_bitmap, gc, bitmap.GetBitmap(), 0, 0, 0, 0, bitmap.GetWidth(), bitmap.GetHeight() );
+    
+    gdk_gc_unref( gc );
+    
+    return TRUE;
+}
+
+GdkBitmap *wxMask::GetBitmap() const
 {
     return m_bitmap;
 }
@@ -60,8 +114,8 @@ GdkBitmap *wxMask::GetBitmap(void) const
 class wxBitmapRefData: public wxObjectRefData
 {
 public:
-  wxBitmapRefData(void);
-  ~wxBitmapRefData(void);
+  wxBitmapRefData();
+  ~wxBitmapRefData();
 
   GdkPixmap      *m_pixmap;
   GdkBitmap      *m_bitmap;
@@ -230,33 +284,33 @@ bool wxBitmap::operator != ( const wxBitmap& bmp )
     return m_refData != bmp.m_refData;
 }
 
-bool wxBitmap::Ok(void) const
+bool wxBitmap::Ok() const
 {
     return (m_refData != NULL);
 }
 
-int wxBitmap::GetHeight(void) const
+int wxBitmap::GetHeight() const
 {
     wxCHECK_MSG( Ok(), -1, _T("invalid bitmap") );
 
     return M_BMPDATA->m_height;
 }
 
-int wxBitmap::GetWidth(void) const
+int wxBitmap::GetWidth() const
 {
     wxCHECK_MSG( Ok(), -1, _T("invalid bitmap") );
 
     return M_BMPDATA->m_width;
 }
 
-int wxBitmap::GetDepth(void) const
+int wxBitmap::GetDepth() const
 {
     wxCHECK_MSG( Ok(), -1, _T("invalid bitmap") );
 
     return M_BMPDATA->m_bpp;
 }
 
-wxMask *wxBitmap::GetMask(void) const
+wxMask *wxBitmap::GetMask() const
 {
     wxCHECK_MSG( Ok(), (wxMask *) NULL, _T("invalid bitmap") );
 
@@ -327,7 +381,7 @@ bool wxBitmap::LoadFile( const wxString &name, int type )
     return TRUE;
 }
 
-wxPalette *wxBitmap::GetPalette(void) const
+wxPalette *wxBitmap::GetPalette() const
 {
     if (!Ok()) return (wxPalette *) NULL;
 
@@ -362,14 +416,14 @@ void wxBitmap::SetPixmap( GdkPixmap *pixmap )
     M_BMPDATA->m_pixmap = pixmap;
 }
 
-GdkPixmap *wxBitmap::GetPixmap(void) const
+GdkPixmap *wxBitmap::GetPixmap() const
 {
     wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, _T("invalid bitmap") );
 
     return M_BMPDATA->m_pixmap;
 }
 
-GdkBitmap *wxBitmap::GetBitmap(void) const
+GdkBitmap *wxBitmap::GetBitmap() const
 {
     wxCHECK_MSG( Ok(), (GdkBitmap *) NULL, _T("invalid bitmap") );
 
diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp
index 93f34e9fe7..649070a915 100644
--- a/src/gtk/dcclient.cpp
+++ b/src/gtk/dcclient.cpp
@@ -1172,9 +1172,15 @@ void wxWindowDC::SetUpDC()
     m_brush = wxNullBrush;
     SetBrush( tmp_brush );
     
+/*
     tmp_brush = m_backgroundBrush;
     m_backgroundBrush = wxNullBrush;
     SetBackground( tmp_brush );
+*/
+    tmp_brush = m_backgroundBrush;
+    m_backgroundBrush = wxNullBrush;
+    SetBackground( *wxWHITE_BRUSH );
+    m_backgroundBrush = tmp_brush;
   
     if (!hatch_bitmap) 
     {
diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp
index dddd561bcc..1675dfe547 100644
--- a/src/gtk/utilsgtk.cpp
+++ b/src/gtk/utilsgtk.cpp
@@ -18,23 +18,16 @@
 #include "wx/unix/execute.h"
 
 #include <stdarg.h>
-#include <dirent.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <sys/wait.h>
-#include <pwd.h>
-#include <errno.h>
-#include <netdb.h>
-#include <signal.h>
-#include <fcntl.h>          // for O_WRONLY and friends
-
-#include <glib.h>
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
-#include <gtk/gtkfeatures.h>
-#include <gdk/gdkx.h>
+
+#include "glib.h"
+#include "gdk/gdk.h"
+#include "gtk/gtk.h"
+#include "gtk/gtkfeatures.h"
+#include "gdk/gdkx.h"
 
 #ifdef HAVE_X11_XKBLIB_H
   #ifdef __HPUX__
diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp
index 85b8b53fb6..1af8165327 100644
--- a/src/gtk1/app.cpp
+++ b/src/gtk1/app.cpp
@@ -28,13 +28,15 @@
 #include "wx/module.h"
 #include "wx/image.h"
 
+#if wxUSE_THREADS
 #include "wx/thread.h"
+#endif
 
 #include "unistd.h"
 
-#include <glib.h>
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
+#include "glib.h"
+#include "gdk/gdk.h"
+#include "gtk/gtk.h"
 
 #include "wx/gtk/win_gtk.h"
 
diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp
index 80ecdcddac..5af0c4c336 100644
--- a/src/gtk1/bitmap.cpp
+++ b/src/gtk1/bitmap.cpp
@@ -31,16 +31,19 @@ wxMask::wxMask()
     m_bitmap = (GdkBitmap *) NULL;
 }
 
-wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), const wxColour& WXUNUSED(colour) )
+wxMask::wxMask( const wxBitmap& bitmap, const wxColour& colour )
 {
+    Create( bitmap, colour );
 }
 
-wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), int WXUNUSED(paletteIndex) )
+wxMask::wxMask( const wxBitmap& bitmap, int paletteIndex )
 {
+    Create( bitmap, paletteIndex );
 }
 
-wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap) )
+wxMask::wxMask( const wxBitmap& bitmap )
 {
+    Create( bitmap );
 }
 
 wxMask::~wxMask()
@@ -48,7 +51,58 @@ wxMask::~wxMask()
     if (m_bitmap) gdk_bitmap_unref( m_bitmap );
 }
 
-GdkBitmap *wxMask::GetBitmap(void) const
+bool wxMask::Create( const wxBitmap& bitmap, const wxColour& colour )
+{
+    if (m_bitmap)
+    { 
+        gdk_bitmap_unref( m_bitmap );
+	m_bitmap = (GdkBitmap*) NULL;
+    }
+    
+    wxFAIL_MSG( "TODO" );
+    
+    return FALSE;
+}
+
+bool wxMask::Create( const wxBitmap& WXUNUSED(bitmap), int WXUNUSED(paletteIndex) )
+{
+    if (m_bitmap)
+    { 
+        gdk_bitmap_unref( m_bitmap );
+	m_bitmap = (GdkBitmap*) NULL;
+    }
+    
+    wxFAIL_MSG( "not implemented" );
+    
+    return FALSE;
+}
+
+bool wxMask::Create( const wxBitmap& bitmap )
+{
+    if (m_bitmap)
+    { 
+        gdk_bitmap_unref( m_bitmap );
+	m_bitmap = (GdkBitmap*) NULL;
+    }
+    
+    if (!bitmap.Ok()) return FALSE;
+    
+    wxCHECK_MSG( bitmap.GetBitmap(), FALSE, "Cannot create mask from colour bitmap" );
+    
+    m_bitmap = gdk_pixmap_new( (GdkWindow*) &gdk_root_parent, bitmap.GetWidth(), bitmap.GetHeight(), 1 );
+    
+    if (!m_bitmap) return FALSE;
+    
+    GdkGC *gc = gdk_gc_new( m_bitmap );
+    
+    gdk_draw_bitmap( m_bitmap, gc, bitmap.GetBitmap(), 0, 0, 0, 0, bitmap.GetWidth(), bitmap.GetHeight() );
+    
+    gdk_gc_unref( gc );
+    
+    return TRUE;
+}
+
+GdkBitmap *wxMask::GetBitmap() const
 {
     return m_bitmap;
 }
@@ -60,8 +114,8 @@ GdkBitmap *wxMask::GetBitmap(void) const
 class wxBitmapRefData: public wxObjectRefData
 {
 public:
-  wxBitmapRefData(void);
-  ~wxBitmapRefData(void);
+  wxBitmapRefData();
+  ~wxBitmapRefData();
 
   GdkPixmap      *m_pixmap;
   GdkBitmap      *m_bitmap;
@@ -230,33 +284,33 @@ bool wxBitmap::operator != ( const wxBitmap& bmp )
     return m_refData != bmp.m_refData;
 }
 
-bool wxBitmap::Ok(void) const
+bool wxBitmap::Ok() const
 {
     return (m_refData != NULL);
 }
 
-int wxBitmap::GetHeight(void) const
+int wxBitmap::GetHeight() const
 {
     wxCHECK_MSG( Ok(), -1, _T("invalid bitmap") );
 
     return M_BMPDATA->m_height;
 }
 
-int wxBitmap::GetWidth(void) const
+int wxBitmap::GetWidth() const
 {
     wxCHECK_MSG( Ok(), -1, _T("invalid bitmap") );
 
     return M_BMPDATA->m_width;
 }
 
-int wxBitmap::GetDepth(void) const
+int wxBitmap::GetDepth() const
 {
     wxCHECK_MSG( Ok(), -1, _T("invalid bitmap") );
 
     return M_BMPDATA->m_bpp;
 }
 
-wxMask *wxBitmap::GetMask(void) const
+wxMask *wxBitmap::GetMask() const
 {
     wxCHECK_MSG( Ok(), (wxMask *) NULL, _T("invalid bitmap") );
 
@@ -327,7 +381,7 @@ bool wxBitmap::LoadFile( const wxString &name, int type )
     return TRUE;
 }
 
-wxPalette *wxBitmap::GetPalette(void) const
+wxPalette *wxBitmap::GetPalette() const
 {
     if (!Ok()) return (wxPalette *) NULL;
 
@@ -362,14 +416,14 @@ void wxBitmap::SetPixmap( GdkPixmap *pixmap )
     M_BMPDATA->m_pixmap = pixmap;
 }
 
-GdkPixmap *wxBitmap::GetPixmap(void) const
+GdkPixmap *wxBitmap::GetPixmap() const
 {
     wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, _T("invalid bitmap") );
 
     return M_BMPDATA->m_pixmap;
 }
 
-GdkBitmap *wxBitmap::GetBitmap(void) const
+GdkBitmap *wxBitmap::GetBitmap() const
 {
     wxCHECK_MSG( Ok(), (GdkBitmap *) NULL, _T("invalid bitmap") );
 
diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp
index 93f34e9fe7..649070a915 100644
--- a/src/gtk1/dcclient.cpp
+++ b/src/gtk1/dcclient.cpp
@@ -1172,9 +1172,15 @@ void wxWindowDC::SetUpDC()
     m_brush = wxNullBrush;
     SetBrush( tmp_brush );
     
+/*
     tmp_brush = m_backgroundBrush;
     m_backgroundBrush = wxNullBrush;
     SetBackground( tmp_brush );
+*/
+    tmp_brush = m_backgroundBrush;
+    m_backgroundBrush = wxNullBrush;
+    SetBackground( *wxWHITE_BRUSH );
+    m_backgroundBrush = tmp_brush;
   
     if (!hatch_bitmap) 
     {
diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp
index dddd561bcc..1675dfe547 100644
--- a/src/gtk1/utilsgtk.cpp
+++ b/src/gtk1/utilsgtk.cpp
@@ -18,23 +18,16 @@
 #include "wx/unix/execute.h"
 
 #include <stdarg.h>
-#include <dirent.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <sys/wait.h>
-#include <pwd.h>
-#include <errno.h>
-#include <netdb.h>
-#include <signal.h>
-#include <fcntl.h>          // for O_WRONLY and friends
-
-#include <glib.h>
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
-#include <gtk/gtkfeatures.h>
-#include <gdk/gdkx.h>
+
+#include "glib.h"
+#include "gdk/gdk.h"
+#include "gtk/gtk.h"
+#include "gtk/gtkfeatures.h"
+#include "gdk/gdkx.h"
 
 #ifdef HAVE_X11_XKBLIB_H
   #ifdef __HPUX__
diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp
index bb8b4b33e9..f0f3439033 100644
--- a/src/unix/utilsunx.cpp
+++ b/src/unix/utilsunx.cpp
@@ -69,6 +69,17 @@
     };
 #endif // Unices without usleep()
 
+#ifdef __EMX__
+  /* I copied this from the XFree86 diffs. AV. */
+extern void DosSleep(unsigned long);
+#define INCL_DOSPROCESS
+#include <os2.h>
+void usleep(unsigned long delay)
+{
+    DosSleep(delay ? (delay/1000l) : 1l);
+}
+#endif
+
 // ============================================================================
 // implementation
 // ============================================================================
-- 
2.45.2

