From e2fc40b4786f7ae8c255ce1184441bd94d9554a0 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Sat, 15 Dec 2007 01:25:56 +0000
Subject: [PATCH] PalmOS 6 compilation fixes (patch 1849757)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50704 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 build/bakefiles/files.bkl       |   2 +
 build/msw/config.vc             |   2 +-
 build/palmos/.cdtproject        |  31 +--
 build/palmos/.project           |  56 ++++-
 build/palmos/auto-generated.mk  |  18 +-
 build/palmos/makefile           |  27 ++-
 build/palmos/makefile-engine.mk |   8 +
 include/wx/defs.h               |  21 +-
 include/wx/filefn.h             |   9 +
 include/wx/palmos/apptrait.h    |   7 +-
 include/wx/palmos/chkconf.h     |  13 +-
 include/wx/palmos/control.h     |   2 +-
 include/wx/palmos/dc.h          | 166 ++++++++++---
 include/wx/palmos/dcclient.h    |  64 ++----
 include/wx/palmos/dcmemory.h    |  20 +-
 include/wx/palmos/dcscreen.h    |  19 +-
 include/wx/palmos/dialog.h      |   2 +-
 include/wx/palmos/evtloop.h     |   1 +
 include/wx/palmos/missing.h     | 396 ++++++++++++++++++++++++++++++++
 include/wx/palmos/tglbtn.h      |   3 +-
 include/wx/palmos/window.h      |   7 +-
 include/wx/platform.h           |  35 ++-
 include/wx/wxcrtbase.h          |  17 +-
 src/common/dcbase.cpp           |   6 +
 src/common/filefn.cpp           |  10 +-
 src/common/wxcrt.cpp            |   3 +
 src/palmos/app.cpp              |  14 +-
 src/palmos/base.cpp             |  16 +-
 src/palmos/button.cpp           |   2 +-
 src/palmos/control.cpp          |   8 +-
 src/palmos/datectrl.cpp         |   3 +-
 src/palmos/dc.cpp               | 381 +++++++++++++++++++-----------
 src/palmos/dcclient.cpp         | 221 ++++++++++++++----
 src/palmos/dcmemory.cpp         |  65 +++---
 src/palmos/dcscreen.cpp         |   9 +-
 src/palmos/dialog.cpp           |  10 +-
 src/palmos/evtloop.cpp          |   5 +
 src/palmos/main.cpp             |   4 +-
 src/palmos/prefconf.cpp         |   8 +-
 src/palmos/stdall.c             | 360 +++++++++++++++++++++++++++++
 src/palmos/toplevel.cpp         |   3 +
 src/palmos/utils.cpp            |   2 +
 src/palmos/window.cpp           |   7 +-
 43 files changed, 1679 insertions(+), 384 deletions(-)
 create mode 100644 include/wx/palmos/missing.h
 create mode 100644 src/palmos/stdall.c

diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl
index 2681b1e616..1a0c333936 100644
--- a/build/bakefiles/files.bkl
+++ b/build/bakefiles/files.bkl
@@ -288,6 +288,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     src/palmos/dir.cpp
     src/palmos/prefconf.cpp
     src/palmos/snglinst.cpp
+    src/palmos/stdall.c
     src/palmos/thread.cpp
     src/palmos/utils.cpp
     src/palmos/utilsexc.cpp
@@ -303,6 +304,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     wx/palmos/apptrait.h
     wx/palmos/chkconf.h
     wx/palmos/mimetype.h
+    wx/palmos/missing.h
     wx/palmos/stdpaths.h
 </set>
 
diff --git a/build/msw/config.vc b/build/msw/config.vc
index 472dae964d..2bf4308855 100644
--- a/build/msw/config.vc
+++ b/build/msw/config.vc
@@ -32,7 +32,7 @@ LDFLAGS =
 CPP = $(CC) /EP /nologo
 
 # What type of library to build? [0,1]
-SHARED = 0
+SHARED = 1
 
 # Build wxUniversal instead of native port? [0,1]
 WXUNIV = 0
diff --git a/build/palmos/.cdtproject b/build/palmos/.cdtproject
index 586a6a913b..9d688e3df2 100644
--- a/build/palmos/.cdtproject
+++ b/build/palmos/.cdtproject
@@ -1,22 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<?eclipse-cdt version="2.0"?>
+
 <cdtproject id="org.eclipse.cdt.make.core.make">
-    <extension id="org.eclipse.cdt.make.core.MakeScannerProvider" point="org.eclipse.cdt.core.ScannerInfoProvider"/>
-    <extension id="org.eclipse.cdt.core.Elf" point="org.eclipse.cdt.core.BinaryParser"/>
-    <data>
-        <item id="org.eclipse.cdt.make.core.makeScannerInfo">
-            <includePath path="$(SDK6_LOCATION)headers"/>
-            <includePath path="$(SDK6_LOCATION)headers\EntryNums"/>
-            <includePath path="$(SDK6_LOCATION)headers\posix"/>
-            <includePath path="$(SDK6_LOCATION)headers\posix\arm"/>
-            <includePath path="$(SDK6_LOCATION)headers\posix\arpa"/>
-            <includePath path="$(SDK6_LOCATION)headers\posix\machine"/>
-            <includePath path="$(SDK6_LOCATION)headers\posix\machine\arm"/>
-            <includePath path="$(SDK6_LOCATION)headers\posix\machine\x86"/>
-            <includePath path="$(SDK6_LOCATION)headers\posix\net"/>
-            <includePath path="$(SDK6_LOCATION)headers\posix\netinet"/>
-            <includePath path="$(SDK6_LOCATION)headers\posix\sys"/>
-            <includePath path="$(SDK6_LOCATION)headers\streams"/>
-            <definedSymbol symbol="__arm__"/>
-        </item>
-    </data>
+<extension point="org.eclipse.cdt.core.BinaryParser" id="org.eclipse.cdt.core.PE"/>
+<data>
+        
+    <item id="org.eclipse.cdt.core.pathentry">
+<pathentry kind="src" path=""/>
+<pathentry kind="out" path=""/>
+<pathentry kind="mac" path="" name="__arm__" value="1"/>
+<pathentry kind="con" path="org.eclipse.cdt.make.core.DISCOVERED_SCANNER_INFO"/>
+</item>
+</data>
 </cdtproject>
diff --git a/build/palmos/.project b/build/palmos/.project
index c8debc9bac..5074e6309e 100644
--- a/build/palmos/.project
+++ b/build/palmos/.project
@@ -29,25 +29,29 @@
 					<value>1</value>
 				</dictionary>
 				<dictionary>
-					<key>SDK</key>
-					<value>com.palmsource.eclipse.sdk.palmos6</value>
+					<key>PROJECT_VERSION</key>
+					<value>10100</value>
 				</dictionary>
 				<dictionary>
 					<key>DB_RESET_INSTALL</key>
 					<value>false</value>
 				</dictionary>
 				<dictionary>
-					<key>APP_NAME</key>
-					<value>wxWidgets</value>
+					<key>SDK</key>
+					<value>com.palmsource.eclipse.sdk.palmos6</value>
 				</dictionary>
 				<dictionary>
-					<key>PROJECT_NAME</key>
+					<key>APP_NAME</key>
 					<value>wxWidgets</value>
 				</dictionary>
 				<dictionary>
 					<key>OS_API</key>
 					<value>Protein</value>
 				</dictionary>
+				<dictionary>
+					<key>PROJECT_NAME</key>
+					<value>wxWidgets</value>
+				</dictionary>
 				<dictionary>
 					<key>PROJECT_TYPE</key>
 					<value>appl</value>
@@ -115,6 +119,47 @@
 				</dictionary>
 			</arguments>
 		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name>
+			<arguments>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.ScannerConfigDiscoveryEnabled</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.makeBuilderParserId</key>
+					<value>org.eclipse.cdt.make.core.GCCScannerInfoConsoleParser</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.esiProviderCommandEnabled</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.siProblemGenerationEnabled</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.useDefaultESIProviderCmd</key>
+					<value>false</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.makeBuilderParserEnabled</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.esiProviderArguments</key>
+					<value>-E -P -v ${plugin_state_location}/${specs_file}</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.esiProviderParserId</key>
+					<value>org.eclipse.cdt.make.core.GCCSpecsConsoleParser</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.esiProviderCommand</key>
+					<value>gcc</value>
+				</dictionary>
+			</arguments>
+		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>com.palmsource.eclipse.palmos6dev.palmOSProteinNature</nature>
@@ -122,5 +167,6 @@
 		<nature>org.eclipse.cdt.core.cnature</nature>
 		<nature>org.eclipse.cdt.make.core.makeNature</nature>
 		<nature>org.eclipse.cdt.core.ccnature</nature>
+		<nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature>
 	</natures>
 </projectDescription>
diff --git a/build/palmos/auto-generated.mk b/build/palmos/auto-generated.mk
index 42b70323f5..0b35c59573 100644
--- a/build/palmos/auto-generated.mk
+++ b/build/palmos/auto-generated.mk
@@ -7,7 +7,7 @@ endif
 
 # This value is unescaped.  Either quote the value or escape special characters when you use it.
 ifeq ($(SDK_LOCATION), )
-   SDK_LOCATION = C:/Program Files/PalmSource/Palm OS Developer Suite/sdk-6/
+   SDK_LOCATION = C:/Program Files/PalmSource/Palm OS Developer Suite/sdk-6.1/
 endif
 
 ifeq ($(SDK_VERSION), )
@@ -34,26 +34,30 @@ ifeq ($(VERSION), )
    VERSION = 1
 endif
 
-ifeq ($(DB_RESET_INSTALL), )
-   DB_RESET_INSTALL = false
+ifeq ($(PROJECT_VERSION), )
+   PROJECT_VERSION = 10100
 endif
 
 ifeq ($(SDK), )
    SDK = com.palmsource.eclipse.sdk.palmos6
 endif
 
-ifeq ($(APP_NAME), )
-   APP_NAME = wxWidgets
+ifeq ($(DB_RESET_INSTALL), )
+   DB_RESET_INSTALL = false
 endif
 
-ifeq ($(OS_API), )
-   OS_API = Protein
+ifeq ($(APP_NAME), )
+   APP_NAME = wxWidgets
 endif
 
 ifeq ($(PROJECT_NAME), )
    PROJECT_NAME = wxWidgets
 endif
 
+ifeq ($(OS_API), )
+   OS_API = Protein
+endif
+
 ifeq ($(PROJECT_TYPE), )
    PROJECT_TYPE = appl
 endif
diff --git a/build/palmos/makefile b/build/palmos/makefile
index 017766a090..0621493585 100644
--- a/build/palmos/makefile
+++ b/build/palmos/makefile
@@ -10,6 +10,9 @@
 #	2. Review the other settings as needed.
 #
 ## --------------------------------------------------------------------------
+INSTALL=install
+INSTALL_DATA=${INSTALL} -m 644
+INSTALL_DIR=${INSTALL} -d
 
 SHELL = /bin/sh
 ## conditionally include an auto-generated.mk for dynamic definitions
@@ -42,13 +45,17 @@ PRC_NAME = wxWidgets.prc
 # TODO: Update all sources and resources
 
 BASE_CMN_SRC = \
+../../src/common/arrstr.cpp \
 ../../src/common/appbase.cpp \
 ../../src/common/archive.cpp \
+../../src/common/btncmn.cpp \
 ../../src/common/clntdata.cpp \
 ../../src/common/cmdline.cpp \
 ../../src/common/config.cpp \
+../../src/common/convauto.cpp \
 ../../src/common/datetime.cpp \
 ../../src/common/datstrm.cpp \
+../../src/common/dcbufcmn.cpp \
 ../../src/common/dircmn.cpp \
 ../../src/common/dynarray.cpp \
 ../../src/common/dynlib.cpp \
@@ -84,15 +91,20 @@ BASE_CMN_SRC = \
 ../../src/common/strconv.cpp \
 ../../src/common/stream.cpp \
 ../../src/common/string.cpp \
+../../src/common/stringimpl.cpp \
+../../src/common/stringops.cpp \
+../../src/common/strvararg.cpp \
 ../../src/common/sysopt.cpp \
 ../../src/common/textbuf.cpp \
 ../../src/common/textfile.cpp \
 ../../src/common/tokenzr.cpp \
 ../../src/common/txtstrm.cpp \
+../../src/common/unichar.cpp \
 ../../src/common/uri.cpp \
 ../../src/common/variant.cpp \
 ../../src/common/wfstream.cpp \
-../../src/common/wxchar.cpp \
+../../src/common/wxcrt.cpp \
+../../src/common/wxprintf.cpp \
 ../../src/common/xti.cpp \
 ../../src/common/xtistrm.cpp \
 ../../src/common/zipstrm.cpp \
@@ -130,6 +142,7 @@ NET_CMN_SRC = \
 ../../src/common/url.cpp
 
 PALMOS_LOWLEVEL_SRC = \
+../../src/palmos/stdall.c \
 ../../src/palmos/app.cpp \
 ../../src/palmos/bitmap.cpp \
 ../../src/palmos/brush.cpp \
@@ -280,6 +293,7 @@ GUI_CMN_SRC = \
 ../../src/common/settcmn.cpp \
 ../../src/common/sizer.cpp \
 ../../src/common/statbar.cpp \
+../../src/common/stattextcmn.cpp \
 ../../src/common/stockitem.cpp \
 ../../src/common/tbarbase.cpp \
 ../../src/common/textcmn.cpp \
@@ -451,6 +465,9 @@ $(XML_SRC) \
 $(OPENGL_SRC) \
 ../../src/palmos/progdlg.cpp
 
+#include othersrc.mak
+#SOURCES += $(OTHER_SRC)
+
 RESOURCES = ../../include/wx/palmos/wxWidgets.xrd ../../include/wx/palmos/Version.xrd
 DEFS_FILE = ../../include/wx/palmos/wxWidgets.def
 SLD_FILE = ../../include/wx/palmos/wxWidgets.sld
@@ -500,7 +517,10 @@ DEBUG_OR_RELEASE=Debug
 # Set the target platform for the build; either Device or Simulator
 # Use Device as a target for emulator builds.
 #
-TARGET_PLATFORM=Simulator
+#TARGET_PLATFORM=Simulator
+TARGET_PLATFORM=Device
+
+#TARGET_FORMAT=PalmOS4
 
 # Specify the level of optimization that you want:
 # NONE, SOME, FULL, INTRAPROCEDURAL, INTERPROCEDURAL, INLINING.
@@ -535,7 +555,8 @@ ADDITIONAL_SIM_LINK_LIBRARIES =
 # Additionally, you must explicly specify the "-I" prior to each
 # path included in this variable.  Spaces are used to separate
 # each path from each other.
-LOCAL_INCLUDE_PATHS = -Irsc -I../../lib/gcc_lib/palmos -I../../include
+incdir=../../lib/gcc_lib/palmos
+LOCAL_INCLUDE_PATHS = -Irsc -I$(incdir) -I../../include
 LOCAL_SIM_INCLUDE_PATHS = $(LOCAL_INCLUDE_PATHS)
 
 # Additional paths to look for #include <header>
diff --git a/build/palmos/makefile-engine.mk b/build/palmos/makefile-engine.mk
index 817be3e202..522acf7f61 100644
--- a/build/palmos/makefile-engine.mk
+++ b/build/palmos/makefile-engine.mk
@@ -160,7 +160,9 @@ endif
 ###############################################################################
 # Compile and Link Settings
 
+ifeq ($(TARGET_FORMAT), )
 TARGET_FORMAT=PalmOS6
+endif
 
 # Compiler settings... compiler + optimizations + debug
 # This is a makefile for Palm OS 6 so the compilers used are as follows:
@@ -428,6 +430,7 @@ SLD_SIM_OBJ := $(addprefix $(SIM_OBJ_DIR)/, $(addsuffix .o, $(SLD_BASENAME)))
 VPATH :=
 VPATH += $(addprefix :, $(subst  ,:, $(filter-out $($(subst, :, ,$(VPATH))), $(SOURCE_PATHS) $(RESOURCE_PATHS) )))
 
+# -I "$(SDK_LOCATION)include" -I "$(SDK_LOCATION)include/Core/System" #
 SYSTEM_INCLUDES = $(SYSTEM_INCLUDE_PATHS) -I "$(SDK_LOCATION)headers" -I "$(SDK_LOCATION)headers/posix"
 INCLUDES = $(LOCAL_INCLUDE_PATHS) $(foreach path, $(SOURCE_PATHS), $(addprefix -I, $(path))) $(SYSTEM_INCLUDES) $(PRE_INCLUDE_PATHS)
 CPP_INCLUDES = -I "$(TOOLS_DIR)include/stlport"
@@ -602,10 +605,15 @@ $(RSC_OBJ_DIR)/%.trc : %.XRD makefile
 $(SLD_OBJ) : makefile
 	@echo "...Processing definition file for Device..."
 	"$(TOOLS_DIR)pslib" -inDef "$(SLD_FILE)" $(PSLIB_DEV_FLAGS) -outObjStartup $@ -type '$(DB_TYPE)' -creator '$(CREATOR_ID)' -execName $(DATABASE_NAME)
+	$(INSTALL_DIR) $(incdir)/wx/
+	$(INSTALL_DATA) ../../include/wx/palmos/setup0.h $(incdir)/wx/setup.h
+	
 	
 $(SLD_SIM_OBJ) : makefile
 	@echo "...Processing definition file for Simulator..."
 	"$(TOOLS_DIR)pslib" -inDef "$(SLD_FILE)" $(PSLIB_SIM_FLAGS) -outSimStartup $@ -outSimRsrc $(SIM_OBJ_DIR)/acod0000.bin  -outSimDefs $(SIM_OBJ_DIR)/gcc_link.def -type '$(DB_TYPE)' -creator '$(CREATOR_ID)' -execName $(DATABASE_NAME)
+	$(INSTALL_DIR) $(incdir)/wx/
+	$(INSTALL_DATA) ../../include/wx/palmos/setup0.h $(incdir)/wx/setup.h
 
 # Linking step
 $(LINKER_OUTPUT) : $(OBJS)
diff --git a/include/wx/defs.h b/include/wx/defs.h
index 5550a48455..abe2500e52 100644
--- a/include/wx/defs.h
+++ b/include/wx/defs.h
@@ -204,6 +204,9 @@
             #define false ((bool)0)
         #endif
         #define HAVE_BOOL
+    #elif defined(__WXPALMOS__)
+        /*  Palm OS supports bool */
+        #define HAVE_BOOL
     #endif /*  compilers */
 #endif /*  HAVE_BOOL */
 
@@ -563,7 +566,7 @@ typedef int wxWindowID;
 /*  NULL declaration: it must be defined as 0 for C++ programs (in particular, */
 /*  it must not be defined as "(void *)0" which is standard for C but completely */
 /*  breaks C++ code) */
-#ifndef __HANDHELDPC__
+#if !defined(__HANDHELDPC__) && !defined(__PALMOS__)
 #include <stddef.h>
 #endif
 
@@ -751,7 +754,9 @@ enum {  wxDefaultCoord = -1 };
 /*  ---------------------------------------------------------------------------- */
 
 #if defined(__WXPALMOS__) || defined(__MINGW32__)
+  #if !defined(__MWERKS__)
     #include <sys/types.h>
+  #endif
 #endif
 
 /*  chars are always one byte (by definition), shorts are always two (in */
@@ -807,7 +812,9 @@ typedef wxUint16 wxWord;
     #define SIZEOF_LONG 4
     #define SIZEOF_WCHAR_T 2
     #define SIZEOF_SIZE_T 4
-    #define wxSIZE_T_IS_UINT
+    #ifdef __WXPALMOS6__
+        #define wxSIZE_T_IS_UINT
+    #endif
     #define SIZEOF_VOID_P 4
     #define SIZEOF_SIZE_T 4
 #elif defined(__WINDOWS__)
@@ -1058,7 +1065,11 @@ inline void *wxUIntToPtr(wxUIntPtr p)
         #error "See the documentation on the 'longlong' pragma."
     #endif
 #elif defined(__WXPALMOS__)
-    #define wxLongLong_t int64_t
+    #if defined(__WXPALMOS6__)
+        #define wxLongLong_t int64_t
+    #else
+        #define wxLongLong_t long long
+    #endif /* __WXPALMOS6__ */
     #define wxLongLongSuffix ll
     #define wxLongLongFmtSpec _T("ll")
 #elif defined(__VISAGECPP__) && __IBMCPP__ >= 400
@@ -1082,7 +1093,11 @@ inline void *wxUIntToPtr(wxUIntPtr p)
 #ifdef wxLongLong_t
 
     #ifdef __WXPALMOS__
+    #if defined(__WXPALMOS6__)
         #define wxULongLong_t uint64_t
+    #else
+        #define wxULongLong_t unsigned long long
+    #endif /* __WXPALMOS6__ */
     #else
         #define wxULongLong_t unsigned wxLongLong_t
     #endif
diff --git a/include/wx/filefn.h b/include/wx/filefn.h
index ba57e38001..a36505eb1c 100644
--- a/include/wx/filefn.h
+++ b/include/wx/filefn.h
@@ -15,6 +15,7 @@
 #include "wx/list.h"
 #include "wx/arrstr.h"
 
+#ifndef __WXPALMOS5__
 #ifdef __WXWINCE__
     #include "wx/msw/wince/time.h"
     #include "wx/msw/private.h"
@@ -39,6 +40,7 @@
         #include <unix.h>
     #endif
 #endif
+#endif // !__WXPALMOS5__
 
 #ifdef __OS2__
 // need to check for __OS2__ first since currently both
@@ -88,9 +90,11 @@
     #include <unix.h>
 #endif
 
+#ifndef __WXPALMOS5__
 #ifndef __WXWINCE__
     #include  <fcntl.h>       // O_RDONLY &c
 #endif
+#endif // !__WXPALMOS5__
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -116,6 +120,8 @@
     typedef long off_t;
 #elif defined(__MWERKS__) && !defined(__INTEL__) && !defined(__MACH__)
     typedef long off_t;
+#elif defined(__WXPALMOS5__)
+    typedef long off_t;
 #endif
 
 enum wxSeekMode
@@ -615,6 +621,9 @@ WXDLLIMPEXP_BASE bool wxIsExecutable(const wxString &path);
   // CYGWIN also uses UNIX settings
   #define wxFILE_SEP_PATH     wxFILE_SEP_PATH_UNIX
   #define wxPATH_SEP          wxPATH_SEP_UNIX
+#elif defined(__WXPALMOS__)
+  #define wxFILE_SEP_PATH     wxFILE_SEP_PATH_UNIX
+  #define wxPATH_SEP          wxPATH_SEP_UNIX
 #elif defined(__MAC__)
   #define wxFILE_SEP_PATH     wxFILE_SEP_PATH_MAC
   #define wxPATH_SEP          wxPATH_SEP_MAC
diff --git a/include/wx/palmos/apptrait.h b/include/wx/palmos/apptrait.h
index af90da7225..1a2f4b4522 100644
--- a/include/wx/palmos/apptrait.h
+++ b/include/wx/palmos/apptrait.h
@@ -19,13 +19,17 @@
 class WXDLLIMPEXP_BASE wxConsoleAppTraits : public wxConsoleAppTraitsBase
 {
 public:
+#if wxUSE_CONSOLE_EVENTLOOP
+    virtual wxEventLoopBase *CreateEventLoop();
+#endif // wxUSE_CONSOLE_EVENTLOOP
     virtual void *BeforeChildWaitLoop();
     virtual void AlwaysYield();
     virtual void AfterChildWaitLoop(void *data);
 #if wxUSE_TIMER
-    virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) { return NULL; };
+    virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) { return new wxPalmOSTimerImpl(timer); }
 #endif
     virtual bool DoMessageFromThreadWait();
+    virtual WXDWORD WaitForThread(WXHANDLE hThread);
 };
 
 #if wxUSE_GUI
@@ -33,6 +37,7 @@ public:
 class WXDLLIMPEXP_CORE wxGUIAppTraits : public wxGUIAppTraitsBase
 {
 public:
+    virtual wxEventLoopBase *CreateEventLoop();
     virtual void *BeforeChildWaitLoop();
     virtual void AlwaysYield();
     virtual void AfterChildWaitLoop(void *data);
diff --git a/include/wx/palmos/chkconf.h b/include/wx/palmos/chkconf.h
index ba0dc19b85..6cb458fdfd 100644
--- a/include/wx/palmos/chkconf.h
+++ b/include/wx/palmos/chkconf.h
@@ -150,6 +150,9 @@
 #undef wxUSE_ICO_CUR
 #define wxUSE_ICO_CUR 0
 
+#undef wxUSE_SVG
+#define wxUSE_SVG 0
+
 #undef wxUSE_INTL
 #define wxUSE_INTL 0
 
@@ -303,8 +306,8 @@
 #undef wxUSE_URL
 #define wxUSE_URL 0
 
-#undef wxUSE_WCHAR_T
-#define wxUSE_WCHAR_T 0
+//#undef wxUSE_WCHAR_T
+//#define wxUSE_WCHAR_T 1
 
 #undef wxUSE_WIZARDDLG
 #define wxUSE_WIZARDDLG 0
@@ -324,5 +327,11 @@
 #undef wxUSE_ZLIB
 #define wxUSE_ZLIB 0
 
+#undef wxUSE_COLLPANE
+#define wxUSE_COLLPANE 0
+
+#undef wxUSE_TOOLBOOK
+#define wxUSE_TOOLBOOK 0
+
 #endif
     /* _WX_PALMOS_CHKCONF_H_ */
diff --git a/include/wx/palmos/control.h b/include/wx/palmos/control.h
index fe88a5974e..849ad78d26 100644
--- a/include/wx/palmos/control.h
+++ b/include/wx/palmos/control.h
@@ -48,7 +48,7 @@ public:
     virtual bool IsShown() const;
 
     virtual void SetLabel(const wxString& label);
-    virtual wxString GetLabel();
+    //virtual wxString GetLabel();
 
     // implementation from now on
     // --------------------------
diff --git a/include/wx/palmos/dc.h b/include/wx/palmos/dc.h
index 56ce10b190..0e02472e31 100644
--- a/include/wx/palmos/dc.h
+++ b/include/wx/palmos/dc.h
@@ -9,8 +9,8 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifndef _WX_DC_H_
-#define _WX_DC_H_
+#ifndef _WX_PALM_DC_H_
+#define _WX_PALM_DC_H_
 
 #include "wx/defs.h"
 #include "wx/dc.h"
@@ -41,11 +41,13 @@ public:
 };
 #endif
 
-class WXDLLEXPORT wxDC : public wxDCBase
+// this is an ABC: use one of the derived classes to create a DC associated
+// with a window, screen, printer and so on
+class WXDLLEXPORT wxPalmDCImpl: public wxDCImpl
 {
 public:
-    wxDC();
-    virtual ~wxDC();
+    wxPalmDCImpl(wxDC *owner, WXHDC hDC);
+    virtual ~wxPalmDCImpl();
 
     // implement base class pure virtuals
     // ----------------------------------
@@ -71,46 +73,31 @@ public:
 
     virtual wxCoord GetCharHeight() const;
     virtual wxCoord GetCharWidth() const;
-    virtual void DoGetTextExtent(const wxString& string,
-                                 wxCoord *x, wxCoord *y,
-                                 wxCoord *descent = NULL,
-                                 wxCoord *externalLeading = NULL,
-                                 const wxFont *theFont = NULL) const;
-    virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
 
     virtual bool CanDrawBitmap() const;
     virtual bool CanGetTextExtent() const;
     virtual int GetDepth() const;
     virtual wxSize GetPPI() const;
 
+
     virtual void SetMapMode(int mode);
     virtual void SetUserScale(double x, double y);
-    virtual void SetSystemScale(double x, double y);
     virtual void SetLogicalScale(double x, double y);
     virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
     virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
     virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
+
     virtual void SetLogicalFunction(int function);
 
-    virtual wxCoord DeviceToLogicalX(wxCoord x) const;
-    virtual wxCoord DeviceToLogicalY(wxCoord y) const;
-    virtual wxCoord DeviceToLogicalXRel(wxCoord x) const;
-    virtual wxCoord DeviceToLogicalYRel(wxCoord y) const;
-    virtual wxCoord LogicalToDeviceX(wxCoord x) const;
-    virtual wxCoord LogicalToDeviceY(wxCoord y) const;
-    virtual wxCoord LogicalToDeviceXRel(wxCoord x) const;
-    virtual wxCoord LogicalToDeviceYRel(wxCoord y) const ;
-    
     // implementation from now on
     // --------------------------
 
     virtual void SetRop(WXHDC cdc);
     virtual void SelectOldObjects(WXHDC dc);
 
-    wxWindow *GetWindow() const { return m_canvas; }
     void SetWindow(wxWindow *win)
     {
-        m_canvas = win;
+        m_window = win;
 
 #if wxUSE_PALETTE
         // if we have palettes use the correct one for this window
@@ -119,7 +106,7 @@ public:
     }
 
     WXHDC GetHDC() const { return m_hDC; }
-    void SetHDC(WXHDC dc, bool bOwnsDC = FALSE)
+    void SetHDC(WXHDC dc, bool bOwnsDC = false)
     {
         m_hDC = dc;
         m_bOwnsDC = bOwnsDC;
@@ -147,10 +134,52 @@ public:
     static void ClearCache();
 #endif
 
+    // RTL related functions
+    // ---------------------
+
+    // get or change the layout direction (LTR or RTL) for this dc,
+    // wxLayout_Default is returned if layout direction is not supported
+    virtual wxLayoutDirection GetLayoutDirection() const;
+    virtual void SetLayoutDirection(wxLayoutDirection dir);
+
 protected:
+    void Init()
+    {
+        m_bOwnsDC = false;
+        m_hDC = NULL;
+
+        m_oldBitmap = NULL;
+        m_oldPen = NULL;
+        m_oldBrush = NULL;
+        m_oldFont = NULL;
+
+#if wxUSE_PALETTE
+        m_oldPalette = NULL;
+#endif // wxUSE_PALETTE
+    }
+
+    // create an uninitialized DC: this should be only used by the derived
+    // classes
+    wxPalmDCImpl( wxDC *owner ) : wxDCImpl( owner ) { Init(); }
+
+    void RealizeScaleAndOrigin();
+
+public:
+    virtual void DoGetTextExtent(const wxString& string,
+                                 wxCoord *x, wxCoord *y,
+                                 wxCoord *descent = NULL,
+                                 wxCoord *externalLeading = NULL,
+                                 const wxFont *theFont = NULL) const;
+    virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
+
     virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
                              int style = wxFLOOD_SURFACE);
 
+    virtual void DoGradientFillLinear(const wxRect& rect,
+                                      const wxColour& initialColour,
+                                      const wxColour& destColour,
+                                      wxDirection nDirection = wxEAST);
+
     virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
 
     virtual void DoDrawPoint(wxCoord x, wxCoord y);
@@ -170,11 +199,15 @@ protected:
                                         double radius);
     virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
 
+#if wxUSE_SPLINES
+    virtual void DoDrawSpline(const wxPointList *points);
+#endif
+
     virtual void DoCrossHair(wxCoord x, wxCoord y);
 
     virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
     virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
-                              bool useMask = FALSE);
+                              bool useMask = false);
 
     virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
     virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
@@ -182,7 +215,15 @@ protected:
 
     virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
                         wxDC *source, wxCoord xsrc, wxCoord ysrc,
-                        int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
+                        int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
+
+    virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest,
+                               wxCoord dstWidth, wxCoord dstHeight,
+                               wxDC *source,
+                               wxCoord xsrc, wxCoord ysrc,
+                               wxCoord srcWidth, wxCoord srcHeight,
+                               int rop = wxCOPY, bool useMask = false,
+                               wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
 
     // this is gnarly - we can't even call this function DoSetClippingRegion()
     // because of virtual function hiding
@@ -192,7 +233,6 @@ protected:
     virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
                                   wxCoord *w, wxCoord *h) const;
 
-    virtual void DoGetSize(int *width, int *height) const;
     virtual void DoGetSizeMM(int* width, int* height) const;
 
     virtual void DoDrawLines(int n, wxPoint points[],
@@ -203,6 +243,11 @@ protected:
     virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
                                    wxCoord xoffset, wxCoord yoffset,
                                    int fillStyle = wxODDEVEN_RULE);
+    virtual wxBitmap DoGetAsBitmap(const wxRect *subrect) const
+    {
+        return subrect == NULL ? GetSelectedBitmap()
+                               : GetSelectedBitmap().GetSubBitmap(*subrect);
+    }
 
 
 #if wxUSE_PALETTE
@@ -210,18 +255,30 @@ protected:
     // (tell windows to translate pixel from other palettes to our custom one
     // and vice versa)
     // Realize tells it to also reset the system palette to this one.
-    void DoSelectPalette(bool realize = FALSE);
+    void DoSelectPalette(bool realize = false);
 
     // Find out what palette our parent window has, then select it into the dc
     void InitializePalette();
 #endif // wxUSE_PALETTE
 
+protected:
     // common part of DoDrawText() and DoDrawRotatedText()
     void DrawAnyText(const wxString& text, wxCoord x, wxCoord y);
 
     // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
     void SetClippingHrgn(WXHRGN hrgn);
 
+    // implementation of DoGetSize() for wxScreen/PrinterDC: this simply
+    // returns the size of the entire device this DC is associated with
+    //
+    // notice that we intentionally put it in a separate function instead of
+    // DoGetSize() itself because we want it to remain pure virtual both
+    // because each derived class should take care to define it as needed (this
+    // implementation is not at all always appropriate) and because we want
+    // wxDC to be an ABC to prevent it from being created directly
+    void GetDeviceSize(int *width, int *height) const;
+
+
     // MSW-specific member variables
     // -----------------------------
 
@@ -249,12 +306,12 @@ protected:
 #endif // wxUSE_PALETTE
 
 #if wxUSE_DC_CACHEING
-    static wxList     sm_bitmapCache;
-    static wxList     sm_dcCache;
+    static wxObjectList     sm_bitmapCache;
+    static wxObjectList     sm_dcCache;
 #endif
 
-    DECLARE_DYNAMIC_CLASS(wxDC)
-    DECLARE_NO_COPY_CLASS(wxDC)
+    DECLARE_CLASS(wxPalmDCImpl)
+    DECLARE_NO_COPY_CLASS(wxPalmDCImpl)
 };
 
 // ----------------------------------------------------------------------------
@@ -262,15 +319,50 @@ protected:
 // only/mainly)
 // ----------------------------------------------------------------------------
 
-class WXDLLEXPORT wxDCTemp : public wxDC
+class WXDLLEXPORT wxDCTempImpl : public wxPalmDCImpl
 {
 public:
-    wxDCTemp(WXHDC hdc) { SetHDC(hdc); }
-    virtual ~wxDCTemp() { SetHDC((WXHDC)NULL); }
+    // construct a temporary DC with the specified HDC and size (it should be
+    // specified whenever we know it for this HDC)
+    wxDCTempImpl(wxDC *owner, WXHDC hdc, const wxSize& size )
+        : wxPalmDCImpl( owner, hdc ),
+          m_size(size)
+    {
+    }
+
+    virtual ~wxDCTempImpl()
+    {
+        // prevent base class dtor from freeing it
+        SetHDC((WXHDC)NULL);
+    }
+
+    virtual void DoGetSize(int *w, int *h) const
+    {
+        wxASSERT_MSG( m_size.IsFullySpecified(),
+                      _T("size of this DC hadn't been set and is unknown") );
+
+        if ( w )
+            *w = m_size.x;
+        if ( h )
+            *h = m_size.y;
+    }
 
 private:
-    DECLARE_NO_COPY_CLASS(wxDCTemp)
+    // size of this DC must be explicitly set by SetSize() as we have no way to
+    // find it ourselves
+    const wxSize m_size;
+
+    DECLARE_NO_COPY_CLASS(wxDCTempImpl)
+};
+
+class WXDLLEXPORT wxDCTemp : public wxDC
+{
+public:
+    wxDCTemp(WXHDC hdc, const wxSize& size = wxDefaultSize)
+        : wxDC(new wxDCTempImpl(this, hdc, size))
+    {
+    }
 };
 
 #endif
-    // _WX_DC_H_
+    // _WX_PALM_DC_H_
diff --git a/include/wx/palmos/dcclient.h b/include/wx/palmos/dcclient.h
index 5ac553fbb7..af3f15e8da 100644
--- a/include/wx/palmos/dcclient.h
+++ b/include/wx/palmos/dcclient.h
@@ -17,6 +17,8 @@
 // ----------------------------------------------------------------------------
 
 #include "wx/dc.h"
+#include "wx/palmos/dc.h"
+#include "wx/dcclient.h"
 #include "wx/dynarray.h"
 
 // ----------------------------------------------------------------------------
@@ -32,56 +34,54 @@ WX_DECLARE_EXPORTED_OBJARRAY(wxPaintDCInfo, wxArrayDCInfo);
 // DC classes
 // ----------------------------------------------------------------------------
 
-class WXDLLEXPORT wxWindowDC : public wxDC
+class WXDLLEXPORT wxWindowDCImpl : public wxPalmDCImpl
 {
 public:
     // default ctor
-    wxWindowDC();
+    wxWindowDCImpl( wxDC *owner );
 
     // Create a DC corresponding to the whole window
-    wxWindowDC(wxWindow *win);
+    wxWindowDCImpl( wxDC *owner, wxWindow *win );
+
+    virtual void DoGetSize(int *width, int *height) const;
 
 protected:
     // initialize the newly created DC
     void InitDC();
 
-    // override some base class virtuals
-    virtual void DoGetSize(int *width, int *height) const;
-
-private:
-    DECLARE_DYNAMIC_CLASS_NO_COPY(wxWindowDC)
+    DECLARE_CLASS(wxWindowDCImpl)
+    DECLARE_NO_COPY_CLASS(wxWindowDCImpl)
 };
 
-class WXDLLEXPORT wxClientDC : public wxWindowDC
+class WXDLLEXPORT wxClientDCImpl : public wxWindowDCImpl
 {
 public:
     // default ctor
-    wxClientDC();
+    wxClientDCImpl( wxDC *owner );
 
     // Create a DC corresponding to the client area of the window
-    wxClientDC(wxWindow *win);
+    wxClientDCImpl( wxDC *owner, wxWindow *win );
 
-    virtual ~wxClientDC();
+    virtual ~wxClientDCImpl();
+
+    virtual void DoGetSize(int *width, int *height) const;
 
 protected:
     void InitDC();
 
-    // override some base class virtuals
-    virtual void DoGetSize(int *width, int *height) const;
-
-private:
-    DECLARE_DYNAMIC_CLASS_NO_COPY(wxClientDC)
+    DECLARE_CLASS(wxClientDCImpl)
+    DECLARE_NO_COPY_CLASS(wxClientDCImpl)
 };
 
-class WXDLLEXPORT wxPaintDC : public wxClientDC
+class WXDLLEXPORT wxPaintDCImpl : public wxClientDCImpl
 {
 public:
-    wxPaintDC();
+    wxPaintDCImpl( wxDC *owner );
 
     // Create a DC corresponding for painting the window in OnPaint()
-    wxPaintDC(wxWindow *win);
+    wxPaintDCImpl( wxDC *owner, wxWindow *win );
 
-    virtual ~wxPaintDC();
+    virtual ~wxPaintDCImpl();
 
     // find the entry for this DC in the cache (keyed by the window)
     static WXHDC FindDCInCache(wxWindow* win);
@@ -92,26 +92,8 @@ protected:
     // find the entry for this DC in the cache (keyed by the window)
     wxPaintDCInfo *FindInCache(size_t *index = NULL) const;
 
-private:
-    DECLARE_DYNAMIC_CLASS_NO_COPY(wxPaintDC)
-};
-
-/*
- * wxPaintDCEx
- * This class is used when an application sends an HDC with the WM_PAINT
- * message. It is used in HandlePaint and need not be used by an application.
- */
-
-class WXDLLEXPORT wxPaintDCEx : public wxPaintDC
-{
-public:
-    wxPaintDCEx(wxWindow *canvas, WXHDC dc);
-    virtual ~wxPaintDCEx();
-private:
-    int saveState;
-
-    DECLARE_CLASS(wxPaintDCEx)
-    DECLARE_NO_COPY_CLASS(wxPaintDCEx)
+    DECLARE_CLASS(wxPaintDCImpl)
+    DECLARE_NO_COPY_CLASS(wxPaintDCImpl)
 };
 
 #endif
diff --git a/include/wx/palmos/dcmemory.h b/include/wx/palmos/dcmemory.h
index 580ea68bbc..c1125eee7b 100644
--- a/include/wx/palmos/dcmemory.h
+++ b/include/wx/palmos/dcmemory.h
@@ -12,29 +12,31 @@
 #ifndef _WX_DCMEMORY_H_
 #define _WX_DCMEMORY_H_
 
-#include "wx/dcclient.h"
+#include "wx/dcmemory.h"
+#include "wx/palmos/dc.h"
 
-class WXDLLEXPORT wxMemoryDC : public wxDC, public wxMemoryDCBase
+class WXDLLEXPORT wxMemoryDCImpl: public wxPalmDCImpl
 {
 public:
-    wxMemoryDC() { Init(); }
-    wxMemoryDC(wxBitmap& bitmap) { Init(); SelectObject(bitmap); }
-    wxMemoryDC(wxDC *dc); // Create compatible DC
+    wxMemoryDCImpl( wxMemoryDC *owner );
+    wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap );
+    wxMemoryDCImpl( wxMemoryDC *owner, wxDC *dc ); // Create compatible DC
 
-protected:
     // override some base class virtuals
-    virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
     virtual void DoGetSize(int* width, int* height) const;
     virtual void DoSelect(const wxBitmap& bitmap);
 
+    virtual wxBitmap DoGetAsBitmap(const wxRect* subrect) const;
+
+protected:
     // create DC compatible with the given one or screen if dc == NULL
     bool CreateCompatible(wxDC *dc);
 
     // initialize the newly created DC
     void Init();
 
-private:
-    DECLARE_DYNAMIC_CLASS_NO_COPY(wxMemoryDC)
+    DECLARE_CLASS(wxMemoryDCImpl)
+    DECLARE_NO_COPY_CLASS(wxMemoryDCImpl)
 };
 
 #endif
diff --git a/include/wx/palmos/dcscreen.h b/include/wx/palmos/dcscreen.h
index 257647cb1c..f0c5f2a97c 100644
--- a/include/wx/palmos/dcscreen.h
+++ b/include/wx/palmos/dcscreen.h
@@ -12,24 +12,19 @@
 #ifndef _WX_DCSCREEN_H_
 #define _WX_DCSCREEN_H_
 
-#include "wx/dcclient.h"
+#include "wx/dcscreen.h"
+#include "wx/palmos/dc.h"
 
-class WXDLLEXPORT wxScreenDC : public wxWindowDC
+class WXDLLEXPORT wxScreenDCImpl : public wxPalmDCImpl
 {
 public:
     // Create a DC representing the whole screen
-    wxScreenDC();
+    wxScreenDCImpl( wxScreenDC *owner );
 
-    // Compatibility with X's requirements for drawing on top of all windows
-    static bool StartDrawingOnTop(wxWindow* WXUNUSED(window)) { return TRUE; }
-    static bool StartDrawingOnTop(wxRect* WXUNUSED(rect) = NULL) { return TRUE; }
-    static bool EndDrawingOnTop() { return TRUE; }
+    virtual void DoGetSize(int *w, int *h) const;
 
-protected:
-    virtual void DoGetSize(int *width, int *height) const;
-
-private:
-    DECLARE_DYNAMIC_CLASS_NO_COPY(wxScreenDC)
+    DECLARE_CLASS(wxScreenDCImpl)
+    DECLARE_NO_COPY_CLASS(wxScreenDCImpl)
 };
 
 #endif
diff --git a/include/wx/palmos/dialog.h b/include/wx/palmos/dialog.h
index ef6f5b3dcd..a2b9f74506 100644
--- a/include/wx/palmos/dialog.h
+++ b/include/wx/palmos/dialog.h
@@ -14,7 +14,7 @@
 
 #include "wx/panel.h"
 
-WXDLLEXPORT_DATA(extern const wxChar) wxDialogNameStr[];
+//WXDLLEXPORT_DATA(extern const wxChar) wxDialogNameStr[];
 
 class WXDLLIMPEXP_FWD_CORE wxDialogModalData;
 
diff --git a/include/wx/palmos/evtloop.h b/include/wx/palmos/evtloop.h
index 8473fb38c1..fcc4ce9ef8 100644
--- a/include/wx/palmos/evtloop.h
+++ b/include/wx/palmos/evtloop.h
@@ -37,6 +37,7 @@ public:
 
     // process a single message
     virtual void ProcessMessage(WXMSG *msg);
+    virtual void WakeUp();
 
 protected:
     // should we exit the loop?
diff --git a/include/wx/palmos/missing.h b/include/wx/palmos/missing.h
new file mode 100644
index 0000000000..155bee5da8
--- /dev/null
+++ b/include/wx/palmos/missing.h
@@ -0,0 +1,396 @@
+#ifndef _PALMOS_STDIO_FAKE_H
+#define _PALMOS_STDIO_FAKE_H
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <PalmTypes.h>
+#include <MemoryMgr.h> // Core/System/
+#include <StringMgr.h> // Core/System/
+#include <UIResources.h> // alertRscType,MenuRscType
+
+#ifdef __cplusplus
+#define _PSF_BEGIN_EXTERN_C extern "C" {
+#define _PSF_END_EXTERN_C }
+#else
+#define _PSF_BEGIN_EXTERN_C
+#define _PSF_END_EXTERN_C
+#endif
+
+#if __WXPALMOS6__
+    #include <wchar.h> // wint_t
+    #include <unistd.h> // access(), rmdir()
+    #include <time.h>
+    #include <StatusBar.h>
+    #include <Loader.h>
+#else
+    #if !defined(__MWERKS__)
+        #include <PenInputMgr.h>
+    #endif
+
+    #define uint32_t UInt32
+    #define uint16_t UInt16
+    #define uint8_t  UInt8
+#endif // __WXPALMOS6__
+#if __WXPALMOS6__
+    #define POS_DmGetResource(a,b,c) DmGetResource(a,b,c)
+    #define POS_FrmSetMenu(a,b,c)    FrmSetMenu(a,b,c)
+    #define POS_FrmCustomAlert(a,b,c,d,e) FrmCustomAlert(a,b,c,d,e)
+    #define POS_MemNumRAMHeaps(a)    MemNumRAMHeaps()
+#else // __WXPALMOS6__
+    #define POS_DmGetResource(a,b,c) DmGetResource(b,c)
+    #define POS_FrmSetMenu(a,b,c)    FrmSetMenu(a,c)
+    #define POS_FrmCustomAlert(a,b,c,d,e) FrmCustomAlert(b,c,d,e)
+    #define POS_MemNumRAMHeaps(a)    MemNumRAMHeaps(a)
+#endif // __WXPALMOS6__
+
+_PSF_BEGIN_EXTERN_C
+
+#if __WXPALMOS5__
+
+#if defined(__MWERKS__)
+//#include <unix_stdarg.h>
+#endif
+
+#if 0
+#define strcpy(x,y)    StrCopy((char*)(x),(char*)(y))
+#define strncpy(x,y,z) StrNCopy((x),(y),(z))
+#define strcmp(x,y)    StrCompare((x),(y))
+#define strcat(x,y)    StrCat((x),(y))
+#define strlen(x)      StrLen((char*)(x))
+#define strchr(x,y)    StrChr((x),(y))
+#define strstr(x,y)    StrStr((x),(y))
+
+#define memcpy(x,y,z)  ((0 == MemMove((x),(void *)(y),(z))) ? (x) : (0))
+#define memset(x,y,z)  (MemSet((x),(z),(y)))
+#define memcmp(x,y,z)  (MemCmp((x),(y),(z)))
+#endif
+
+#include "sections.h"
+#ifndef int8_t
+#define int8_t char
+#define int16_t short
+#define int64_t long long
+#define uint64_t unsigned int64_t
+
+#define wchar_t uint16_t
+#endif
+#define wint_t int
+
+#define ssize_t long
+#define size_t  uint32_t
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if 0
+#define malloc(x) MemPtrNew(x)
+#define free(x)   MemPtrFree(x)
+void * realloc (void *p, size_t newsize);
+#endif
+char * strdup (const char *old);
+
+// copy from Core/System/Unix/unix_stdio.h
+#ifndef _STDLIB
+	#define sprintf StrPrintF
+	#define vsprintf(x,y,z) StrVPrintF(x,(const Char *)y,z)
+#else
+	int vsprintf(char *, const char *, _Va_list);
+#endif
+int sscanf(const char *, const char *, ...);
+
+///////////////////// time ////////////////////
+#define time_t uint64_t
+time_t time(time_t *T);
+
+#define JAN  0
+#define FEB  1
+#define MAR  2
+#define APR  3
+#define MAY  4
+#define JUN  5
+#define JUL  6
+#define AUG  7
+#define SEP  8
+#define OCT  9
+#define NOV 10
+#define DEC 11
+struct tm {
+	int8_t tm_gmtoff;
+	int8_t tm_isdst;
+	uint8_t tm_sec;
+	uint8_t tm_min;
+	uint8_t tm_hour;
+	uint8_t tm_wday;
+	uint8_t tm_mday;
+	uint8_t tm_mon;
+	uint16_t tm_yday;
+	uint64_t tm_year;
+};
+
+#define HAVE_LOCALTIME_R 1
+extern struct tm *localtime (const time_t *CLOCK); // datetime.cpp: GetTmNow(void)
+extern struct tm *localtime_r (const time_t *CLOCK, struct tm *RES);
+
+#define HAVE_GMTIME_R 1
+extern struct tm *gmtime (const time_t *CLOCK);
+extern struct tm *gmtime_r (const time_t *CLOCK, struct tm *RES);
+
+extern time_t mktime (struct tm *TIMP);
+double difftime (time_t TIM1, time_t TIM2);
+
+char *ctime(const time_t *CLOCK);
+char *ctime_r(const time_t *CLOCK, char *BUF);
+
+//#define HAVE_STRFTIME 1
+extern size_t strftime(char *S, size_t MAXSIZE, const char *FORMAT, const struct tm *TIMP);
+
+///////////////////// locale.h ////////////////////
+struct lconv
+{
+  char *decimal_point;
+  char *thousands_sep;
+  char *grouping;
+  char *int_curr_symbol;
+  char *currency_symbol;
+  char *mon_decimal_point;
+  char *mon_thousands_sep;
+  char *mon_grouping;
+  char *positive_sign;
+  char *negative_sign;
+  char int_frac_digits;
+  char frac_digits;
+  char p_cs_precedes;
+  char p_sep_by_space;
+  char n_cs_precedes;
+  char n_sep_by_space;
+  char p_sign_posn;
+  char n_sign_posn;
+};
+char *setlocale(int CATEGORY, const char *LOCALE);
+struct lconv *localeconv(void);
+
+char *_setlocale_r(void *REENT, int CATEGORY, const char *LOCALE);
+struct lconv *_localeconv_r(void *REENT);
+///////////////////// stdlib.h ////////////////////
+
+#if !defined(__MWERKS__)
+#define wchar_t int
+#endif
+int _watoi(wchar_t * nptr);
+long _watol(wchar_t * nptr);
+double _watof(wchar_t *nptr);
+#define watoi(a) _watoi((wchar_t *)(a))
+#define watol(a) _watol((wchar_t *)(a))
+#define watof(a) _watof((wchar_t *)(a))
+int mbstowcs(wchar_t *PWC, const char *S, size_t N);
+int wcstombs(const char *S, wchar_t *PWC, size_t N);
+
+///////////////////// fcntl.h ////////////////////
+#define	O_RDONLY	0x01
+#define	O_WRONLY	0x02
+#define	O_RDWR    0x04
+#define	O_APPEND	0x08
+#define	O_CREAT   0x10
+#define	O_TRUNC   0x20
+#define	O_EXCL    0x40
+#define O_SYNC    0x80
+
+// io.h
+int open (const char*, int, ...);
+int read (int, void*, unsigned int);
+int write (int, const void*, unsigned int);
+int close (int);
+long lseek (int, long, int);
+
+///////////////////// stdio.h ////////////////////
+int remove(const char *FILENAME);
+int rename(const char *OLD, const char *NEW);
+
+///////////////////// unistd.h ////////////////////
+int access (const char *path, int amode);
+int rmdir (const char *path);
+
+///////////////////// FILE ////////////////////
+#ifndef NULL
+#define NULL ((void *)(0))
+#endif
+
+#define FILE void
+#undef stdin
+#undef stdout
+#undef stderr
+#define stdin NULL
+#define stdout NULL
+#define stderr NULL
+
+#define	SEEK_SET	0	/* set file offset to offset */
+#define	SEEK_CUR	1	/* set file offset to current plus offset */
+#define	SEEK_END	2	/* set file offset to EOF plus offset */
+
+FILE *	fopen (const char *_name, const char *_type);
+int	fclose (FILE *);
+size_t fread (void *buf, size_t _size, size_t _n, FILE *);
+size_t	fwrite (const void *buf , size_t _size, size_t _n, FILE *);
+int	fseek (FILE *, long, int);
+long ftell ( FILE *);
+int	feof (FILE *);
+int	ferror (FILE *);
+void clearerr (FILE *);
+FILE *freopen(const char *fn, const char *mode, FILE *fp);
+//FILE *_freopen_r(struct _reent *PTR, const char *fn, const char *mode, FILE *fp);
+
+extern int fflush (FILE *FP);
+extern int fputs (const char *S, FILE *FP);
+extern int fputc (int CH, FILE *FP);
+
+//int printf(const char *format, ...);
+int fprintf(FILE *stream, const char *format, ...);
+//int sprintf(char *str, const char *format, ...);
+//int snprintf(char *str, size_t size, const char *format, ...);
+//int vfprintf(FILE * restrict stream, const char * restrict format, va_list ap);
+//int vsprintf(char * restrict str, const char * restrict format, va_list ap);
+//int vsnprintf(char * restrict str, size_t size, const char * restrict format, va_list ap);
+int vsscanf (const char *s, const char *format, va_list param);
+
+///////////////////// string ////////////////////
+char *strerror(int ERRNUM);
+
+///////////////////// ctype.h ////////////////////
+extern int isascii(int C);
+
+///////////////////// stdlib ////////////////////
+void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
+void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *));
+//int heapsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
+//int mergesort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
+void *bsearch(const void *key, const void *base, size_t nmemb,size_t size, int (*compar)(const void *, const void *));
+
+char *getenv(const char *NAME);
+
+double atof(const char *S);
+double strtod(const char *STR, char **TAIL);
+double _strtod_r(void *REENT, const char *STR, char **TAIL);
+
+///////////////////// math.h ////////////////////
+#define __IMPORT
+
+union __dmath
+{
+  unsigned long i[2];
+  double d;
+};
+ 
+union __fmath
+{
+  unsigned long i[1];
+  float f;
+};
+ 
+union __ldmath
+{
+  unsigned long i[4];
+  long double ld;
+};
+#if defined(__GNUC__) && \
+  ( (__GNUC__ >= 4) || \
+    ( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 3) ) )
+
+ /* gcc >= 3.3 implicitly defines builtins for HUGE_VALx values.  */
+
+ #ifndef HUGE_VAL
+  #define HUGE_VAL (__builtin_huge_val())
+ #endif
+
+ #ifndef HUGE_VALF
+  #define HUGE_VALF (__builtin_huge_valf())
+ #endif
+
+ #ifndef HUGE_VALL
+  #define HUGE_VALL (__builtin_huge_vall())
+ #endif
+
+#else /* !gcc >= 3.3  */
+
+ /* No builtins.  Use floating-point unions instead.  Declare as an array 
+    without bounds so no matter what small data support a port and/or 
+    library has, the reference will be via the general method for accessing 
+    globals. */
+
+ #ifndef HUGE_VAL
+  extern __IMPORT const union __dmath __infinity[];
+  #define HUGE_VAL (__infinity[0].d)
+ #endif
+
+ #ifndef HUGE_VALF
+  extern __IMPORT const union __fmath __infinityf[];
+  #define HUGE_VALF (__infinityf[0].f)
+ #endif
+
+ #ifndef HUGE_VALL
+  extern __IMPORT const union __ldmath __infinityld[];
+  #define HUGE_VALL (__infinityld[0].ld)
+ #endif
+
+#endif /* !gcc >= 3.3  */
+#undef __IMPORT
+
+///////////////////// PalmOS6 ////////////////////
+#define status_t Err
+
+// TimeMgr.h
+time_t SysTimeToMilliSecs(time_t systime);
+time_t SysTimeInSecs(time_t secs);
+
+///////////////////// END ////////////////////
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __WXPALMOS5__
+
+///////////////////// wctype.h ////////////////////
+extern int iswalnum(wint_t C);
+extern int iswalpha(wint_t C);
+extern int iswcntrl(wint_t C);
+extern int iswdigit(wint_t C);
+extern int iswgraph(wint_t C);
+extern int iswlower(wint_t C);
+extern int iswprint(wint_t C);
+extern int iswpunct(wint_t C);
+extern int iswspace(wint_t C);
+extern int iswupper(wint_t C);
+extern int iswxdigit(wint_t C);
+
+extern wint_t towlower(wint_t C);
+extern wint_t towupper(wint_t C);
+extern size_t wcsftime(wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr);
+
+size_t wcslen (const wchar_t * str);
+wchar_t * wcscpy (wchar_t * dst, const wchar_t * src);
+wchar_t * wcsncpy (wchar_t * dst, const wchar_t * src, size_t n);
+wchar_t * wcscat (wchar_t * dst, const wchar_t * src);
+wchar_t * wcsncat (wchar_t * dst, const wchar_t * src, size_t n);
+int wcscmp (const wchar_t * str1, const wchar_t * str2);
+int wcsncmp (const wchar_t * str1, const wchar_t * str2, size_t n);
+wchar_t * wcschr (const wchar_t * str, const wchar_t chr);
+int wcscoll (const wchar_t *str1, const wchar_t * str2);
+size_t wcsxfrm (wchar_t * str1, const wchar_t * str2, size_t n);
+wchar_t * wcsrchr (const wchar_t * str, wchar_t chr);
+wchar_t * wcspbrk (const wchar_t * str, const wchar_t * set);
+size_t wcsspn (const wchar_t * str, const wchar_t * set);
+size_t wcscspn (const wchar_t * str, const wchar_t * set);
+wchar_t * wcsstr (const wchar_t * str, const wchar_t * pat);
+wchar_t * wcstok (wchar_t * str, const wchar_t * set, wchar_t ** );
+
+long wcstol (const wchar_t * str, wchar_t ** end, int base);
+unsigned long wcstoul (const wchar_t * a, wchar_t ** b, int c);
+double wcstod (const wchar_t * a, wchar_t ** b);
+
+char * setlocale (int category, const char *locale);
+
+_PSF_END_EXTERN_C
+
+#endif // _PALMOS_STDIO_FAKE_H
diff --git a/include/wx/palmos/tglbtn.h b/include/wx/palmos/tglbtn.h
index f4edb56863..8e0b1d0453 100644
--- a/include/wx/palmos/tglbtn.h
+++ b/include/wx/palmos/tglbtn.h
@@ -13,7 +13,8 @@
 #ifndef _WX_TOGGLEBUTTON_H_
 #define _WX_TOGGLEBUTTON_H_
 
-WXDLLEXPORT_DATA(extern const wxChar) wxCheckBoxNameStr[];
+#include "wx/checkbox.h" // wxCheckBoxNameStr, in Datacmn.cpp
+//WXDLLEXPORT_DATA(extern const wxChar) wxCheckBoxNameStr[];
 
 // Checkbox item (single checkbox)
 class WXDLLEXPORT wxToggleButton : public wxToggleButtonBase
diff --git a/include/wx/palmos/window.h b/include/wx/palmos/window.h
index 81cddb3611..aeb2a5f9a9 100644
--- a/include/wx/palmos/window.h
+++ b/include/wx/palmos/window.h
@@ -132,8 +132,9 @@ public:
     // simple accessors
     // ----------------
 
-    virtual WXWINHANDLE GetWinHandle() const { return m_handle; }
-    virtual WXWidget GetHandle() const { return GetWinHandle(); }
+    WXHWND GetHWND() const { return m_hWnd; }
+    void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
+    virtual WXWidget GetHandle() const { return GetHWND(); }
 
     // event handlers
     // --------------
@@ -208,7 +209,7 @@ public:
 
 protected:
     // the window handle
-    WXWINHANDLE m_handle;
+    WXHWND                m_hWnd;
     WXFORMPTR FrameForm;
 
     WXFORMPTR GetFormPtr();
diff --git a/include/wx/platform.h b/include/wx/platform.h
index fce5c927cd..22b2469aaf 100644
--- a/include/wx/platform.h
+++ b/include/wx/platform.h
@@ -21,6 +21,10 @@
 */
 #ifdef __MWERKS__
 #   include <stddef.h>
+
+#  if !defined(__WXMAC__) && !defined(__WINDOWS__) && !defined(WIN32) && !defined(_WIN32_WCE)
+#    define __PALMOS__ 0x05000000
+#  endif
 #endif
 
 /*
@@ -94,13 +98,13 @@
 
 #if defined(__PALMOS__)
 #   if __PALMOS__ == 0x06000000
-#       define __WXPALMOS6__
+#       define __WXPALMOS6__ 1
 #   endif
 #   if __PALMOS__ == 0x05000000
-#       define __WXPALMOS5__
+#       define __WXPALMOS5__ 1
 #   endif
 #   ifndef __WXPALMOS__
-#       define __WXPALMOS__
+#       define __WXPALMOS__ 1
 #   endif
 #   ifdef __WXMSW__
 #       undef __WXMSW__
@@ -679,4 +683,29 @@
     #include <AvailabilityMacros.h>
 #endif
 
+#if defined (__WXPALMOS__)
+#include "wx/palmos/missing.h"
+#endif // __WXPALMOS__
+
+#if !defined (__WXPALMOS5__)
+#define POSSEC_APPBASE
+#define POSSEC_ARCHIVE
+#define POSSEC_CLNTDATA
+#define POSSEC_CMDLINE
+#define POSSEC_CONFIG
+#define POSSEC_DATETIME
+#define POSSEC_DATETIME2
+#define POSSEC_DATSTRM
+#define POSSEC_DIRCMN
+#define POSSEC_DYNARRAY
+#define POSSEC_DYNLIB
+#define POSSEC_DYNLOAD
+#define POSSEC_ENCCONV
+#define POSSEC_EXTENDED
+#define POSSEC_FFILE
+#define POSSEC_FILE
+#define POSSEC_FILECONF
+#define POSSEC_FILEFN
+#endif // __WXPALMOS5__
+
 #endif /* _WX_PLATFORM_H_ */
diff --git a/include/wx/wxcrtbase.h b/include/wx/wxcrtbase.h
index 49ff24f402..ca195b2806 100644
--- a/include/wx/wxcrtbase.h
+++ b/include/wx/wxcrtbase.h
@@ -28,11 +28,17 @@
         include this one!
  */
 
+#if !defined(__WXPALMOS5__)
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
-#include <wctype.h>
+#if defined(__WXPALMOS__)
+    #include <wchar.h>
+#else
+    #include <wctype.h>
+#endif
 #include <time.h>
+#endif
 
 #if defined(__WINDOWS__) && !defined(__WXWINCE__)
     #include <io.h>
@@ -157,7 +163,7 @@ WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
 #define wxCRT_StrstrW    wcsstr
 
 /* these functions are not defined under CE, at least in VC8 CRT */
-#ifndef __WXWINCE__
+#if !defined(__WXWINCE__) && !defined(__WXPALMOS__)
     #define wxCRT_StrcollA   strcoll
     #define wxCRT_StrxfrmA   strxfrm
 
@@ -232,7 +238,7 @@ WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
          * quick hack should do until one can be written.
          */
         #define wxCRT_StricmpA StrCaselessCompare
-        #define wxCRT_StrnicmpA strnicmp
+        #define wxCRT_StrnicmpA StrNCaselessCompare
     #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
             (defined(__MWERKS__) && defined(__INTEL__))
         #define wxCRT_StricmpA _stricmp
@@ -401,7 +407,7 @@ WXDLLIMPEXP_BASE wchar_t *wxCRT_StrtokW(wchar_t *psz, const wchar_t *delim, wcha
                                   stdio.h
    ------------------------------------------------------------------------- */
 
-#if defined(__UNIX__) || defined(__WXMAC__)
+#if defined(__UNIX__) || defined(__WXMAC__) || defined(__WXPALMOS__)
     #define wxMBFILES 1
 #else
     #define wxMBFILES 0
@@ -561,6 +567,9 @@ WXDLLIMPEXP_BASE wchar_t * wxCRT_GetenvW(const wchar_t *name);
 #if defined(__MWERKS__) && defined(__MSL__)
     #define wxNEED_WX_MBSTOWCS
 #endif
+#if defined(__WXPALMOS__)
+    #define wxNEED_WX_MBSTOWCS
+#endif
 
 #ifdef __DARWIN__
     #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp
index 623ff0bc61..c0e98a3bdb 100644
--- a/src/common/dcbase.cpp
+++ b/src/common/dcbase.cpp
@@ -78,6 +78,12 @@
     #include "wx/dfb/dcscreen.h"
 #endif
 
+#ifdef __WXPALMOS__
+    #include "wx/palmos/dcclient.h"
+    #include "wx/palmos/dcmemory.h"
+    #include "wx/palmos/dcscreen.h"
+#endif
+
 //----------------------------------------------------------------------------
 // wxDCFactory
 //----------------------------------------------------------------------------
diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp
index 686f80bbd7..c23f02bf1c 100644
--- a/src/common/filefn.cpp
+++ b/src/common/filefn.cpp
@@ -403,11 +403,9 @@ void wxStripExtension(wxString& buffer)
 template<typename CharType>
 static CharType *wxDoRealPath (CharType *path)
 {
+  static const CharType SEP = wxFILE_SEP_PATH;
 #ifdef __WXMSW__
-  static const CharType SEP = wxT('\\');
   wxUnix2DosFilename(path);
-#else
-  static const CharType SEP = wxT('/');
 #endif
   if (path[0] && path[1]) {
     /* MATTHEW: special case "/./x" */
@@ -539,11 +537,11 @@ static CharType *wxDoExpandPath(CharType *buf, const wxString& name)
     trimchars[2] = wxT('\t');
     trimchars[3] = 0;
 
+    static const CharType SEP = wxFILE_SEP_PATH;
 #ifdef __WXMSW__
-    const CharType     SEP = wxT('\\');
-#else
-    const CharType     SEP = wxT('/');
+    //wxUnix2DosFilename(path);
 #endif
+
     buf[0] = wxT('\0');
     if (name.empty())
         return buf;
diff --git a/src/common/wxcrt.cpp b/src/common/wxcrt.cpp
index 197fe9597d..c50a880767 100644
--- a/src/common/wxcrt.cpp
+++ b/src/common/wxcrt.cpp
@@ -21,6 +21,7 @@
 #endif
 
 #include "wx/crt.h"
+#include "wx/strconv.h" // wxMBConv::cWC2MB()
 
 #define _ISOC9X_SOURCE 1 // to get vsscanf()
 #define _BSD_SOURCE    1 // to still get strdup()
@@ -29,12 +30,14 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifndef __WXPALMOS5__
 #ifndef __WXWINCE__
     #include <time.h>
     #include <locale.h>
 #else
     #include "wx/msw/wince/time.h"
 #endif
+#endif // !__WXPALMOS5__
 
 #ifndef WX_PRECOMP
     #include "wx/string.h"
diff --git a/src/palmos/app.cpp b/src/palmos/app.cpp
index 888ab4bf8c..6accd4a64f 100644
--- a/src/palmos/app.cpp
+++ b/src/palmos/app.cpp
@@ -120,10 +120,12 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *majVer, int *minVer) const
     return wxPORT_PALMOS;
 }
 
+#if wxUSE_TIMER
 wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
 {
     return new wxPalmOSTimerImpl(timer);
 };
+#endif // wxUSE_TIMER
 
 wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
 {
@@ -227,17 +229,21 @@ wxApp::wxApp()
 
 wxApp::~wxApp()
 {
+    wxChar **argv_tmp;
+    argv_tmp = argv;
+    // src/palmos/main.cpp
     // our cmd line arguments are allocated inside wxEntry(HINSTANCE), they
     // don't come from main(), so we have to free them
-
     while ( argc )
     {
         // m_argv elements were allocated by wxStrdup()
-        free(argv[--argc]);
+        if (argv_tmp[--argc]) {
+            free((void *)(argv_tmp[--argc]));
+        }
     }
-
     // but m_argv itself -- using new[]
-    delete [] argv;
+    delete [] argv_tmp;
+    //argv = NULL;
 }
 
 // ----------------------------------------------------------------------------
diff --git a/src/palmos/base.cpp b/src/palmos/base.cpp
index db93d42b96..cadd56b368 100644
--- a/src/palmos/base.cpp
+++ b/src/palmos/base.cpp
@@ -28,8 +28,8 @@
 #endif //WX_PRECOMP
 
 #include "wx/apptrait.h"
-
 #include "wx/recguard.h"
+#include "wx/evtloop.h" // wxEventLoop
 
 // ============================================================================
 // wxConsoleAppTraits implementation
@@ -53,3 +53,17 @@ bool wxConsoleAppTraits::DoMessageFromThreadWait()
     return true;
 }
 
+WXDWORD wxConsoleAppTraits::WaitForThread(WXHANDLE hThread)
+{
+    // TODO
+    return 0;
+}
+
+#if wxUSE_CONSOLE_EVENTLOOP
+wxEventLoopBase *
+wxConsoleAppTraits::CreateEventLoop()
+{
+    return new wxEventLoop;
+}
+#endif // wxUSE_CONSOLE_EVENTLOOP
+
diff --git a/src/palmos/button.cpp b/src/palmos/button.cpp
index 7b9be28910..94dae6c81c 100644
--- a/src/palmos/button.cpp
+++ b/src/palmos/button.cpp
@@ -200,7 +200,7 @@ wxWindow *wxButton::SetDefault()
 {
     FormType* form = (FormType* )GetParentForm();
     if(form==NULL)
-        return;
+        return NULL;
     FrmSetDefaultButtonID(form,GetId());
 
     return wxButtonBase::SetDefault();
diff --git a/src/palmos/control.cpp b/src/palmos/control.cpp
index 89c50c48ac..8fc1e73810 100644
--- a/src/palmos/control.cpp
+++ b/src/palmos/control.cpp
@@ -137,7 +137,7 @@ bool wxControl::PalmCreateControl(int style,
                                (void **)&form,
                                GetId(),
                                (ControlStyleType)style,
-                               wxEmptyString,
+                               NULL,
                                x,
                                y,
                                w,
@@ -421,7 +421,7 @@ void wxControl::SetControlLabel(const wxString& label)
     ControlType* control = (ControlType*)GetObjectPtr();
     if(control==NULL)
         return;
-    CtlSetLabel(control,wxEmptyString);
+    CtlSetLabel(control, "");
     m_label = label;
     if(!m_label.empty())
         CtlSetLabel(control,m_label.c_str());
@@ -452,7 +452,7 @@ wxString wxControl::GetControlLabel()
         return wxEmptyString;
     return CtlGetLabel(control);
 }
-
+#if 0
 wxString wxControl::GetLabel()
 {
     if(IsPalmField())
@@ -464,7 +464,7 @@ wxString wxControl::GetLabel()
 
     return wxEmptyString;
 }
-
+#endif
 /* static */ wxVisualAttributes
 wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
 {
diff --git a/src/palmos/datectrl.cpp b/src/palmos/datectrl.cpp
index c030a4c142..87044d1564 100644
--- a/src/palmos/datectrl.cpp
+++ b/src/palmos/datectrl.cpp
@@ -123,7 +123,8 @@ bool wxDatePickerCtrl::SendClickEvent()
     int16_t day = m_dt.GetDay();
     int16_t year = m_dt.GetYear();
 
-    if(!SelectDay(selectDayByDay,&month,&day,&year,_T("Pick date")))
+    //if(!SelectDay(selectDayByDay,&month,&day,&year,_T("Pick date")))
+    if(!SelectDay(selectDayByDay,&month,&day,&year, "Pick date"))
         return false;
     wxDateTime dt(m_dt);
     dt.Set((wxDateTime::wxDateTime_t)day,
diff --git a/src/palmos/dc.cpp b/src/palmos/dc.cpp
index 38c0ae1d51..86e7abfcec 100644
--- a/src/palmos/dc.cpp
+++ b/src/palmos/dc.cpp
@@ -17,6 +17,8 @@
 // headers
 // ---------------------------------------------------------------------------
 
+#include <string.h>
+
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -25,6 +27,7 @@
 #endif
 
 #ifndef WX_PRECOMP
+    #include "wx/image.h"
     #include "wx/window.h"
     #include "wx/dc.h"
     #include "wx/utils.h"
@@ -39,16 +42,20 @@
 #endif
 
 #include "wx/sysopt.h"
-#include "wx/dynload.h"
+#include "wx/dynlib.h"
 
 #ifdef wxHAVE_RAW_BITMAP
 #include "wx/rawbmp.h"
 #endif
 
-#include <string.h>
+#include "wx/palmos/dc.h"
 
 #ifndef AC_SRC_ALPHA
-#define AC_SRC_ALPHA 1
+    #define AC_SRC_ALPHA 1
+#endif
+
+#ifndef LAYOUT_RTL
+    #define LAYOUT_RTL 1
 #endif
 
 /* Quaternary raster codes */
@@ -56,18 +63,48 @@
 #define MAKEROP4(fore,back) (DWORD)((((back) << 8) & 0xFF000000) | (fore))
 #endif
 
-IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
+// apparently with MicroWindows it is possible that HDC is 0 so we have to
+// check for this ourselves
+#ifdef __WXMICROWIN__
+    #define WXMICROWIN_CHECK_HDC if ( !GetHDC() ) return;
+    #define WXMICROWIN_CHECK_HDC_RET(x) if ( !GetHDC() ) return x;
+#else
+    #define WXMICROWIN_CHECK_HDC
+    #define WXMICROWIN_CHECK_HDC_RET(x)
+#endif
+
+IMPLEMENT_ABSTRACT_CLASS(wxPalmDCImpl, wxDCImpl)
 
 // ---------------------------------------------------------------------------
 // constants
 // ---------------------------------------------------------------------------
 
-static const int VIEWPORT_EXTENT = 1000;
+// ROPs which don't have standard names (see "Ternary Raster Operations" in the
+// MSDN docs for how this and other numbers in wxDC::Blit() are obtained)
+#define DSTCOPY 0x00AA0029      // a.k.a. NOP operation
 
-static const int MM_POINTS = 9;
-static const int MM_METRIC = 10;
+// ----------------------------------------------------------------------------
+// macros for logical <-> device coords conversion
+// ----------------------------------------------------------------------------
 
-#define DSTCOPY 0x00AA0029
+/*
+   We currently let Windows do all the translations itself so these macros are
+   not really needed (any more) but keep them to enhance readability of the
+   code by allowing to see where are the logical and where are the device
+   coordinates used.
+ */
+
+#ifdef __WXWINCE__
+    #define XLOG2DEV(x) ((x-m_logicalOriginX)*m_signX)
+    #define YLOG2DEV(y) ((y-m_logicalOriginY)*m_signY)
+    #define XDEV2LOG(x) ((x)*m_signX+m_logicalOriginX)
+    #define YDEV2LOG(y) ((y)*m_signY+m_logicalOriginY)
+#else
+    #define XLOG2DEV(x) (x)
+    #define YLOG2DEV(y) (y)
+    #define XDEV2LOG(x) (x)
+    #define YDEV2LOG(y) (y)
+#endif
 
 // ---------------------------------------------------------------------------
 // private functions
@@ -77,27 +114,77 @@ static const int MM_METRIC = 10;
 // private classes
 // ----------------------------------------------------------------------------
 
+#if wxUSE_DYNLIB_CLASS
+
+// helper class to cache dynamically loaded libraries and not attempt reloading
+// them if it fails
+class wxOnceOnlyDLLLoader
+{
+public:
+    // ctor argument must be a literal string as we don't make a copy of it!
+    wxOnceOnlyDLLLoader(const wxChar *dllName)
+        : m_dllName(dllName)
+    {
+    }
+
+
+    // return the symbol with the given name or NULL if the DLL not loaded
+    // or symbol not present
+    void *GetSymbol(const wxChar *name)
+    {
+        // we're prepared to handle errors here
+        wxLogNull noLog;
+
+        if ( m_dllName )
+        {
+            m_dll.Load(m_dllName);
+
+            // reset the name whether we succeeded or failed so that we don't
+            // try again the next time
+            m_dllName = NULL;
+        }
+
+        return m_dll.IsLoaded() ? m_dll.GetSymbol(name) : NULL;
+    }
+
+    void Unload()
+    {
+        if ( m_dll.IsLoaded() )
+        {
+            m_dll.Unload();
+        }
+    }
+
+private:
+    wxDynamicLibrary m_dll;
+    const wxChar *m_dllName;
+};
+
+#endif // wxUSE_DYNLIB_CLASS
+
 // ===========================================================================
 // implementation
 // ===========================================================================
 
 // ---------------------------------------------------------------------------
-// wxDC
+// wxPalmDCImpl
 // ---------------------------------------------------------------------------
 
-// Default constructor
-wxDC::wxDC()
+wxPalmDCImpl::wxPalmDCImpl( wxDC *owner, WXHDC hDC ) :
+    wxDCImpl( owner )
 {
+    Init();
+    m_hDC = hDC;
 }
 
-wxDC::~wxDC()
+wxPalmDCImpl::~wxPalmDCImpl()
 {
 }
 
 // This will select current objects out of the DC,
 // which is what you have to do before deleting the
 // DC.
-void wxDC::SelectOldObjects(WXHDC dc)
+void wxPalmDCImpl::SelectOldObjects(WXHDC dc)
 {
 }
 
@@ -105,29 +192,30 @@ void wxDC::SelectOldObjects(WXHDC dc)
 // clipping
 // ---------------------------------------------------------------------------
 
-void wxDC::UpdateClipBox()
+void wxPalmDCImpl::UpdateClipBox()
 {
 }
 
 void
-wxDC::DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
+wxPalmDCImpl::DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
 {
 }
 
 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
-void wxDC::SetClippingHrgn(WXHRGN hrgn)
+void wxPalmDCImpl::SetClippingHrgn(WXHRGN hrgn)
 {
+    wxCHECK_RET( hrgn, wxT("invalid clipping region") );
 }
 
-void wxDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
+void wxPalmDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
 {
 }
 
-void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region)
+void wxPalmDCImpl::DoSetClippingRegionAsRegion(const wxRegion& region)
 {
 }
 
-void wxDC::DestroyClippingRegion()
+void wxPalmDCImpl::DestroyClippingRegion()
 {
 }
 
@@ -135,17 +223,17 @@ void wxDC::DestroyClippingRegion()
 // query capabilities
 // ---------------------------------------------------------------------------
 
-bool wxDC::CanDrawBitmap() const
+bool wxPalmDCImpl::CanDrawBitmap() const
 {
     return false;
 }
 
-bool wxDC::CanGetTextExtent() const
+bool wxPalmDCImpl::CanGetTextExtent() const
 {
     return false;
 }
 
-int wxDC::GetDepth() const
+int wxPalmDCImpl::GetDepth() const
 {
     return 0;
 }
@@ -154,51 +242,58 @@ int wxDC::GetDepth() const
 // drawing
 // ---------------------------------------------------------------------------
 
-void wxDC::Clear()
+void wxPalmDCImpl::Clear()
 {
 }
 
-bool wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style)
+bool wxPalmDCImpl::DoFloodFill(wxCoord WXUNUSED_IN_WINCE(x),
+                       wxCoord WXUNUSED_IN_WINCE(y),
+                       const wxColour& WXUNUSED_IN_WINCE(col),
+                       int WXUNUSED_IN_WINCE(style))
 {
     return false;
 }
 
-bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
+bool wxPalmDCImpl::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
 {
     return false;
 }
 
-void wxDC::DoCrossHair(wxCoord x, wxCoord y)
+void wxPalmDCImpl::DoCrossHair(wxCoord x, wxCoord y)
 {
 }
 
-void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
+void wxPalmDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
 {
 }
 
 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
 // and ending at (x2, y2)
-void wxDC::DoDrawArc(wxCoord x1, wxCoord y1,
+void wxPalmDCImpl::DoDrawArc(wxCoord x1, wxCoord y1,
                      wxCoord x2, wxCoord y2,
                      wxCoord xc, wxCoord yc)
 {
 }
 
-void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1,
+void wxPalmDCImpl::DoDrawCheckMark(wxCoord x1, wxCoord y1,
                            wxCoord width, wxCoord height)
 {
 }
 
-void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
+void wxPalmDCImpl::DoDrawPoint(wxCoord x, wxCoord y)
 {
 }
 
-void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int fillStyle)
+void wxPalmDCImpl::DoDrawPolygon(int n,
+                         wxPoint points[],
+                         wxCoord xoffset,
+                         wxCoord yoffset,
+                         int WXUNUSED_IN_WINCE(fillStyle))
 {
 }
 
 void
-wxDC::DoDrawPolyPolygon(int n,
+wxPalmDCImpl::DoDrawPolyPolygon(int n,
                         int count[],
                         wxPoint points[],
                         wxCoord xoffset,
@@ -207,43 +302,50 @@ wxDC::DoDrawPolyPolygon(int n,
 {
 }
 
-void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
+void wxPalmDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
 {
 }
 
-void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+void wxPalmDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
 {
 }
 
-void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
+void wxPalmDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
 {
 }
 
-void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+void wxPalmDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
 {
 }
 
-void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
+#if wxUSE_SPLINES
+void wxPalmDCImpl::DoDrawSpline(const wxPointList *points)
+{
+}
+#endif
+
+// Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
+void wxPalmDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
 {
 }
 
-void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
+void wxPalmDCImpl::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
 {
 }
 
-void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
+void wxPalmDCImpl::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
 {
 }
 
-void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
+void wxPalmDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
 {
 }
 
-void wxDC::DrawAnyText(const wxString& text, wxCoord x, wxCoord y)
+void wxPalmDCImpl::DrawAnyText(const wxString& text, wxCoord x, wxCoord y)
 {
 }
 
-void wxDC::DoDrawRotatedText(const wxString& text,
+void wxPalmDCImpl::DoDrawRotatedText(const wxString& text,
                              wxCoord x, wxCoord y,
                              double angle)
 {
@@ -255,62 +357,66 @@ void wxDC::DoDrawRotatedText(const wxString& text,
 
 #if wxUSE_PALETTE
 
-void wxDC::DoSelectPalette(bool realize)
+void wxPalmDCImpl::DoSelectPalette(bool realize)
 {
 }
 
-void wxDC::SetPalette(const wxPalette& palette)
+void wxPalmDCImpl::SetPalette(const wxPalette& palette)
 {
 }
 
-void wxDC::InitializePalette()
+void wxPalmDCImpl::InitializePalette()
 {
 }
 
 #endif // wxUSE_PALETTE
 
-void wxDC::SetFont(const wxFont& font)
+// SetFont/Pen/Brush() really ask to be implemented as a single template
+// function... but doing it is not worth breaking OpenWatcom build <sigh>
+
+void wxPalmDCImpl::SetFont(const wxFont& font)
 {
 }
 
-void wxDC::SetPen(const wxPen& pen)
+void wxPalmDCImpl::SetPen(const wxPen& pen)
 {
 }
 
-void wxDC::SetBrush(const wxBrush& brush)
+void wxPalmDCImpl::SetBrush(const wxBrush& brush)
 {
 }
 
-void wxDC::SetBackground(const wxBrush& brush)
+void wxPalmDCImpl::SetBackground(const wxBrush& brush)
 {
 }
 
-void wxDC::SetBackgroundMode(int mode)
+void wxPalmDCImpl::SetBackgroundMode(int mode)
 {
 }
 
-void wxDC::SetLogicalFunction(int function)
+void wxPalmDCImpl::SetLogicalFunction(int function)
 {
 }
 
-void wxDC::SetRop(WXHDC dc)
+void wxPalmDCImpl::SetRop(WXHDC dc)
 {
 }
 
-bool wxDC::StartDoc(const wxString& WXUNUSED(message))
+bool wxPalmDCImpl::StartDoc(const wxString& WXUNUSED(message))
 {
+    // We might be previewing, so return true to let it continue.
     return true;
 }
 
-void wxDC::EndDoc()
+void wxPalmDCImpl::EndDoc()
 {
 }
 
-void wxDC::StartPage()
+void wxPalmDCImpl::StartPage()
 {
 }
 
-void wxDC::EndPage()
+void wxPalmDCImpl::EndPage()
 {
 }
 
@@ -318,126 +424,96 @@ void wxDC::EndPage()
 // text metrics
 // ---------------------------------------------------------------------------
 
-wxCoord wxDC::GetCharHeight() const
+wxCoord wxPalmDCImpl::GetCharHeight() const
 {
     return 0;
 }
 
-wxCoord wxDC::GetCharWidth() const
+wxCoord wxPalmDCImpl::GetCharWidth() const
 {
     return 0;
 }
 
-void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
+void wxPalmDCImpl::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
                            wxCoord *descent, wxCoord *externalLeading,
                            const wxFont *font) const
 {
 }
 
 
-bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
+// Each element of the array will be the width of the string up to and
+// including the coresoponding character in text.
+
+bool wxPalmDCImpl::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
 {
     return false;
 }
 
-
-
-
-void wxDC::SetMapMode(int mode)
+void wxPalmDCImpl::RealizeScaleAndOrigin()
 {
 }
 
-void wxDC::SetUserScale(double x, double y)
+void wxPalmDCImpl::SetMapMode(int mode)
 {
 }
 
-void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp)
+void wxPalmDCImpl::SetUserScale(double x, double y)
 {
 }
 
-void wxDC::SetSystemScale(double x, double y)
+void wxPalmDCImpl::SetAxisOrientation(bool xLeftRight,
+                              bool yBottomUp)
 {
 }
 
-void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y)
+void wxPalmDCImpl::SetLogicalOrigin(wxCoord x, wxCoord y)
 {
 }
 
-void wxDC::SetDeviceOrigin(wxCoord x, wxCoord y)
+void wxPalmDCImpl::SetDeviceOrigin(wxCoord x, wxCoord y)
 {
 }
 
 // ---------------------------------------------------------------------------
-// coordinates transformations
+// bit blit
 // ---------------------------------------------------------------------------
 
-wxCoord wxDC::DeviceToLogicalX(wxCoord x) const
-{
-    return 0;
-}
-
-wxCoord wxDC::DeviceToLogicalXRel(wxCoord x) const
-{
-    return 0;
-}
-
-wxCoord wxDC::DeviceToLogicalY(wxCoord y) const
-{
-    return 0;
-}
-
-wxCoord wxDC::DeviceToLogicalYRel(wxCoord y) const
-{
-    return 0;
-}
-
-wxCoord wxDC::LogicalToDeviceX(wxCoord x) const
-{
-    return 0;
-}
-
-wxCoord wxDC::LogicalToDeviceXRel(wxCoord x) const
-{
-    return 0;
-}
-
-wxCoord wxDC::LogicalToDeviceY(wxCoord y) const
-{
-    return 0;
-}
-
-wxCoord wxDC::LogicalToDeviceYRel(wxCoord y) const
+bool wxPalmDCImpl::DoBlit(wxCoord dstX, wxCoord dstY,
+                  wxCoord dstWidth, wxCoord dstHeight,
+                  wxDC *source,
+                  wxCoord srcX, wxCoord srcY,
+                  int rop, bool useMask,
+                  wxCoord srcMaskX, wxCoord srcMaskY)
 {
-    return 0;
+    return false;
 }
 
-// ---------------------------------------------------------------------------
-// bit blit
-// ---------------------------------------------------------------------------
-
-bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
-                  wxCoord width, wxCoord height,
-                  wxDC *source, wxCoord xsrc, wxCoord ysrc,
-                  int rop, bool useMask,
-                  wxCoord xsrcMask, wxCoord ysrcMask)
+bool wxPalmDCImpl::DoStretchBlit(wxCoord xdest, wxCoord ydest,
+                         wxCoord dstWidth, wxCoord dstHeight,
+                         wxDC *source,
+                         wxCoord xsrc, wxCoord ysrc,
+                         wxCoord srcWidth, wxCoord srcHeight,
+                         int rop, bool useMask,
+                         wxCoord xsrcMask, wxCoord ysrcMask)
 {
     return false;
 }
 
-void wxDC::DoGetSize(int *w, int *h) const
+void wxPalmDCImpl::GetDeviceSize(int *width, int *height) const
 {
 }
 
-void wxDC::DoGetSizeMM(int *w, int *h) const
+void wxPalmDCImpl::DoGetSizeMM(int *w, int *h) const
 {
 }
 
-wxSize wxDC::GetPPI() const
+wxSize wxPalmDCImpl::GetPPI() const
 {
     return wxSize(0, 0);
 }
 
-void wxDC::SetLogicalScale(double x, double y)
+// For use by wxWidgets only, unless custom units are required.
+void wxPalmDCImpl::SetLogicalScale(double x, double y)
 {
 }
 
@@ -447,11 +523,22 @@ void wxDC::SetLogicalScale(double x, double y)
 
 #if wxUSE_DC_CACHEING
 
-wxList wxDC::sm_bitmapCache;
-wxList wxDC::sm_dcCache;
+/*
+ * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will
+ * improve it in due course, either using arrays, or simply storing pointers to one
+ * entry for the bitmap, and two for the DCs. -- JACS
+ */
+
+wxObjectList wxPalmDCImpl::sm_bitmapCache;
+wxObjectList wxPalmDCImpl::sm_dcCache;
 
 wxDCCacheEntry::wxDCCacheEntry(WXHBITMAP hBitmap, int w, int h, int depth)
 {
+    m_bitmap = hBitmap;
+    m_dc = 0;
+    m_width = w;
+    m_height = h;
+    m_depth = depth;
 }
 
 wxDCCacheEntry::wxDCCacheEntry(WXHDC hDC, int depth)
@@ -462,33 +549,34 @@ wxDCCacheEntry::~wxDCCacheEntry()
 {
 }
 
-wxDCCacheEntry* wxDC::FindBitmapInCache(WXHDC dc, int w, int h)
+wxDCCacheEntry* wxPalmDCImpl::FindBitmapInCache(WXHDC dc, int w, int h)
 {
     return NULL;
 }
 
-wxDCCacheEntry* wxDC::FindDCInCache(wxDCCacheEntry* notThis, WXHDC dc)
+wxDCCacheEntry* wxPalmDCImpl::FindDCInCache(wxDCCacheEntry* notThis, WXHDC dc)
 {
     return NULL;
 }
 
-void wxDC::AddToBitmapCache(wxDCCacheEntry* entry)
+void wxPalmDCImpl::AddToBitmapCache(wxDCCacheEntry* entry)
 {
 }
 
-void wxDC::AddToDCCache(wxDCCacheEntry* entry)
+void wxPalmDCImpl::AddToDCCache(wxDCCacheEntry* entry)
 {
 }
 
-void wxDC::ClearCache()
+void wxPalmDCImpl::ClearCache()
 {
 }
 
+// Clean up cache at app exit
 class wxDCModule : public wxModule
 {
 public:
     virtual bool OnInit() { return true; }
-    virtual void OnExit() { wxDC::ClearCache(); }
+    virtual void OnExit() { wxPalmDCImpl::ClearCache(); }
 
 private:
     DECLARE_DYNAMIC_CLASS(wxDCModule)
@@ -497,3 +585,40 @@ private:
 IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule)
 
 #endif // wxUSE_DC_CACHEING
+
+void wxPalmDCImpl::DoGradientFillLinear (const wxRect& rect,
+                                 const wxColour& initialColour,
+                                 const wxColour& destColour,
+                                 wxDirection nDirection)
+{
+}
+
+#if wxUSE_DYNLIB_CLASS
+
+wxLayoutDirection wxPalmDCImpl::GetLayoutDirection() const
+{
+    DWORD layout = wxGetDCLayout(GetHdc());
+
+    if ( layout == (DWORD)-1 )
+        return wxLayout_Default;
+
+    return layout & LAYOUT_RTL ? wxLayout_RightToLeft : wxLayout_LeftToRight;
+}
+
+void wxPalmDCImpl::SetLayoutDirection(wxLayoutDirection dir)
+{
+}
+
+#else // !wxUSE_DYNLIB_CLASS
+
+// we can't provide RTL support without dynamic loading, so stub it out
+wxLayoutDirection wxPalmDCImpl::GetLayoutDirection() const
+{
+    return wxLayout_Default;
+}
+
+void wxPalmDCImpl::SetLayoutDirection(wxLayoutDirection WXUNUSED(dir))
+{
+}
+
+#endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS
diff --git a/src/palmos/dcclient.cpp b/src/palmos/dcclient.cpp
index b8a423d326..6a190e5938 100644
--- a/src/palmos/dcclient.cpp
+++ b/src/palmos/dcclient.cpp
@@ -25,6 +25,7 @@
 #endif
 
 #include "wx/dcclient.h"
+#include "wx/palmos/dcclient.h"
 
 #ifndef WX_PRECOMP
     #include "wx/string.h"
@@ -38,36 +39,35 @@
 
 struct WXDLLEXPORT wxPaintDCInfo
 {
-    wxPaintDCInfo(wxWindow *win, wxDC *dc)
+    wxPaintDCInfo(wxWindow *win, wxPaintDCImpl *dc)
     {
-        handle = win->GetWinHandle();
-        hdc    = dc->GetHDC();
-        count  = 1;
+        hwnd = win->GetHWND();
+        hdc = dc->GetHDC();
+        count = 1;
     }
 
-    WXWINHANDLE handle;       // window for this DC
-    WXHDC       hdc;        // the DC handle
-    size_t     count;      // usage count
+    WXHWND    hwnd;       // window for this DC
+    WXHDC     hdc;        // the DC handle
+    size_t    count;      // usage count
 };
 
 #include "wx/arrimpl.cpp"
 
-WX_DEFINE_OBJARRAY(wxArrayDCInfo);
+WX_DEFINE_OBJARRAY(wxArrayDCInfo)
 
 // ----------------------------------------------------------------------------
 // macros
 // ----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
-IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
-IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxClientDC)
-IMPLEMENT_CLASS(wxPaintDCEx, wxPaintDC)
-
 // ----------------------------------------------------------------------------
 // global variables
 // ----------------------------------------------------------------------------
 
 #ifdef __WXDEBUG__
+    // a global variable which we check to verify that wxPaintDC are only
+    // created in response to WM_PAINT message - doing this from elsewhere is a
+    // common programming error among wxWidgets programmers and might lead to
+    // very subtle and difficult to debug refresh/repaint bugs.
     int g_isPainting = 0;
 #endif // __WXDEBUG__
 
@@ -76,85 +76,218 @@ IMPLEMENT_CLASS(wxPaintDCEx, wxPaintDC)
 // ===========================================================================
 
 // ----------------------------------------------------------------------------
-// wxWindowDC
+// wxWindowDCImpl
 // ----------------------------------------------------------------------------
 
-wxWindowDC::wxWindowDC()
+IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl, wxPalmDCImpl)
+
+wxWindowDCImpl::wxWindowDCImpl( wxDC *owner ) :
+   wxPalmDCImpl( owner )
 {
 }
 
-wxWindowDC::wxWindowDC(wxWindow *canvas)
+wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow *window ) :
+   wxPalmDCImpl( owner )
 {
+    wxCHECK_RET( window, _T("invalid window in wxWindowDCImpl") );
 }
 
-void wxWindowDC::InitDC()
+void wxWindowDCImpl::InitDC()
 {
+
+    // since we are a window dc we need to grab the palette from the window
+#if wxUSE_PALETTE
+    InitializePalette();
+#endif
 }
 
-void wxWindowDC::DoGetSize(int *width, int *height) const
+void wxWindowDCImpl::DoGetSize(int *width, int *height) const
 {
+    wxCHECK_RET( m_window, _T("wxWindowDCImpl without a window?") );
+
+    m_window->GetSize(width, height);
 }
 
 // ----------------------------------------------------------------------------
-// wxClientDC
+// wxClientDCImpl
 // ----------------------------------------------------------------------------
 
-wxClientDC::wxClientDC()
+IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl)
+
+wxClientDCImpl::wxClientDCImpl( wxDC *owner ) :
+   wxWindowDCImpl( owner )
 {
 }
 
-wxClientDC::wxClientDC(wxWindow *canvas)
+wxClientDCImpl::wxClientDCImpl( wxDC *owner, wxWindow *window ) :
+   wxWindowDCImpl( owner )
 {
 }
 
-void wxClientDC::InitDC()
+void wxClientDCImpl::InitDC()
 {
+    wxWindowDCImpl::InitDC();
+
+    // in wxUniv build we must manually do some DC adjustments usually
+    // performed by Windows for us
+    //
+    // we also need to take the menu/toolbar manually into account under
+    // Windows CE because they're just another control there, not anything
+    // special as usually under Windows
+#if defined(__WXUNIVERSAL__) || defined(__WXWINCE__)
+    wxPoint ptOrigin = m_window->GetClientAreaOrigin();
+    if ( ptOrigin.x || ptOrigin.y )
+    {
+        // no need to shift DC origin if shift is null
+        SetDeviceOrigin(ptOrigin.x, ptOrigin.y);
+    }
+
+    // clip the DC to avoid overwriting the non client area
+    SetClippingRegion(wxPoint(0,0), m_window->GetClientSize());
+#endif // __WXUNIVERSAL__ || __WXWINCE__
 }
 
-wxClientDC::~wxClientDC()
+wxClientDCImpl::~wxClientDCImpl()
 {
 }
 
-void wxClientDC::DoGetSize(int *width, int *height) const
+void wxClientDCImpl::DoGetSize(int *width, int *height) const
 {
+    wxCHECK_RET( m_window, _T("wxClientDCImpl without a window?") );
+
+    m_window->GetClientSize(width, height);
 }
 
 // ----------------------------------------------------------------------------
-// wxPaintDC
+// wxPaintDCImpl
 // ----------------------------------------------------------------------------
 
-wxArrayDCInfo wxPaintDC::ms_cache;
-
-wxPaintDC::wxPaintDC()
+// VZ: initial implementation (by JACS) only remembered the last wxPaintDC
+//     created and tried to reuse it - this was supposed to take care of a
+//     situation when a derived class OnPaint() calls base class OnPaint()
+//     because in this case ::BeginPaint() shouldn't be called second time.
+//
+//     I'm not sure how useful this is, however we must remember the HWND
+//     associated with the last HDC as well - otherwise we may (and will!) try
+//     to reuse the HDC for another HWND which is a nice recipe for disaster.
+//
+//     So we store a list of windows for which we already have the DC and not
+//     just one single hDC. This seems to work, but I'm really not sure about
+//     the usefullness of the whole idea - IMHO it's much better to not call
+//     base class OnPaint() at all, or, if we really want to allow it, add a
+//     "wxPaintDC *" parameter to wxPaintEvent which should be used if it's
+//     !NULL instead of creating a new DC.
+
+IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxClientDCImpl)
+
+wxArrayDCInfo wxPaintDCImpl::ms_cache;
+
+wxPaintDCImpl::wxPaintDCImpl( wxDC *owner ) :
+   wxClientDCImpl( owner )
 {
 }
 
-wxPaintDC::wxPaintDC(wxWindow *canvas)
+wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *window ) :
+   wxClientDCImpl( owner )
 {
-}
+    wxCHECK_RET( window, wxT("NULL canvas in wxPaintDCImpl ctor") );
 
-wxPaintDC::~wxPaintDC()
-{
-}
+#ifdef __WXDEBUG__
+    if ( g_isPainting <= 0 )
+    {
+        wxFAIL_MSG( wxT("wxPaintDCImpl may be created only in EVT_PAINT handler!") );
 
-wxPaintDCInfo *wxPaintDC::FindInCache(size_t *index) const
-{
-    return NULL;
+        return;
+    }
+#endif // __WXDEBUG__
+
+    m_window = window;
+
+    // do we have a DC for this window in the cache?
+    wxPaintDCInfo *info = FindInCache();
+    if ( info )
+    {
+        m_hDC = info->hdc;
+        info->count++;
+    }
+    else // not in cache, create a new one
+    {
+        //m_hDC = (WXHDC)::BeginPaint(GetHwndOf(m_window), &g_paintStruct);
+        if (m_hDC)
+            ms_cache.Add(new wxPaintDCInfo(m_window, this));
+    }
+
+    // Note: at this point m_hDC can be NULL under MicroWindows, when dragging.
+    if (!GetHDC())
+        return;
+
+    // (re)set the DC parameters.
+    InitDC();
+
+    // the HDC can have a clipping box (which we didn't set), make sure our
+    // DoGetClippingBox() checks for it
+    m_clipping = true;
 }
 
-WXHDC wxPaintDC::FindDCInCache(wxWindow* win)
+wxPaintDCImpl::~wxPaintDCImpl()
 {
-    return 0;
-}
+    if ( m_hDC )
+    {
+        SelectOldObjects(m_hDC);
+
+        size_t index;
+        wxPaintDCInfo *info = FindInCache(&index);
+
+        wxCHECK_RET( info, wxT("existing DC should have a cache entry") );
 
-/*
- * wxPaintDCEx
- */
+        if ( --info->count == 0 )
+        {
+            //::EndPaint(GetHwndOf(m_window), &g_paintStruct);
 
-wxPaintDCEx::wxPaintDCEx(wxWindow *canvas, WXHDC dc) : saveState(0)
+            ms_cache.RemoveAt(index);
+
+            // Reduce the number of bogus reports of non-freed memory
+            // at app exit
+            if (ms_cache.IsEmpty())
+                ms_cache.Clear();
+        }
+        //else: cached DC entry is still in use
+
+        // prevent the base class dtor from ReleaseDC()ing it again
+        m_hDC = 0;
+    }
+}
+
+wxPaintDCInfo *wxPaintDCImpl::FindInCache(size_t *index) const
 {
+    wxPaintDCInfo *info = NULL;
+    size_t nCache = ms_cache.GetCount();
+    for ( size_t n = 0; n < nCache; n++ )
+    {
+        wxPaintDCInfo *info1 = &ms_cache[n];
+        if ( info1->hwnd == m_window->GetHWND() )
+        {
+            info = info1;
+            if ( index )
+                *index = n;
+            break;
+        }
+    }
+
+    return info;
 }
 
-wxPaintDCEx::~wxPaintDCEx()
+// find the entry for this DC in the cache (keyed by the window)
+WXHDC wxPaintDCImpl::FindDCInCache(wxWindow* win)
 {
+    size_t nCache = ms_cache.GetCount();
+    for ( size_t n = 0; n < nCache; n++ )
+    {
+        wxPaintDCInfo *info = &ms_cache[n];
+        if ( info->hwnd == win->GetHWND() )
+        {
+            return info->hdc;
+        }
+    }
+    return 0;
 }
diff --git a/src/palmos/dcmemory.cpp b/src/palmos/dcmemory.cpp
index 5211678a18..827aaddea2 100644
--- a/src/palmos/dcmemory.cpp
+++ b/src/palmos/dcmemory.cpp
@@ -25,6 +25,7 @@
 #endif
 
 #include "wx/dcmemory.h"
+#include "wx/palmos/dcmemory.h"
 
 #ifndef WX_PRECOMP
     #include "wx/utils.h"
@@ -32,55 +33,61 @@
 #endif
 
 // ----------------------------------------------------------------------------
-// wxWin macros
+// wxMemoryDCImpl
 // ----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
+IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl, wxPalmDCImpl)
 
-// ============================================================================
-// implementation
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// wxMemoryDC
-// ----------------------------------------------------------------------------
-
-wxMemoryDC::wxMemoryDC(wxDC *dc)
+wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner ) 
+        : wxPalmDCImpl( owner )
 {
+    CreateCompatible(NULL); 
+    Init(); 
 }
 
-void wxMemoryDC::Init()
-{
+wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap ) 
+        : wxPalmDCImpl( owner ) 
+{ 
+    CreateCompatible(NULL); 
+    Init(); 
+    DoSelect(bitmap);
 }
 
-bool wxMemoryDC::CreateCompatible(wxDC *dc)
+wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC *dc )
+        : wxPalmDCImpl( owner ) 
 {
-    return false;
-}
+    wxCHECK_RET( dc, _T("NULL dc in wxMemoryDC ctor") );
 
-void wxMemoryDC::DoSelect(const wxBitmap& bitmap)
-{
+    CreateCompatible(dc);
+
+    Init();
 }
 
-void wxMemoryDC::DoGetSize(int *width, int *height) const
+void wxMemoryDCImpl::Init()
 {
 }
 
-// the rest of this file deals with drawing rectangles workaround, disabled by
-// default
-
-#define wxUSE_MEMORY_DC_DRAW_RECTANGLE 0
+bool wxMemoryDCImpl::CreateCompatible(wxDC *dc)
+{
+    wxDCImpl *impl = dc ? dc->GetImpl() : NULL ;
+    wxPalmDCImpl *msw_impl = wxDynamicCast( impl, wxPalmDCImpl );
+    if ( dc && !msw_impl)
+    {
+        m_ok = false;
+        return false;
+    }
 
-#if wxUSE_MEMORY_DC_DRAW_RECTANGLE
+    return false;
+}
 
-// For some reason, drawing a rectangle on a memory DC has problems.
-// Use this substitute if we can.
-static void wxDrawRectangle(wxDC& dc, wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
 {
 }
 
-#endif // wxUSE_MEMORY_DC_DRAW_RECTANGLE
+void wxMemoryDCImpl::DoGetSize(int *width, int *height) const
+{
+}
 
-void wxMemoryDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+wxBitmap wxMemoryDCImpl::DoGetAsBitmap(const wxRect* subrect) const
 {
 }
diff --git a/src/palmos/dcscreen.cpp b/src/palmos/dcscreen.cpp
index f89af8a49a..b223aaa5e3 100644
--- a/src/palmos/dcscreen.cpp
+++ b/src/palmos/dcscreen.cpp
@@ -16,20 +16,21 @@
     #pragma hdrstop
 #endif
 
-#include "wx/dcscreen.h"
+#include "wx/palmos/dcscreen.h"
 
 #ifndef WX_PRECOMP
    #include "wx/string.h"
    #include "wx/window.h"
 #endif
 
-IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
+IMPLEMENT_ABSTRACT_CLASS(wxScreenDCImpl, wxPalmDCImpl)
 
 // Create a DC representing the whole screen
-wxScreenDC::wxScreenDC()
+wxScreenDCImpl::wxScreenDCImpl( wxScreenDC *owner ) :
+    wxPalmDCImpl( owner )
 {
 }
 
-void wxScreenDC::DoGetSize(int *width, int *height) const
+void wxScreenDCImpl::DoGetSize (int *w, int *h) const
 {
 }
diff --git a/src/palmos/dialog.cpp b/src/palmos/dialog.cpp
index 88c4620e43..32535b9bca 100644
--- a/src/palmos/dialog.cpp
+++ b/src/palmos/dialog.cpp
@@ -147,11 +147,14 @@ bool wxDialog::Create(wxWindow *parent,
                       long style,
                       const wxString& name)
 {
-    return false;
+    if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
+        return false;
+    return true;
 }
 
 wxDialog::~wxDialog()
 {
+    Show (false);
 }
 
 // ----------------------------------------------------------------------------
@@ -165,7 +168,7 @@ wxWindow *wxDialog::FindSuitableParent() const
 
 bool wxDialog::Show(bool show)
 {
-    return false;
+    return wxTopLevelWindowPalm::Show (show);
 }
 
 void wxDialog::Raise()
@@ -175,6 +178,9 @@ void wxDialog::Raise()
 // show dialog modally
 int wxDialog::ShowModal()
 {
+    if (errNone == FrmDoDialog ((FormType *)wxTopLevelWindow::GetForm())) {
+        return 0;
+    }
     return -1;
 }
 
diff --git a/src/palmos/evtloop.cpp b/src/palmos/evtloop.cpp
index 84d17fef35..01bd21e982 100644
--- a/src/palmos/evtloop.cpp
+++ b/src/palmos/evtloop.cpp
@@ -135,3 +135,8 @@ bool wxGUIEventLoop::Dispatch()
     return false;
 }
 
+void wxGUIEventLoop::WakeUp()
+{
+    return;
+}
+
diff --git a/src/palmos/main.cpp b/src/palmos/main.cpp
index d1ca479472..2c4f957771 100644
--- a/src/palmos/main.cpp
+++ b/src/palmos/main.cpp
@@ -48,12 +48,12 @@ int wxEntry()
      */
     wxArrayString args;
     int argc = args.GetCount();
-
     // +1 here for the terminating NULL
     wxChar **argv = new wxChar *[argc + 1];
     for ( int i = 0; i < argc; i++ )
     {
-        argv[i] = wxStrdup(args[i]);
+        //argv[i] = wxStrdup(args[i]);
+        argv[i] = wxStrdup(wxConvLibc.cMB2WX(args[i]));
     }
 
     // argv[] must be NULL-terminated
diff --git a/src/palmos/prefconf.cpp b/src/palmos/prefconf.cpp
index 5347007980..6bb8b54f99 100644
--- a/src/palmos/prefconf.cpp
+++ b/src/palmos/prefconf.cpp
@@ -178,11 +178,13 @@ bool wxPrefConfig::DoReadLong(const wxString& key, long *plResult) const
     return false;
 }
 
-bool DoReadBinary(const wxString& key, wxMemoryBuffer *buf) const
+#if wxUSE_BASE64
+bool wxPrefConfig::DoReadBinary(const wxString& key, wxMemoryBuffer *buf) const
 {
     /* TODO */
     return false;
 }
+#endif // wxUSE_BASE64
 
 bool wxPrefConfig::DoWriteString(const wxString& key, const wxString& szValue)
 {
@@ -196,11 +198,13 @@ bool wxPrefConfig::DoWriteLong(const wxString& key, long lValue)
     return false;
 }
 
-bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf)
+#if wxUSE_BASE64
+bool wxPrefConfig::DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf)
 {
     /* TODO */
     return false;
 }
+#endif // wxUSE_BASE64
 
 // ----------------------------------------------------------------------------
 // renaming
diff --git a/src/palmos/stdall.c b/src/palmos/stdall.c
new file mode 100644
index 0000000000..c4a0d054b6
--- /dev/null
+++ b/src/palmos/stdall.c
@@ -0,0 +1,360 @@
+
+#include <Preferences.h> // Core/System/
+#include <DateTime.h> //Core/System/, DateToAscii() etc.
+#include <TimeMgr.h> //Core/System/, TimGetTicks()
+
+#include "wx/defs.h"
+
+#if __WXPALMOS6__
+void
+exit (int exitno)
+{
+}
+
+#else
+
+#define SEC_1904_1970 2082844800LU//0x7C25B080 // 0x7C25B080 == 2082844800LU
+
+time_t
+time (time_t *T)
+{
+    UInt32 sec;
+    // UInt32 TimGetSeconds(void); // seconds since 1/1/1904
+    // void TimSetSeconds (UInt32 seconds); // seconds since 1/1/1904
+    // UInt32 TimGetTicks(void); // ticks since power on
+    sec = TimGetSeconds ();
+    if (T) {
+        *T = sec - SEC_1904_1970;
+    }
+    return (sec - SEC_1904_1970);
+}
+
+static struct tm *
+palmtimet2unixtm (const time_t t, struct tm *ptm)
+{
+    DateTimeType dt;
+    memset (&dt, 0, sizeof (dt));
+    memset (ptm, 0, sizeof (*ptm));
+    TimSecondsToDateTime (t, &dt);
+    ptm->tm_sec  = dt.second;
+    ptm->tm_min  = dt.minute;
+    ptm->tm_hour = dt.hour;
+    ptm->tm_mday = dt.day;
+    ptm->tm_mon  = dt.month;
+    ptm->tm_year = dt.year;
+    ptm->tm_wday = dt.weekDay;
+
+    //ptm->tm_wday = DayOfWeek (dt.month, dt.day, dt.year);
+    //ptm->tm_mday = DayOfMonth (dt.month, dt.day, dt.year);
+    return ptm;
+}
+
+struct tm *
+gmtime_r (const time_t *pt, struct tm *ptm)
+{
+    UInt32 utcTime;
+    Int16 timeZone = PrefGetPreference(prefTimeZone);
+    Int16 daylightSavingAdjustment = PrefGetPreference(prefDaylightSavingAdjustment);
+
+    if ((NULL == pt) || (NULL == ptm)) {
+        return NULL;
+    }
+    utcTime = TimTimeZoneToUTC (*pt + SEC_1904_1970, timeZone, daylightSavingAdjustment);
+    palmtimet2unixtm (utcTime, ptm);
+    return ptm;
+}
+
+struct tm *
+localtime_r (const time_t *pt, struct tm *ptm)
+{
+    UInt32 utcTime;
+    Int16 timeZone = PrefGetPreference(prefTimeZone);
+    Int16 daylightSavingAdjustment = PrefGetPreference(prefDaylightSavingAdjustment);
+    if ((NULL == pt) || (NULL == ptm)) {
+        return NULL;
+    }
+    utcTime = TimUTCToTimeZone (*pt + SEC_1904_1970, timeZone, daylightSavingAdjustment);
+    palmtimet2unixtm (utcTime, ptm);
+    return ptm;
+}
+/*
+static struct tm g_gmtime_info;
+
+struct tm *
+gmtime (const time_t *CLOCK)
+{
+    if (NULL == CLOCK) {
+        return NULL;
+    }
+    if (NULL == gmtime_r (CLOCK, &g_gmtime_info)) {
+        return NULL;
+    }
+    return &g_gmtime_info;
+}
+*/
+static struct tm g_localtime_info;
+
+struct tm *
+localtime (const time_t *CLOCK)
+{
+    if (NULL == CLOCK) {
+        return NULL;
+    }
+    if (NULL == localtime_r (CLOCK, &g_localtime_info)) {
+        return NULL;
+    }
+    return &g_localtime_info;
+}
+
+static char * g_strftime_wdayconv[][2] = {
+    {"Sun", "Sunday"},
+    {"Mon", "Monday"},
+    {"Tue", "Tuesday"},
+    {"Wed", "Wednesday"},
+    {"Thu", "Thursday"},
+    {"Fri", "Friday"},
+    {"Sat", "Saturday"},
+};
+
+static char * g_strftime_monconv[][2] = {
+    {"Jan", "January"},
+    {"Feb", "Febuary"},
+    {"Mar", "March"},
+    {"Apr", "April"},
+    {"May", "May"},
+    {"Jun", "June"},
+    {"Jul", "July"},
+    {"Aug", "August"},
+    {"Sep", "September"},
+    {"Oct", "October"},
+    {"Nov", "November"},
+    {"Dec", "December"},
+};
+#define SFCONV_ABBR 0
+#define SFCONV_FULL 1
+
+size_t
+strftime (char *buf, size_t sz_buf, const char *fmt, const struct tm *ptm)
+{
+    char *p;
+    char *pret;
+    if ((timeStringLength > sz_buf) || (strlen (fmt) < 1)) {
+        return 0;
+    }
+    memset (buf, 0, sz_buf);
+    p = fmt;
+    pret = buf;
+    for (; *p != '\0';) {
+        if ('%' == *p) {
+            p ++;
+            if (*p == '\0') {
+                break;
+            }
+            // FIXME: Åжϻº³åÊÇ·ñÒç³ö
+            switch (*p) {
+            case 'a':
+                strcpy (pret, g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_ABBR]);
+                pret += 3;
+                break;
+            case 'A':
+                strcpy (pret, g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_FULL]);
+                pret += strlen (g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_FULL]);
+                break;
+            case 'b':
+                strcpy (pret, g_strftime_monconv[ptm->tm_mon % 12][SFCONV_ABBR]);
+                pret += 3;
+                break;
+            case 'B':
+                strcpy (pret, g_strftime_monconv[ptm->tm_mon % 12][SFCONV_FULL]);
+                pret += strlen (g_strftime_monconv[ptm->tm_mon % 12][SFCONV_FULL]);
+                break;
+            case 'c':
+                strcpy (pret, g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_ABBR]);
+                pret += 3;
+                *pret = ' ';
+                pret ++;
+                strcpy (pret, g_strftime_monconv[ptm->tm_mon % 12][SFCONV_ABBR]);
+                pret += 3;
+                *pret = ' ';
+                pret ++;
+                sprintf (pret, "%d %02d:%02d:%02d %d", ptm->tm_mday,
+                    ptm->tm_hour, ptm->tm_min, ptm->tm_sec, ptm->tm_year);
+                pret += strlen (pret);
+                break;
+            case 'd':
+                sprintf (pret, "%02d", ptm->tm_mday % 31);
+                pret += 2;
+                break;
+            case 'H':
+                sprintf (pret, "%02d", ptm->tm_hour % 24);
+                pret += 2;
+                break;
+            case 'I':
+                sprintf (pret, "%02d", (ptm->tm_hour % 12) + 1);
+                pret += 2;
+                break;
+            case 'j':
+                sprintf (pret, "%03d", ptm->tm_year % 400);
+                pret += 3;
+                break;
+            case 'm':
+                sprintf (pret, "%02d", (ptm->tm_mon % 12) + 1);
+                pret += 2;
+                break;
+            case 'M':
+                sprintf (pret, "%02d", ptm->tm_min % 60);
+                pret += 2;
+                break;
+            case 'p':
+                if (ptm->tm_hour > 12) {
+                    strcpy (pret, "PM");
+                    break;
+                }
+                strcpy (pret, "AM");
+                pret += 2;
+                break;
+            case 'S':
+                sprintf (pret, "%02d", ptm->tm_sec % 61);
+                pret += 2;
+                break;
+            case 'U':
+                // FIXME: Week number with the first Sunday as the first day of week one (00-53)
+                sprintf (pret, "%02d", ptm->tm_yday / 7);
+                pret += 2;
+                break;
+            case 'w':
+                sprintf (pret, "%d", ptm->tm_wday % 7);
+                pret += 1;
+                break;
+            case 'W':
+                // FIXME: Week number with the first Sunday as the first day of week one (00-53)
+                sprintf (pret, "%02d", ptm->tm_yday / 7);
+                pret += 2;
+                break;
+            case 'x':
+                sprintf (pret, "%02d/%02d/%02d",
+                    ptm->tm_mon, ptm->tm_mday, ptm->tm_year - 1900);
+                pret += strlen (pret);
+                break;
+            case 'X':
+                sprintf (pret, "%02d:%02d:%02d",
+                    ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
+                pret += strlen (pret);
+                break;
+            case 'y':
+                sprintf (pret, "%02d", ptm->tm_year - 1900);
+                pret += 2;
+                break;
+            case 'Y':
+                sprintf (pret, "%02d", ptm->tm_year);
+                pret += strlen (pret);
+                break;
+            case 'Z':
+            {
+                LmLocaleType ll;
+                ll.language = lmAnyLanguage;
+                ll.country = 0;
+                TimeZoneToAscii (ptm->tm_gmtoff, &ll, pret);
+            }
+                pret += strlen (pret);
+                break;
+            case '%':
+                *pret = *p;
+                pret ++;
+                break;
+            }
+        } else {
+            *pret = *p;
+            pret ++;
+        }
+        p ++;
+    }
+    return 0;
+}
+
+time_t
+mktime (struct tm *ptm)
+{
+    DateTimeType dt;
+    if (NULL == ptm) {
+        return 0;
+    }
+    memset (&dt, 0, sizeof (dt));
+    dt.second  = ptm->tm_sec;
+    dt.minute  = ptm->tm_min;
+    dt.hour    = ptm->tm_hour;
+    dt.day     = ptm->tm_mday;
+    dt.month   = ptm->tm_mon;
+    dt.year    = ptm->tm_year;
+    dt.weekDay = ptm->tm_wday;
+    return TimDateTimeToSeconds (&dt);
+}
+
+int
+vsscanf (const char *s, const char *format, va_list param)
+{
+    return -1;
+}
+
+FILE * fopen (const char *_name, const char *_type) {return NULL;}
+int fclose (FILE *fp) {return 0;}
+size_t fread (void *buf, size_t _size, size_t _n, FILE *fp) {return 0;}
+size_t fwrite (const void *buf , size_t _size, size_t _n, FILE *fp) {return 0;}
+int fseek (FILE *fp, long offset, int whence) {return -1;}
+long ftell (FILE *fp) {return -1;}
+int feof (FILE *fp) {return -1;}
+int ferror (FILE *fp) {return -1;}
+void clearerr (FILE *fp) {}
+
+#endif // __WXPALMOS6__
+
+#define _BIT_ALPHA  0X0001
+#define _BIT_BLANK  0X0002
+#define _BIT_CNTRL  0X0004
+#define _BIT_DIGIT  0X0008
+#define _BIT_GRAPH  0X0010
+#define _BIT_LOWER  0X0020
+#define _BIT_PRINT  0X0040
+#define _BIT_PUNCT  0X0080
+#define _BIT_SPACE  0X0100
+#define _BIT_UPPER  0X0200
+#define _BIT_XDIGIT 0X0400
+
+int iswalnum(wint_t C) {return 0;}
+int iswalpha(wint_t C) {return 0;}
+int iswcntrl(wint_t C) {return 0;}
+int iswdigit(wint_t C) {return 0;}
+int iswgraph(wint_t C) {return 0;}
+int iswlower(wint_t C) {return 0;}
+int iswprint(wint_t C) {return 0;}
+int iswpunct(wint_t C) {return 0;}
+int iswspace(wint_t C) {return 0;}
+int iswupper(wint_t C) {return 0;}
+int iswxdigit(wint_t C) {return 0;}
+
+wint_t towlower(wint_t C) {return 0;}
+wint_t towupper(wint_t C) {return 0;}
+size_t wcsftime(wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr) {return 0;}
+
+size_t wcslen (const wchar_t * str) {return 0;}
+wchar_t * wcscpy (wchar_t * dst, const wchar_t * src) {return NULL;}
+wchar_t * wcsncpy (wchar_t * dst, const wchar_t * src, size_t n) {return NULL;}
+wchar_t * wcscat (wchar_t * dst, const wchar_t * src) {return NULL;}
+wchar_t * wcsncat (wchar_t * dst, const wchar_t * src, size_t n) {return NULL;}
+int wcscmp (const wchar_t * str1, const wchar_t * str2) {return 0;}
+int wcsncmp (const wchar_t * str1, const wchar_t * str2, size_t n) {return 0;}
+wchar_t * wcschr (const wchar_t * str, const wchar_t chr) {return NULL;}
+int wcscoll (const wchar_t *str1, const wchar_t * str2) {return 0;}
+size_t wcsxfrm (wchar_t * str1, const wchar_t * str2, size_t n) {return 0;}
+wchar_t * wcsrchr (const wchar_t * str, wchar_t chr) {return NULL;}
+wchar_t * wcspbrk (const wchar_t * str, const wchar_t * set) {return NULL;}
+size_t wcsspn (const wchar_t * str, const wchar_t * set) {return 0;}
+size_t wcscspn (const wchar_t * str, const wchar_t * set) {return 0;}
+wchar_t * wcsstr (const wchar_t * str, const wchar_t * pat) {return NULL;}
+wchar_t * wcstok (wchar_t * str, const wchar_t * set, wchar_t ** a) {return NULL;}
+
+unsigned long wcstoul (const wchar_t * a, wchar_t ** b, int c) {return 0;}
+double wcstod (const wchar_t * a, wchar_t ** b) {return 0.0;}
+
+long wcstol (const wchar_t * str, wchar_t ** end, int base) {return 0;}
+char * setlocale (int category, const char *locale) {return NULL;}
diff --git a/src/palmos/toplevel.cpp b/src/palmos/toplevel.cpp
index 8f28b50904..2863573c9e 100644
--- a/src/palmos/toplevel.cpp
+++ b/src/palmos/toplevel.cpp
@@ -167,6 +167,9 @@ void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd)
 
 bool wxTopLevelWindowPalm::Show(bool show)
 {
+    if (true != show) {
+	    return true;
+    }
     FrmDrawForm((FormType *)FrameForm);
 
     wxPaintEvent event(m_windowId);
diff --git a/src/palmos/utils.cpp b/src/palmos/utils.cpp
index e0da4651b1..f63cfb67ee 100644
--- a/src/palmos/utils.cpp
+++ b/src/palmos/utils.cpp
@@ -122,10 +122,12 @@ bool wxGetEnv(const wxString& var, wxString *value)
     return false;
 }
 
+#if ! WXWIN_COMPATIBILITY_2_8
 bool wxSetEnv(const wxString& var, const wxChar *value)
 {
     return false;
 }
+#endif // ! WXWIN_COMPATIBILITY_2_8
 
 bool wxUnsetEnv(const wxString& var)
 {
diff --git a/src/palmos/window.cpp b/src/palmos/window.cpp
index f2f25a0109..3507888caf 100644
--- a/src/palmos/window.cpp
+++ b/src/palmos/window.cpp
@@ -76,6 +76,7 @@
 #include "wx/notebook.h"
 #include "wx/listctrl.h"
 
+#ifndef __WXUNIVERSAL__
 #include <Window.h>
 
 // ---------------------------------------------------------------------------
@@ -247,7 +248,7 @@ bool wxGetKeyState(wxKeyCode key)
 
 void wxWindowPalm::Init()
 {
-    m_handle = 0;
+    m_hWnd = 0;
 }
 
 // Destructor
@@ -445,7 +446,7 @@ void wxWindowPalm::Thaw()
 
 void wxWindowPalm::Refresh(bool eraseBack, const wxRect *rect)
 {
-    WinHandle handle = (WinHandle)GetWinHandle();
+    WinHandle handle = (WinHandle)GetHWND();
     if(handle)
     {
         if(rect)
@@ -754,5 +755,5 @@ bool wxWindowPalm::UnregisterHotKey(int hotkeyId)
 {
     return false;
 }
-
+#endif // # __WXUNIVERSAL__
 #endif // wxUSE_HOTKEY
-- 
2.47.2