From 76a5e5d21ee1a6230d777ce0209b2df4c6075f0f Mon Sep 17 00:00:00 2001
From: Stefan Csomor <csomor@advancedconcepts.ch>
Date: Fri, 4 Jan 2002 17:26:02 +0000
Subject: [PATCH] removing dependancy on mac headers from public wx headers
 (eventually adding wx/mac/private and typecasts)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13370 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 src/common/cmndata.cpp      |  54 ++--
 src/common/dynlib.cpp       |  10 +-
 src/common/fileconf.cpp     |   4 +
 src/common/filefn.cpp       |   4 +
 src/common/filename.cpp     |   4 +
 src/common/intl.cpp         |   4 +
 src/common/log.cpp          |   4 +
 src/generic/dirctrlg.cpp    |   4 +
 src/mac/aga.cpp             |  68 +---
 src/mac/app.cpp             |  58 ++--
 src/mac/bitmap.cpp          | 108 +++----
 src/mac/bmpbuttn.cpp        |  24 +-
 src/mac/brush.cpp           |  54 +++-
 src/mac/button.cpp          |  18 +-
 src/mac/carbon/aga.cpp      |  68 +---
 src/mac/carbon/app.cpp      |  58 ++--
 src/mac/carbon/bitmap.cpp   | 108 +++----
 src/mac/carbon/bmpbuttn.cpp |  24 +-
 src/mac/carbon/brush.cpp    |  54 +++-
 src/mac/carbon/button.cpp   |  18 +-
 src/mac/carbon/checkbox.cpp |   8 +-
 src/mac/carbon/checklst.cpp |  40 +--
 src/mac/carbon/choice.cpp   |  28 +-
 src/mac/carbon/clipbrd.cpp  |   4 +-
 src/mac/carbon/colordlg.cpp |   6 +-
 src/mac/carbon/colour.cpp   |  22 +-
 src/mac/carbon/combobox.cpp |  32 +-
 src/mac/carbon/control.cpp  | 103 +++---
 src/mac/carbon/cursor.cpp   |   5 +-
 src/mac/carbon/dataobj.cpp  |   1 +
 src/mac/carbon/dc.cpp       | 533 ++++++++++++++++++++++--------
 src/mac/carbon/dcclient.cpp |  47 +--
 src/mac/carbon/dcmemory.cpp |   5 +-
 src/mac/carbon/dcprint.cpp  |  30 +-
 src/mac/carbon/dirdlg.cpp   | 627 +++++-------------------------------
 src/mac/carbon/dirmac.cpp   |   2 +
 src/mac/carbon/dnd.cpp      |  25 +-
 src/mac/carbon/filedlg.cpp  | 301 +----------------
 src/mac/carbon/font.cpp     |   3 +
 src/mac/carbon/fontenum.cpp |   2 +
 src/mac/carbon/gauge.cpp    |   6 +-
 src/mac/carbon/glcanvas.cpp |   4 +-
 src/mac/carbon/gsocket.c    |   1 +
 src/mac/carbon/icon.cpp     |   9 +-
 src/mac/carbon/listbox.cpp  |  76 ++---
 src/mac/carbon/macnotfy.cpp |   7 +-
 src/mac/carbon/mdi.cpp      |   2 +
 src/mac/carbon/menu.cpp     |  48 +--
 src/mac/carbon/menuitem.cpp |  22 +-
 src/mac/carbon/metafile.cpp |  14 +-
 src/mac/carbon/notebmac.cpp |  18 +-
 src/mac/carbon/printdlg.cpp |   4 +-
 src/mac/carbon/printmac.cpp |   2 +
 src/mac/carbon/radiobox.cpp |   2 +-
 src/mac/carbon/radiobut.cpp |  10 +-
 src/mac/carbon/region.cpp   |   8 +-
 src/mac/carbon/scrolbar.cpp |  28 +-
 src/mac/carbon/settings.cpp |   2 +
 src/mac/carbon/slider.cpp   |  26 +-
 src/mac/carbon/spinbutt.cpp |  14 +-
 src/mac/carbon/statbox.cpp  |   2 +-
 src/mac/carbon/statbrma.cpp |   8 +-
 src/mac/carbon/statlmac.cpp |   2 +-
 src/mac/carbon/stattext.cpp |   2 +-
 src/mac/carbon/tabctrl.cpp  |   2 +-
 src/mac/carbon/textctrl.cpp | 120 +++----
 src/mac/carbon/thread.cpp   |   4 +
 src/mac/carbon/timer.cpp    |  58 ++--
 src/mac/carbon/toolbar.cpp  |  18 +-
 src/mac/carbon/tooltip.cpp  |  30 +-
 src/mac/carbon/toplevel.cpp |  99 +++---
 src/mac/carbon/uma.cpp      |  56 +++-
 src/mac/carbon/wave.cpp     |   6 +-
 src/mac/carbon/window.cpp   |  39 +--
 src/mac/checkbox.cpp        |   8 +-
 src/mac/checklst.cpp        |  40 +--
 src/mac/choice.cpp          |  28 +-
 src/mac/clipbrd.cpp         |   4 +-
 src/mac/colordlg.cpp        |   6 +-
 src/mac/colour.cpp          |  22 +-
 src/mac/combobox.cpp        |  32 +-
 src/mac/control.cpp         | 103 +++---
 src/mac/cursor.cpp          |   5 +-
 src/mac/dataobj.cpp         |   1 +
 src/mac/dc.cpp              | 533 ++++++++++++++++++++++--------
 src/mac/dcclient.cpp        |  47 +--
 src/mac/dcmemory.cpp        |   5 +-
 src/mac/dcprint.cpp         |  30 +-
 src/mac/dirdlg.cpp          | 627 +++++-------------------------------
 src/mac/dirmac.cpp          |   2 +
 src/mac/dnd.cpp             |  25 +-
 src/mac/filedlg.cpp         | 301 +----------------
 src/mac/font.cpp            |   3 +
 src/mac/fontenum.cpp        |   2 +
 src/mac/gauge.cpp           |   6 +-
 src/mac/glcanvas.cpp        |   4 +-
 src/mac/gsocket.c           |   1 +
 src/mac/icon.cpp            |   9 +-
 src/mac/listbox.cpp         |  76 ++---
 src/mac/macnotfy.cpp        |   7 +-
 src/mac/mdi.cpp             |   2 +
 src/mac/menu.cpp            |  48 +--
 src/mac/menuitem.cpp        |  22 +-
 src/mac/metafile.cpp        |  14 +-
 src/mac/notebmac.cpp        |  18 +-
 src/mac/printdlg.cpp        |   4 +-
 src/mac/printmac.cpp        |   2 +
 src/mac/radiobox.cpp        |   2 +-
 src/mac/radiobut.cpp        |  10 +-
 src/mac/region.cpp          |   8 +-
 src/mac/scrolbar.cpp        |  28 +-
 src/mac/settings.cpp        |   2 +
 src/mac/slider.cpp          |  26 +-
 src/mac/spinbutt.cpp        |  14 +-
 src/mac/statbox.cpp         |   2 +-
 src/mac/statbrma.cpp        |   8 +-
 src/mac/statlmac.cpp        |   2 +-
 src/mac/stattext.cpp        |   2 +-
 src/mac/tabctrl.cpp         |   2 +-
 src/mac/textctrl.cpp        | 120 +++----
 src/mac/thread.cpp          |   4 +
 src/mac/timer.cpp           |  58 ++--
 src/mac/toolbar.cpp         |  18 +-
 src/mac/tooltip.cpp         |  30 +-
 src/mac/toplevel.cpp        |  99 +++---
 src/mac/uma.cpp             |  56 +++-
 src/mac/wave.cpp            |   6 +-
 src/mac/window.cpp          |  39 +--
 128 files changed, 2616 insertions(+), 3278 deletions(-)

diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp
index 7d997f1bde..57c36a0a7c 100644
--- a/src/common/cmndata.cpp
+++ b/src/common/cmndata.cpp
@@ -213,17 +213,17 @@ wxPrintData::wxPrintData()
   #endif
 #else
     m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) );
-    (**m_macPrintInfo).iPrVersion = 0;                    // something invalid
+    (**(THPrint)m_macPrintInfo).iPrVersion = 0;                    // something invalid
 
-    (**m_macPrintInfo).prInfo.iHRes = 72;
-    (**m_macPrintInfo).prInfo.iVRes = 72;
+    (**(THPrint)m_macPrintInfo).prInfo.iHRes = 72;
+    (**(THPrint)m_macPrintInfo).prInfo.iVRes = 72;
     Rect r1 = { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 };
-    (**m_macPrintInfo).prInfo.rPage = r1;// must have its top left & (0,0)
+    (**(THPrint)m_macPrintInfo).prInfo.rPage = r1;// must have its top left & (0,0)
 
     Rect r2 = { -18, -36, 8*72 - 18, 11*72 - 36  };
-    (**m_macPrintInfo).rPaper = r2;
-    (**m_macPrintInfo).prStl.iPageV = 11 * 120 ;                // 11 inches in 120th of an inch
-    (**m_macPrintInfo).prStl.iPageH = 8 * 120 ;                // 8 inches in 120th of an inch
+    (**(THPrint)m_macPrintInfo).rPaper = r2;
+    (**(THPrint)m_macPrintInfo).prStl.iPageV = 11 * 120 ;                // 11 inches in 120th of an inch
+    (**(THPrint)m_macPrintInfo).prStl.iPageH = 8 * 120 ;                // 8 inches in 120th of an inch
 #endif
 #endif
     m_printOrientation = wxPORTRAIT;
@@ -768,7 +768,7 @@ void wxPrintData::ConvertToNative()
 {
 #if TARGET_CARBON
 #else
-    (**m_macPrintInfo).prJob.iCopies = m_printNoCopies;
+    (**(THPrint)m_macPrintInfo).prJob.iCopies = m_printNoCopies;
 #endif
 }
 
@@ -776,7 +776,7 @@ void wxPrintData::ConvertFromNative()
 {
 #if TARGET_CARBON
 #else
-    m_printNoCopies = (**m_macPrintInfo).prJob.iCopies;
+    m_printNoCopies = (**(THPrint)m_macPrintInfo).prJob.iCopies;
 #endif
 }
 #endif
@@ -1088,8 +1088,8 @@ void wxPrintDialogData::ConvertToNative()
 {
 #if TARGET_CARBON
 #else
-    (**m_printData.m_macPrintInfo).prJob.iFstPage = m_printFromPage;
-    (**m_printData.m_macPrintInfo).prJob.iLstPage = m_printToPage;
+    (**(THPrint)m_printData.m_macPrintInfo).prJob.iFstPage = m_printFromPage;
+    (**(THPrint)m_printData.m_macPrintInfo).prJob.iLstPage = m_printToPage;
     m_printData.ConvertToNative();
 #endif
 }
@@ -1099,8 +1099,8 @@ void wxPrintDialogData::ConvertFromNative()
 #if TARGET_CARBON
 #else
     m_printData.ConvertFromNative();
-    m_printFromPage = (**m_printData.m_macPrintInfo).prJob.iFstPage;
-    m_printToPage = (**m_printData.m_macPrintInfo).prJob.iLstPage;
+    m_printFromPage = (**(THPrint)m_printData.m_macPrintInfo).prJob.iFstPage;
+    m_printToPage = (**(THPrint)m_printData.m_macPrintInfo).prJob.iLstPage;
 #endif
 }
 #endif
@@ -1413,16 +1413,16 @@ void wxPageSetupDialogData::ConvertToNative()
     // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
 #if TARGET_CARBON
 #else
-    (**m_printData.m_macPrintInfo).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt );
-    (**m_printData.m_macPrintInfo).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt );
+    (**(THPrint)m_printData.m_macPrintInfo).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt );
+    (**(THPrint)m_printData.m_macPrintInfo).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt );
 
-    (**m_printData.m_macPrintInfo).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt );
-    (**m_printData.m_macPrintInfo).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt );
+    (**(THPrint)m_printData.m_macPrintInfo).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt );
+    (**(THPrint)m_printData.m_macPrintInfo).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt );
 
-    (**m_printData.m_macPrintInfo).prInfo.rPage.left = 0;
-    (**m_printData.m_macPrintInfo).prInfo.rPage.top = 0;
-    (**m_printData.m_macPrintInfo).prInfo.rPage.right =  int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt );
-    (**m_printData.m_macPrintInfo).prInfo.rPage.bottom =  int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt );
+    (**(THPrint)m_printData.m_macPrintInfo).prInfo.rPage.left = 0;
+    (**(THPrint)m_printData.m_macPrintInfo).prInfo.rPage.top = 0;
+    (**(THPrint)m_printData.m_macPrintInfo).prInfo.rPage.right =  int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt );
+    (**(THPrint)m_printData.m_macPrintInfo).prInfo.rPage.bottom =  int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt );
 #endif
 }
 
@@ -1432,14 +1432,14 @@ void wxPageSetupDialogData::ConvertFromNative()
 
 #if TARGET_CARBON
 #else
-    m_paperSize.x = ((double) (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ) * pt2mm;
-    m_paperSize.y = ((double) (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ) * pt2mm;
+    m_paperSize.x = ((double) (**(THPrint)m_printData.m_macPrintInfo).rPaper.right - (**(THPrint)m_printData.m_macPrintInfo).rPaper.left ) * pt2mm;
+    m_paperSize.y = ((double) (**(THPrint)m_printData.m_macPrintInfo).rPaper.bottom - (**(THPrint)m_printData.m_macPrintInfo).rPaper.top ) * pt2mm;
 
-    m_minMarginTopLeft.x = ((double) -(**m_printData.m_macPrintInfo).rPaper.left ) * pt2mm;
-    m_minMarginTopLeft.y = ((double) -(**m_printData.m_macPrintInfo).rPaper.top ) * pt2mm;
+    m_minMarginTopLeft.x = ((double) -(**(THPrint)m_printData.m_macPrintInfo).rPaper.left ) * pt2mm;
+    m_minMarginTopLeft.y = ((double) -(**(THPrint)m_printData.m_macPrintInfo).rPaper.top ) * pt2mm;
 
-    m_minMarginBottomRight.x = ((double) (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).prInfo.rPage.right ) * pt2mm;
-    m_minMarginBottomRight.y = ((double)(**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).prInfo.rPage.bottom ) * pt2mm;
+    m_minMarginBottomRight.x = ((double) (**(THPrint)m_printData.m_macPrintInfo).rPaper.right - (**(THPrint)m_printData.m_macPrintInfo).prInfo.rPage.right ) * pt2mm;
+    m_minMarginBottomRight.y = ((double)(**(THPrint)m_printData.m_macPrintInfo).rPaper.bottom - (**(THPrint)m_printData.m_macPrintInfo).prInfo.rPage.bottom ) * pt2mm;
 #endif
     // adjust minimal values
     //TODO add custom fields in dialog for margins
diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp
index 996c2cf38b..f105941fdc 100644
--- a/src/common/dynlib.cpp
+++ b/src/common/dynlib.cpp
@@ -38,6 +38,10 @@
 #include "wx/intl.h"
 #include "wx/log.h"
 
+#if defined(__WXMAC__)
+    #include "wx/mac/private.h"
+#endif
+
 // ----------------------------------------------------------------------------
 // conditional compilation
 // ----------------------------------------------------------------------------
@@ -105,7 +109,7 @@ const char *dlerror(void);
 #   define wxDllGetSymbol(handle, name)    ::GetProcAddress(handle, name)
 #   define wxDllClose                      ::FreeLibrary
 #elif defined(__WXMAC__)
-#   define wxDllClose(handle)               CloseConnection(&handle)
+#   define wxDllClose(handle)               CloseConnection(&((CFragConnectionID)handle))
 #else
 #   error "Don't know how to load shared libraries on this platform."
 #endif // OS
@@ -242,7 +246,7 @@ wxDllType wxDllLoader::LoadLibrary(const wxString & libname, bool *success)
                          kCFragGoesToEOF,
                          "\p",
                          kPrivateCFragCopy,
-                         &handle,
+                         &((CFragConnectionID)handle),
                          &myMainAddr,
                          myErrName ) != noErr )
     {
@@ -310,7 +314,7 @@ void *wxDllLoader::GetSymbol(wxDllType dllHandle, const wxString &name, bool *su
     strcpy( (char *) symName, name );
     c2pstr( (char *) symName );
 #endif
-    if( FindSymbol( dllHandle, symName, &symAddress, &symClass ) == noErr )
+    if( FindSymbol( ((CFragConnectionID)dllHandle), symName, &symAddress, &symClass ) == noErr )
         symbol = (void *)symAddress;
 
 #elif defined(__WXPM__) || defined(__EMX__)
diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp
index a6107188c9..a90cad6a76 100644
--- a/src/common/fileconf.cpp
+++ b/src/common/fileconf.cpp
@@ -46,6 +46,10 @@
 
 #include  "wx/utils.h"    // for wxGetHomeDir
 
+#if defined(__WXMAC__)
+  #include  "wx/mac/private.h"  // includes mac headers
+#endif
+
 // _WINDOWS_ is defined when windows.h is included,
 // __WXMSW__ is defined for MS Windows compilation
 #if       defined(__WXMSW__) && !defined(_WINDOWS_)
diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp
index bbaac43d90..79c63f4bad 100644
--- a/src/common/filefn.cpp
+++ b/src/common/filefn.cpp
@@ -50,6 +50,10 @@
     #endif
 #endif
 
+#if defined(__WXMAC__)
+  #include  "wx/mac/private.h"  // includes mac headers
+#endif
+
 #include <time.h>
 
 #ifndef __MWERKS__
diff --git a/src/common/filename.cpp b/src/common/filename.cpp
index 97b896b2e3..5c2f9b007c 100644
--- a/src/common/filename.cpp
+++ b/src/common/filename.cpp
@@ -90,6 +90,10 @@
 #include "wx/msw/winundef.h"
 #endif
 
+#if defined(__WXMAC__)
+  #include  "wx/mac/private.h"  // includes mac headers
+#endif
+
 // utime() is POSIX so should normally be available on all Unices
 #ifdef __UNIX_LIKE__
 #include <sys/types.h>
diff --git a/src/common/intl.cpp b/src/common/intl.cpp
index 7d1b0d14cf..9c7a2e30b7 100644
--- a/src/common/intl.cpp
+++ b/src/common/intl.cpp
@@ -60,6 +60,10 @@
     #include "wx/fontmap.h"         // for CharsetToEncoding()
 #endif
 
+#if defined(__WXMAC__)
+  #include  "wx/mac/private.h"  // includes mac headers
+#endif
+
 // ----------------------------------------------------------------------------
 // simple types
 // ----------------------------------------------------------------------------
diff --git a/src/common/log.cpp b/src/common/log.cpp
index 3731fe3865..c9c4ab2776 100644
--- a/src/common/log.cpp
+++ b/src/common/log.cpp
@@ -60,6 +60,10 @@
   #include  "wx/msw/private.h"      // includes windows.h for OutputDebugString
 #endif
 
+#if defined(__WXMAC__)
+  #include  "wx/mac/private.h"  // includes mac headers
+#endif
+
 // ----------------------------------------------------------------------------
 // non member functions
 // ----------------------------------------------------------------------------
diff --git a/src/generic/dirctrlg.cpp b/src/generic/dirctrlg.cpp
index 3343b595fe..b9132708e1 100644
--- a/src/generic/dirctrlg.cpp
+++ b/src/generic/dirctrlg.cpp
@@ -47,6 +47,10 @@
 
 #include "wx/generic/dirctrlg.h"
 
+#if defined(__WXMAC__)
+  #include  "wx/mac/private.h"  // includes mac headers
+#endif
+
 #ifdef __WXMSW__
 #include <windows.h>
 
diff --git a/src/mac/aga.cpp b/src/mac/aga.cpp
index 66da32984c..4f4f139e87 100644
--- a/src/mac/aga.cpp
+++ b/src/mac/aga.cpp
@@ -1048,7 +1048,7 @@ pascal SInt32 AGABevelButtonDefProc (SInt16 procID, ControlHandle theControl, Co
 					return 0 ;
 					
 				{
-					AGAPortHelper help((**theControl).contrlOwner) ;
+					wxMacPortStateHelper help((**theControl).contrlOwner) ;
 					AGASetFontStyle( &info->fontStyle ) ;
 					Boolean mRadioBehavior = false ;
 					
@@ -1188,7 +1188,7 @@ pascal SInt32 AGAButtonDefProc (SInt16 procID, ControlHandle theControl, Control
 					return 0 ;
 					
 				{
-					AGAPortHelper help((**theControl).contrlOwner) ;
+					wxMacPortStateHelper help((**theControl).contrlOwner) ;
 					AGASetFontStyle( &info->fontStyle ) ;
 					Boolean mRadioBehavior = false ;
 					
@@ -1425,7 +1425,7 @@ pascal SInt32 AGACheckBoxDefProc (SInt16 procID, ControlHandle theControl, Contr
 						return 0 ;
 						
 					{
-						AGAPortHelper help((**theControl).contrlOwner) ;
+						wxMacPortStateHelper help((**theControl).contrlOwner) ;
 						Rect frame =  (**theControl).contrlRect ;
 						Boolean hasColor = true;
 						Boolean disabled = (*theControl)->contrlHilite == 255 ;
@@ -1621,7 +1621,7 @@ pascal SInt32 AGARadioButtonDefProc (SInt16 procID, ControlHandle theControl, Co
 						return 0 ;
 						
 					{
-						AGAPortHelper help() ;
+						wxMacPortStateHelper help() ;
 						Rect frame =  (**theControl).contrlRect ;
 						Boolean hasColor = true;
 						Boolean disabled = (*theControl)->contrlHilite == 255 ;
@@ -1813,7 +1813,7 @@ pascal SInt32 AGAStaticGroupBoxTextDefProc (SInt16 procID, ControlHandle theCont
 				{
 					bool disabled = false ;
 					bool hasColor = true ;
-					AGAPortHelper help((**theControl).contrlOwner) ;
+					wxMacPortStateHelper help((**theControl).contrlOwner) ;
 					AGASetFontStyle( &info->fontStyle ) ;
 					FontInfo fi ;
 					::GetFontInfo( &fi ) ;
@@ -1899,7 +1899,7 @@ pascal SInt32 AGAStaticTextDefProc (SInt16 procID, ControlHandle theControl, Con
 					return 0 ;
 					
 				{
-					AGAPortHelper help((**theControl).contrlOwner) ;
+					wxMacPortStateHelper help((**theControl).contrlOwner) ;
 					AGASetFontStyle( &info->fontStyle ) ;
 					int x =	(**theControl).contrlRect.left ;
 					int y =	(**theControl).contrlRect.top ;
@@ -2094,7 +2094,7 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr
 	{
 		case initCntl :
 			{
-				AGAPortHelper help((**theControl).contrlOwner) ;
+				wxMacPortStateHelper help((**theControl).contrlOwner) ;
 				SetPort( (**theControl).contrlOwner ) ;
 				::TextFont( kFontIDGeneva ) ; 
 				::TextSize( 10 ) ;
@@ -2116,7 +2116,7 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr
 			break ;
 		case drawCntl :
 			{
-				AGAPortHelper help((**theControl).contrlOwner) ;
+				wxMacPortStateHelper help((**theControl).contrlOwner) ;
 				AGASetFontStyle( &info->fontStyle ) ;
 				SetPort( (**theControl).contrlOwner ) ;
 				RGBBackColor( &gAGARamp[ kAGAWhite ] ) ;
@@ -2223,7 +2223,7 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr
 			break ;
 		case kControlMsgKeyDown :
 			{
-				AGAPortHelper help( (**theControl).contrlOwner ) ;
+				wxMacPortStateHelper help( (**theControl).contrlOwner ) ;
 				AGASetFontStyle( &info->fontStyle ) ;
 				RGBBackColor( &gAGARamp[ kAGAWhite ] ) ;
 				RGBForeColor( &gAGARamp[ kAGABlack ] ) ;
@@ -2332,7 +2332,7 @@ pascal SInt32 AGAListControlDefProc (SInt16 procID, ControlHandle theControl, Co
 			break ;
 		case drawCntl :
 			{
-				AGAPortHelper help((**theControl).contrlOwner) ;
+				wxMacPortStateHelper help((**theControl).contrlOwner) ;
 				AGASetFontStyle( &info->fontStyle ) ;
 				RGBBackColor( &gAGARamp[ kAGAWhite ] ) ;
 				EraseRect( &(**theControl).contrlRect ) ;
@@ -2560,52 +2560,4 @@ void AGAApplyThemeBackground(ThemeBackgroundKind 	inKind,
 // status in a theme savvy manner, pen mode, patterns and fonts
 // attributes
 
-AGAPortHelper::AGAPortHelper( GrafPtr newport) 
-{
-  m_clip = NULL ;
-  Setup( newport ) ;
-}
-AGAPortHelper::AGAPortHelper()
-{
-	m_clip = NULL ;
-}
-
-void AGAPortHelper::Setup( GrafPtr newport )
-{
-	GetPort( &m_oldPort ) ;
-	SetPort( newport ) ;
-	wxASSERT_MSG( m_clip == NULL , "Cannot call setup twice" ) ;
-	m_clip = NewRgn() ;
-	GetClip( m_clip );
-	m_textFont = GetPortTextFont( newport);
-	m_textSize = GetPortTextSize( newport);
-	m_textStyle = GetPortTextFace( newport);
-	m_textMode = GetPortTextMode( newport);	
-	GetThemeDrawingState( &m_drawingState ) ;
-	m_currentPort = newport ;
-}
-void AGAPortHelper::Clear()
-{
-	if ( m_clip )
-	{
-		DisposeRgn( m_clip ) ;
-		DisposeThemeDrawingState( m_drawingState ) ;
-		m_clip = NULL ;
-	}
-}
-AGAPortHelper::~AGAPortHelper()
-{
-	if ( m_clip )
-	{
-		SetPort( m_currentPort ) ;
-		SetClip( m_clip ) ;
-		DisposeRgn( m_clip ) ;
-		TextFont( m_textFont );
-		TextSize( m_textSize );
-		TextFace( m_textStyle );
-		TextMode( m_textMode );
-		SetThemeDrawingState( m_drawingState , true ) ;
-		SetPort( m_oldPort ) ;
-	}
-}
 
diff --git a/src/mac/app.cpp b/src/mac/app.cpp
index 1a02ff2e58..b16dcd492a 100644
--- a/src/mac/app.cpp
+++ b/src/mac/app.cpp
@@ -85,7 +85,7 @@ const short    kMacMinHeap = (29 * 1024) ;
 const short kwxMacMenuBarResource = 1 ;
 const short kwxMacAppleMenuId = 1 ;
 
-RgnHandle            wxApp::s_macCursorRgn = NULL;
+WXHRGN            wxApp::s_macCursorRgn = NULL;
 wxWindow*            wxApp::s_captureWindow = NULL ;
 int                    wxApp::s_lastMouseDown = 0 ;
 long                     wxApp::sm_lastMessageTime = 0;
@@ -125,7 +125,7 @@ pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long re
     return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
 }
 
-OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEODoc(const WXEVENTREF event , WXEVENTREF reply)
 {
     SysBeep(40) ;
     ProcessSerialNumber PSN ;
@@ -135,17 +135,17 @@ OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply)
     return noErr ;
 }
 
-OSErr wxApp::MacHandleAEPDoc(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF reply)
 {
     return noErr ;
 }
 
-OSErr wxApp::MacHandleAEOApp(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEOApp(const WXEVENTREF event , WXEVENTREF reply)
 {
     return noErr ;
 }
 
-OSErr wxApp::MacHandleAEQuit(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEQuit(const WXEVENTREF event , WXEVENTREF reply)
 {
     wxWindow* win = GetTopWindow() ;
     if ( win )
@@ -603,7 +603,7 @@ void wxApp::CleanUp()
 
     UMACleanupToolbox() ;
     if (s_macCursorRgn)
-        ::DisposeRgn(s_macCursorRgn);
+        ::DisposeRgn((RgnHandle)s_macCursorRgn);
 
     #if 0
         TerminateAE() ;
@@ -958,11 +958,11 @@ bool wxApp::Yield(bool onlyIfNeeded)
 
     long sleepTime = 1 ; //::GetCaretTime();
 
-    while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, wxApp::s_macCursorRgn))
+    while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn))
     {
         wxTheApp->MacHandleOneEvent( &event );
         if ( event.what != kHighLevelEvent )
-            SetRectRgn( wxApp::s_macCursorRgn , event.where.h , event.where.v ,  event.where.h + 1 , event.where.v + 1 ) ;
+            SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v ,  event.where.h + 1 , event.where.v + 1 ) ;
     }
 
     wxMacProcessNotifierAndPendingEvents() ;
@@ -1021,7 +1021,7 @@ void wxApp::MacDoOneEvent()
 
     long sleepTime = 1; // GetCaretTime() / 4 ;
 
-    if (WaitNextEvent(everyEvent, &event, sleepTime, s_macCursorRgn))
+    if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn))
     {
         MacHandleOneEvent( &event );
     }
@@ -1035,7 +1035,7 @@ void wxApp::MacDoOneEvent()
         wxTheApp->ProcessIdle() ;
     }
     if ( event.what != kHighLevelEvent )
-        SetRectRgn( s_macCursorRgn , event.where.h , event.where.v ,  event.where.h + 1 , event.where.v + 1 ) ;
+        SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v ,  event.where.h + 1 , event.where.v + 1 ) ;
 
     // repeaters
 
@@ -1043,8 +1043,9 @@ void wxApp::MacDoOneEvent()
     wxMacProcessNotifierAndPendingEvents() ;
 }
 
-void wxApp::MacHandleOneEvent( EventRecord *ev )
+void wxApp::MacHandleOneEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     m_macCurrentEvent = ev ;
 
     wxApp::sm_lastMessageTime = ev->when ;
@@ -1098,15 +1099,17 @@ void wxApp::MacHandleOneEvent( EventRecord *ev )
     wxMacProcessNotifierAndPendingEvents() ;
 }
 
-void wxApp::MacHandleHighLevelEvent( EventRecord *ev )
+void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     ::AEProcessAppleEvent( ev ) ;
 }
 
 bool s_macIsInModalLoop = false ;
 
-void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
+void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     wxToolTip::RemoveToolTips() ;
 
     WindowRef window;
@@ -1156,11 +1159,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                     GrafPtr port ;
                     GetPort( &port ) ;
                     Point pt = { 0, 0 } ;
-                    #if TARGET_CARBON
                     SetPort( GetWindowPort(window) ) ;
-                    #else
-                    SetPort( (window) ) ;
-                    #endif
                     LocalToGlobal( &pt ) ;
                     SetPort( port ) ;
                         win->SetSize( pt.h , pt.v , -1 ,
@@ -1226,11 +1225,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                 {
                     GrafPtr port ;
                     GetPort( &port ) ;
-                    #if TARGET_CARBON
                     SetPort( GetWindowPort(window) ) ;
-                    #else
-                    SetPort( (window) ) ;
-                    #endif
                     SetPort( port ) ;
                 }
                 if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
@@ -1263,8 +1258,9 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleMouseUpEvent( EventRecord *ev )
+void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     WindowRef window;
 
     short windowPart = ::FindWindow(ev->where, &window);
@@ -1394,8 +1390,9 @@ long wxMacTranslateKey(unsigned char key, unsigned char code)
     return retval;
 }
 
-void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
+void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     wxToolTip::RemoveToolTips() ;
 
     UInt32 menuresult = UMAMenuEvent(ev) ;
@@ -1511,8 +1508,9 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleKeyUpEvent( EventRecord *ev )
+void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     wxToolTip::RemoveToolTips() ;
 
     UInt32 menuresult = UMAMenuEvent(ev) ;
@@ -1546,8 +1544,9 @@ void wxApp::MacHandleKeyUpEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleActivateEvent( EventRecord *ev )
+void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     WindowRef window = (WindowRef) ev->message ;
     if ( window )
     {
@@ -1565,8 +1564,9 @@ void wxApp::MacHandleActivateEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleUpdateEvent( EventRecord *ev )
+void wxApp::MacHandleUpdateEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     WindowRef window = (WindowRef) ev->message ;
     wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ;
     if ( win )
@@ -1584,8 +1584,9 @@ void wxApp::MacHandleUpdateEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleDiskEvent( EventRecord *ev )
+void wxApp::MacHandleDiskEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     if ( HiWord( ev->message ) != noErr )
   {
  #if !TARGET_CARBON
@@ -1599,8 +1600,9 @@ void wxApp::MacHandleDiskEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleOSEvent( EventRecord *ev )
+void wxApp::MacHandleOSEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     switch( ( ev->message & osEvtMessageMask ) >> 24 )
     {
         case suspendResumeMessage :
diff --git a/src/mac/bitmap.cpp b/src/mac/bitmap.cpp
index ba9371a821..ec5d91854e 100644
--- a/src/mac/bitmap.cpp
+++ b/src/mac/bitmap.cpp
@@ -313,7 +313,7 @@ static void DisposeBitmapRefData(wxBitmapRefData *data)
             {
                 if ( data->m_hPict )
                 {
-                    KillPicture( data->m_hPict ) ;
+                    KillPicture( MAC_WXHMETAFILE( data->m_hPict ) ) ;
                     data->m_hPict = NULL ;
                 }
             }
@@ -322,7 +322,7 @@ static void DisposeBitmapRefData(wxBitmapRefData *data)
             {
                 if ( data->m_hBitmap )
                 {
-                    wxMacDestroyGWorld( data->m_hBitmap ) ;
+                    wxMacDestroyGWorld( MAC_WXHBITMAP(data->m_hBitmap) ) ;
                     data->m_hBitmap = NULL ;
                 }
             }
@@ -330,7 +330,7 @@ static void DisposeBitmapRefData(wxBitmapRefData *data)
         case kMacBitmapTypeIcon :
             if ( data->m_hIcon )
             {
-                DisposeCIcon( data->m_hIcon ) ;
+                DisposeCIcon( MAC_WXHICON(data->m_hIcon) ) ;
                 data->m_hIcon = NULL ;
             }
         
@@ -377,15 +377,15 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
     if ( no_bits == 1 )
     {
         M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
-        M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( the_width , the_height , no_bits ) ;
-        M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
+        MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) = wxMacCreateGWorld( the_width , the_height , no_bits ) ;
+        M_BITMAPDATA->m_ok = (MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) != NULL ) ;
     
         CGrafPtr    origPort ;
         GDHandle    origDevice ;
     
         GetGWorld( &origPort , &origDevice ) ;
-        SetGWorld( M_BITMAPDATA->m_hBitmap , NULL ) ;
-        LockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
+        SetGWorld( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) , NULL ) ;
+        LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) ) ) ;
     
         // bits is a char array
     
@@ -417,7 +417,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
                 }
             }
         }
-        UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
+        UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) ) ) ;
     
         SetGWorld( origPort , origDevice ) ;
     }
@@ -474,7 +474,7 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
    wxBitmap ret( rect.width, rect.height, GetDepth() );
    wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
 
-   WXHBITMAP origPort;
+   GWorldPtr origPort;
    GDHandle  origDevice;
 
    GetGWorld( &origPort, &origDevice );
@@ -496,10 +496,10 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
        // Copy mask
        if(GetMask())
        {
-           WXHBITMAP submask, mask;
+           GWorldPtr submask, mask;
            RGBColor  color;
 
-           mask = GetMask()->GetMaskBitmap();
+           mask = (GWorldPtr) GetMask()->GetMaskBitmap();
            submask = wxMacCreateGWorld(rect.width, rect.height, 1);
            LockPixels(GetGWorldPixMap(mask));
            LockPixels(GetGWorldPixMap(submask));
@@ -523,11 +523,11 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
        // Copy bitmap
        if(GetHBITMAP())
        {
-           WXHBITMAP subbitmap, bitmap;
+           GWorldPtr subbitmap, bitmap;
            RGBColor  color;
 
-           bitmap = GetHBITMAP();
-           subbitmap = ref->m_hBitmap ;
+           bitmap = (GWorldPtr) GetHBITMAP();
+           subbitmap = (GWorldPtr) ref->m_hBitmap ;
            LockPixels(GetGWorldPixMap(bitmap));
            LockPixels(GetGWorldPixMap(subbitmap));
 
@@ -562,7 +562,7 @@ bool wxBitmap::Create(int w, int h, int d)
 
     M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
     M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( w , h , d ) ;
-    M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
+    M_BITMAPDATA->m_ok = ( M_BITMAPDATA->m_hBitmap != NULL ) ;
     return M_BITMAPDATA->m_ok;
 }
 
@@ -579,7 +579,7 @@ void wxBitmap::SetHBITMAP(WXHBITMAP bmp)
     
     M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
     M_BITMAPDATA->m_hBitmap = bmp ;
-      M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
+      M_BITMAPDATA->m_ok = ( M_BITMAPDATA->m_hBitmap != NULL ) ;
 }
 
 bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
@@ -641,11 +641,11 @@ wxBitmap::wxBitmap(const wxImage& image, int depth)
     CGrafPtr origPort ;
     GDHandle origDevice ;
 
-    PixMapHandle pixMap = GetGWorldPixMap(GetHBITMAP()) ;
+    PixMapHandle pixMap = GetGWorldPixMap((GWorldPtr)GetHBITMAP()) ;
     LockPixels( pixMap );
 
     GetGWorld( &origPort , &origDevice ) ;
-    SetGWorld( GetHBITMAP() , NULL ) ;
+    SetGWorld( (GWorldPtr) GetHBITMAP() , NULL ) ;
     
     // Render image
     RGBColor colorRGB ;
@@ -675,8 +675,8 @@ wxBitmap::wxBitmap(const wxImage& image, int depth)
       wxBitmap maskBitmap ;
 
       maskBitmap.Create( width, height, 1);
-      LockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) );
-      SetGWorld(maskBitmap.GetHBITMAP(), NULL);
+      LockPixels( GetGWorldPixMap( (GWorldPtr) maskBitmap.GetHBITMAP()) );
+      SetGWorld( (GWorldPtr) maskBitmap.GetHBITMAP(), NULL);
 
       for (int y = 0; y < height; y++)
       {
@@ -692,12 +692,12 @@ wxBitmap::wxBitmap(const wxImage& image, int depth)
               data += 3 ;
           }
       }  // for height
-      SetGWorld(GetHBITMAP(), NULL);
+      SetGWorld( (GWorldPtr) GetHBITMAP(), NULL);
       SetMask(new wxMask( maskBitmap ));
-      UnlockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) );
+      UnlockPixels( GetGWorldPixMap( (GWorldPtr) maskBitmap.GetHBITMAP()) );
     }
     
-    UnlockPixels( GetGWorldPixMap(GetHBITMAP()) );
+    UnlockPixels( GetGWorldPixMap( (GWorldPtr) GetHBITMAP()) );
     SetGWorld( origPort, origDevice );
 }
 
@@ -716,7 +716,7 @@ wxImage wxBitmap::ConvertToImage() const
 
     wxCHECK_MSG( data, wxNullImage, wxT("Could not allocate data for image") );
 
-    WXHBITMAP origPort;
+    GWorldPtr origPort;
     GDHandle  origDevice;
     int      index;
     RGBColor color;
@@ -726,8 +726,8 @@ wxImage wxBitmap::ConvertToImage() const
     wxMask  *mask = GetMask();
 
     GetGWorld( &origPort, &origDevice );
-    LockPixels(GetGWorldPixMap(GetHBITMAP()));
-    SetGWorld( GetHBITMAP(), NULL);
+    LockPixels(GetGWorldPixMap( (GWorldPtr) GetHBITMAP()));
+    SetGWorld(  (GWorldPtr) GetHBITMAP(), NULL);
 
     // Copy data into image
     index = 0;
@@ -761,7 +761,7 @@ wxImage wxBitmap::ConvertToImage() const
     }
 
     // Free resources
-    UnlockPixels(GetGWorldPixMap(GetHBITMAP()));
+    UnlockPixels(GetGWorldPixMap( (GWorldPtr) GetHBITMAP()));
     SetGWorld(origPort, origDevice);
 
     return image;
@@ -899,10 +899,10 @@ WXHBITMAP wxBitmap::GetHBITMAP() const
 {
    wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
 
-   return M_BITMAPDATA->m_hBitmap;
+   return MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap);
 }
 
-PicHandle wxBitmap::GetPict() const
+WXHMETAFILE wxBitmap::GetPict() const
 {
    wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
    
@@ -925,16 +925,16 @@ PicHandle wxBitmap::GetPict() const
    wxMask   *mask;
    Rect      portRect ;
 
-   GetPortBounds( GetHBITMAP() , &portRect ) ;
+   GetPortBounds(  (GWorldPtr) GetHBITMAP() , &portRect ) ;
    int width = portRect.right - portRect.left ;
    int height = portRect.bottom - portRect.top ;
 
-   LockPixels( GetGWorldPixMap( GetHBITMAP() ) ) ;
+   LockPixels( GetGWorldPixMap(  (GWorldPtr) GetHBITMAP() ) ) ;
    GetGWorld( &origPort , &origDev ) ;
 
    mask = GetMask();
 
-   SetGWorld( GetHBITMAP() , NULL ) ;
+   SetGWorld(  (GWorldPtr) GetHBITMAP() , NULL ) ;
 
    picture = OpenPicture(&portRect);   // open a picture, this disables drawing
    if(!picture) {
@@ -979,16 +979,16 @@ PicHandle wxBitmap::GetPict() const
        RGBForeColor( &black ) ;
        RGBBackColor( &white ) ;
 
-       CopyBits(GetPortBitMapForCopyBits(GetHBITMAP()), 
+       CopyBits(GetPortBitMapForCopyBits( (GWorldPtr) GetHBITMAP()), 
                 // src PixMap - we copy image over itself -
-                GetPortBitMapForCopyBits(GetHBITMAP()),
+                GetPortBitMapForCopyBits( (GWorldPtr) GetHBITMAP()),
                 //  dst PixMap - no drawing occurs
                 &portRect,    // srcRect - it will be recorded and compressed -
                 &portRect,    // dstRect - into the picture that is open -
                 srcCopy,NULL); // copyMode and no clip region
    }
    ClosePicture();                  // We are done recording the picture
-   UnlockPixels( GetGWorldPixMap( GetHBITMAP() ) ) ;
+   UnlockPixels( GetGWorldPixMap(  (GWorldPtr) GetHBITMAP() ) ) ;
    SetGWorld( origPort , origDev ) ;
 
    return picture;                  // return our groovy pict handle
@@ -1030,7 +1030,7 @@ wxMask::~wxMask()
 {
     if ( m_maskBitmap )
     {
-        wxMacDestroyGWorld( m_maskBitmap ) ;
+        wxMacDestroyGWorld(  (GWorldPtr) m_maskBitmap ) ;
         m_maskBitmap = NULL ;
     }
 }
@@ -1040,7 +1040,7 @@ bool wxMask::Create(const wxBitmap& bitmap)
 {
    if ( m_maskBitmap )
    {
-       wxMacDestroyGWorld( m_maskBitmap ) ;
+       wxMacDestroyGWorld(  (GWorldPtr) m_maskBitmap ) ;
        m_maskBitmap = NULL ;
    }
    wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false,
@@ -1055,13 +1055,13 @@ bool wxMask::Create(const wxBitmap& bitmap)
    m_maskBitmap = wxMacCreateGWorld(bitmap.GetWidth(), bitmap.GetHeight(), 1);
    Rect rect = { 0,0, bitmap.GetHeight(), bitmap.GetWidth() };
 
-   LockPixels( GetGWorldPixMap(m_maskBitmap) );
-   LockPixels( GetGWorldPixMap(bitmap.GetHBITMAP()) );
-   CopyBits(GetPortBitMapForCopyBits(bitmap.GetHBITMAP()),
-            GetPortBitMapForCopyBits(m_maskBitmap),
+   LockPixels( GetGWorldPixMap( (GWorldPtr) m_maskBitmap) );
+   LockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP()) );
+   CopyBits(GetPortBitMapForCopyBits( (GWorldPtr) bitmap.GetHBITMAP()),
+            GetPortBitMapForCopyBits( (GWorldPtr) m_maskBitmap),
             &rect, &rect, srcCopy, 0);
-   UnlockPixels( GetGWorldPixMap(m_maskBitmap) );
-   UnlockPixels( GetGWorldPixMap(bitmap.GetHBITMAP()) );
+   UnlockPixels( GetGWorldPixMap( (GWorldPtr) m_maskBitmap) );
+   UnlockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP()) );
 
    return FALSE;
 }
@@ -1081,7 +1081,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
 {
     if ( m_maskBitmap )
     {
-        wxMacDestroyGWorld( m_maskBitmap ) ;
+        wxMacDestroyGWorld(  (GWorldPtr) m_maskBitmap ) ;
         m_maskBitmap = NULL ;
     }
     wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false,
@@ -1091,9 +1091,9 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
     wxCHECK_MSG( bitmap.Ok(), false, wxT("Illigal bitmap"));
 
     m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 ); 
-    LockPixels( GetGWorldPixMap( m_maskBitmap ) );
-    LockPixels( GetGWorldPixMap( bitmap.GetHBITMAP() ) );
-    RGBColor maskColor = colour.GetPixel();
+    LockPixels( GetGWorldPixMap(  (GWorldPtr) m_maskBitmap ) );
+    LockPixels( GetGWorldPixMap(  (GWorldPtr) bitmap.GetHBITMAP() ) );
+    RGBColor maskColor = MAC_WXCOLORREF(colour.GetPixel());
 
     // this is not very efficient, but I can't think
     // of a better way of doing it
@@ -1109,9 +1109,9 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
     {
         for (int h = 0; h < bitmap.GetHeight(); h++)
         {       
-            SetGWorld( bitmap.GetHBITMAP(), NULL ) ;
+            SetGWorld(  (GWorldPtr) bitmap.GetHBITMAP(), NULL ) ;
             GetCPixel( w , h , &col ) ;
-            SetGWorld( m_maskBitmap , NULL ) ;
+            SetGWorld(  (GWorldPtr) m_maskBitmap , NULL ) ;
             if (col.red == maskColor.red && col.green == maskColor.green && col.blue == maskColor.blue)
             {
                 SetCPixel( w , h , &colors[0] ) ;
@@ -1123,7 +1123,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
         }
     }
     UnlockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ;
-    UnlockPixels( GetGWorldPixMap( bitmap.GetHBITMAP() ) ) ;
+    UnlockPixels( GetGWorldPixMap(  (GWorldPtr) bitmap.GetHBITMAP() ) ) ;
     SetGWorld( origPort , origDevice ) ;
 
     return TRUE;
@@ -1131,7 +1131,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
 
 bool wxMask::PointMasked(int x, int y)
 {
-   WXHBITMAP origPort;
+   GWorldPtr origPort;
    GDHandle  origDevice;
    RGBColor  color;
    bool masked = true;
@@ -1139,11 +1139,11 @@ bool wxMask::PointMasked(int x, int y)
    GetGWorld( &origPort, &origDevice);
 
    //Set port to mask and see if it masked (1) or not ( 0 )
-   SetGWorld(m_maskBitmap, NULL);
-   LockPixels(GetGWorldPixMap(m_maskBitmap));
+   SetGWorld( (GWorldPtr) m_maskBitmap, NULL);
+   LockPixels(GetGWorldPixMap( (GWorldPtr) m_maskBitmap));
    GetCPixel(x,y, &color);
    masked = !(color.red == 0 && color.green == 0 && color.blue == 0);
-   UnlockPixels(GetGWorldPixMap(m_maskBitmap));
+   UnlockPixels(GetGWorldPixMap( (GWorldPtr) m_maskBitmap));
 
    SetGWorld( origPort, origDevice);
 
diff --git a/src/mac/bmpbuttn.cpp b/src/mac/bmpbuttn.cpp
index 2a93999107..ed8ee2a469 100644
--- a/src/mac/bmpbuttn.cpp
+++ b/src/mac/bmpbuttn.cpp
@@ -57,11 +57,11 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
 	
 	MacPreControlCreate( parent , id ,  "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 
 		kControlBehaviorOffsetContents + 
 		    ( bmap->m_bitmapType == kMacBitmapTypeIcon ? kControlContentCIconHandle : kControlContentPictHandle ) , 0, 
 	  	(( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
-	wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+	wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
 	
 	ControlButtonContentInfo info ;
 	
@@ -70,31 +70,31 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
 	{
 		if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
 	    info.contentType = kControlContentPictHandle ;
-			info.u.picture = bmap->m_hPict ;
+			info.u.picture = MAC_WXHMETAFILE( bmap->m_hPict ) ;
 		}
 		else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
 		{
 			if ( m_buttonBitmap.GetMask() )
 			{
 		    info.contentType = kControlContentCIconHandle ;
-				info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ,
+				info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP( bmap->m_hBitmap ) , MAC_WXHBITMAP(m_buttonBitmap.GetMask()->GetMaskBitmap()) ,
 				    8 , 16 ) ;
 			}
 			else
 			{
 		    info.contentType = kControlContentCIconHandle ;
-				info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , NULL ,
+				info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP( bmap->m_hBitmap ) , NULL ,
 				    8 , 16 ) ;
 			}
 		}
 		else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
 		{
 	        info.contentType = kControlContentCIconHandle ;
-	        info.u.cIconHandle = bmap->m_hIcon ;
+	        info.u.cIconHandle = MAC_WXHICON(bmap->m_hIcon) ;
 		}
 	}
 	
-	::SetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
+	::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
 
 	MacPostControlCreate() ;
 
@@ -111,31 +111,31 @@ void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
 		wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
 		if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
 	    info.contentType = kControlContentPictHandle ;
-			info.u.picture = bmap->m_hPict ;
+			info.u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
 		}
 		else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
 		{
 			if ( m_buttonBitmap.GetMask() )
 			{
 		    info.contentType = kControlContentCIconHandle ;
-				info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ,
+				info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(m_buttonBitmap.GetMask()->GetMaskBitmap()) ,
 				    8 , 16 ) ;
 			}
 			else
 			{
 		    info.contentType = kControlContentCIconHandle ;
-				info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , NULL ,
+				info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
 				    8 , 16 ) ;
 			}
 		}
 		else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
 		{
 	        info.contentType = kControlContentCIconHandle ;
-	        info.u.cIconHandle = bmap->m_hIcon ;
+	        info.u.cIconHandle = MAC_WXHICON( bmap->m_hIcon ) ;
 		}
 
 		
-	    ::SetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
+	    ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
     }
 }
 
diff --git a/src/mac/brush.cpp b/src/mac/brush.cpp
index 5c87256763..f38b3782d9 100644
--- a/src/mac/brush.cpp
+++ b/src/mac/brush.cpp
@@ -17,10 +17,34 @@
 #include "wx/utils.h"
 #include "wx/brush.h"
 
+#include "wx/mac/private.h"
+
 #if !USE_SHARED_LIBRARIES
 IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
 #endif
 
+class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
+{
+    friend class WXDLLEXPORT wxBrush;
+public:
+    wxBrushRefData();
+    wxBrushRefData(const wxBrushRefData& data);
+    ~wxBrushRefData();
+
+protected:
+    wxMacBrushKind m_macBrushKind ;
+    int           m_style;
+    wxBitmap      m_stipple ;
+    wxColour      m_colour;
+    
+    ThemeBrush    m_macThemeBrush ;
+    
+    ThemeBackgroundKind m_macThemeBackground ;
+    Rect         m_macThemeBackgroundExtent ;
+};
+
+#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
+
 wxBrushRefData::wxBrushRefData()
 {
     m_style = wxSOLID;
@@ -149,13 +173,13 @@ void wxBrush::SetMacTheme(ThemeBrush macThemeBrush)
     RealizeResource();
 }
 
-void wxBrush::SetMacThemeBackground(ThemeBackgroundKind macThemeBackground, const Rect &extent)
+void wxBrush::SetMacThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent)
 {
     Unshare();
 
     M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground;
     M_BRUSHDATA->m_macThemeBackground = macThemeBackground;
-    M_BRUSHDATA->m_macThemeBackgroundExtent = extent ;
+    M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent ;
     RealizeResource();
 }
 
@@ -164,12 +188,12 @@ bool wxBrush::RealizeResource()
     return TRUE;
 }
 
-ThemeBackgroundKind wxBrush::GetMacThemeBackground(Rect *extent)  const 
+unsigned long wxBrush::GetMacThemeBackground( WXRECTPTR extent)  const 
 {
   if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground )
   {
     if ( extent )
-      *extent = M_BRUSHDATA->m_macThemeBackgroundExtent ;
+      *(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent ;
     return M_BRUSHDATA->m_macThemeBackground ;
   }
   else
@@ -178,3 +202,25 @@ ThemeBackgroundKind wxBrush::GetMacThemeBackground(Rect *extent)  const
   }
 }
 
+short wxBrush::GetMacTheme()  const 
+{ 
+  return (M_BRUSHDATA ? ( M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack); 
+};
+
+wxColour& wxBrush::GetColour() const 
+{ return (M_BRUSHDATA ? M_BRUSHDATA->m_colour : wxNullColour); };
+
+int wxBrush::GetStyle() const 
+{ 
+  return (M_BRUSHDATA ? M_BRUSHDATA->m_style : 0); 
+};
+
+wxBitmap *wxBrush::GetStipple() const 
+{ 
+  return (M_BRUSHDATA ? & M_BRUSHDATA->m_stipple : 0); 
+};
+
+wxMacBrushKind wxBrush::MacGetBrushKind()  const 
+{ 
+  return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour); 
+};
diff --git a/src/mac/button.cpp b/src/mac/button.cpp
index 072ba01720..cbc1d846d9 100644
--- a/src/mac/button.cpp
+++ b/src/mac/button.cpp
@@ -37,9 +37,9 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
 	
 	MacPreControlCreate( parent , id ,  label , pos , size ,style, validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlPushButtonProc , (long) this ) ;
-	wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+	wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
 	
 	MacPostControlCreate() ;
 
@@ -61,13 +61,13 @@ void wxButton::SetDefault()
 	if ( btnOldDefault && btnOldDefault->m_macControl )
 	{
   		inData = 0;
-		::SetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
+		::SetControlData( (ControlHandle) btnOldDefault->m_macControl , kControlButtonPart ,
 						   kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
 	}
-	if ( m_macControl )
+	if ( (ControlHandle) m_macControl )
 	{
   		inData = 1;
-		::SetControlData( m_macControl , kControlButtonPart ,
+		::SetControlData(  (ControlHandle) m_macControl , kControlButtonPart ,
 						   kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
 	}
 }
@@ -95,17 +95,17 @@ wxSize wxButton::GetDefaultSize()
 
 void wxButton::Command (wxCommandEvent & event)
 {
-	if ( m_macControl )
+	if ( (ControlHandle) m_macControl )
 	{
-		HiliteControl( m_macControl , kControlButtonPart ) ;
+		HiliteControl(  (ControlHandle) m_macControl , kControlButtonPart ) ;
 		unsigned long finalTicks ;
 		Delay( 8 , &finalTicks ) ;
-		HiliteControl( m_macControl , 0 ) ;
+		HiliteControl(  (ControlHandle) m_macControl , 0 ) ;
 	}
     ProcessCommand (event);
 }
 
-void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
   if ( controlpart != kControlNoPart )
   {
diff --git a/src/mac/carbon/aga.cpp b/src/mac/carbon/aga.cpp
index 66da32984c..4f4f139e87 100644
--- a/src/mac/carbon/aga.cpp
+++ b/src/mac/carbon/aga.cpp
@@ -1048,7 +1048,7 @@ pascal SInt32 AGABevelButtonDefProc (SInt16 procID, ControlHandle theControl, Co
 					return 0 ;
 					
 				{
-					AGAPortHelper help((**theControl).contrlOwner) ;
+					wxMacPortStateHelper help((**theControl).contrlOwner) ;
 					AGASetFontStyle( &info->fontStyle ) ;
 					Boolean mRadioBehavior = false ;
 					
@@ -1188,7 +1188,7 @@ pascal SInt32 AGAButtonDefProc (SInt16 procID, ControlHandle theControl, Control
 					return 0 ;
 					
 				{
-					AGAPortHelper help((**theControl).contrlOwner) ;
+					wxMacPortStateHelper help((**theControl).contrlOwner) ;
 					AGASetFontStyle( &info->fontStyle ) ;
 					Boolean mRadioBehavior = false ;
 					
@@ -1425,7 +1425,7 @@ pascal SInt32 AGACheckBoxDefProc (SInt16 procID, ControlHandle theControl, Contr
 						return 0 ;
 						
 					{
-						AGAPortHelper help((**theControl).contrlOwner) ;
+						wxMacPortStateHelper help((**theControl).contrlOwner) ;
 						Rect frame =  (**theControl).contrlRect ;
 						Boolean hasColor = true;
 						Boolean disabled = (*theControl)->contrlHilite == 255 ;
@@ -1621,7 +1621,7 @@ pascal SInt32 AGARadioButtonDefProc (SInt16 procID, ControlHandle theControl, Co
 						return 0 ;
 						
 					{
-						AGAPortHelper help() ;
+						wxMacPortStateHelper help() ;
 						Rect frame =  (**theControl).contrlRect ;
 						Boolean hasColor = true;
 						Boolean disabled = (*theControl)->contrlHilite == 255 ;
@@ -1813,7 +1813,7 @@ pascal SInt32 AGAStaticGroupBoxTextDefProc (SInt16 procID, ControlHandle theCont
 				{
 					bool disabled = false ;
 					bool hasColor = true ;
-					AGAPortHelper help((**theControl).contrlOwner) ;
+					wxMacPortStateHelper help((**theControl).contrlOwner) ;
 					AGASetFontStyle( &info->fontStyle ) ;
 					FontInfo fi ;
 					::GetFontInfo( &fi ) ;
@@ -1899,7 +1899,7 @@ pascal SInt32 AGAStaticTextDefProc (SInt16 procID, ControlHandle theControl, Con
 					return 0 ;
 					
 				{
-					AGAPortHelper help((**theControl).contrlOwner) ;
+					wxMacPortStateHelper help((**theControl).contrlOwner) ;
 					AGASetFontStyle( &info->fontStyle ) ;
 					int x =	(**theControl).contrlRect.left ;
 					int y =	(**theControl).contrlRect.top ;
@@ -2094,7 +2094,7 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr
 	{
 		case initCntl :
 			{
-				AGAPortHelper help((**theControl).contrlOwner) ;
+				wxMacPortStateHelper help((**theControl).contrlOwner) ;
 				SetPort( (**theControl).contrlOwner ) ;
 				::TextFont( kFontIDGeneva ) ; 
 				::TextSize( 10 ) ;
@@ -2116,7 +2116,7 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr
 			break ;
 		case drawCntl :
 			{
-				AGAPortHelper help((**theControl).contrlOwner) ;
+				wxMacPortStateHelper help((**theControl).contrlOwner) ;
 				AGASetFontStyle( &info->fontStyle ) ;
 				SetPort( (**theControl).contrlOwner ) ;
 				RGBBackColor( &gAGARamp[ kAGAWhite ] ) ;
@@ -2223,7 +2223,7 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr
 			break ;
 		case kControlMsgKeyDown :
 			{
-				AGAPortHelper help( (**theControl).contrlOwner ) ;
+				wxMacPortStateHelper help( (**theControl).contrlOwner ) ;
 				AGASetFontStyle( &info->fontStyle ) ;
 				RGBBackColor( &gAGARamp[ kAGAWhite ] ) ;
 				RGBForeColor( &gAGARamp[ kAGABlack ] ) ;
@@ -2332,7 +2332,7 @@ pascal SInt32 AGAListControlDefProc (SInt16 procID, ControlHandle theControl, Co
 			break ;
 		case drawCntl :
 			{
-				AGAPortHelper help((**theControl).contrlOwner) ;
+				wxMacPortStateHelper help((**theControl).contrlOwner) ;
 				AGASetFontStyle( &info->fontStyle ) ;
 				RGBBackColor( &gAGARamp[ kAGAWhite ] ) ;
 				EraseRect( &(**theControl).contrlRect ) ;
@@ -2560,52 +2560,4 @@ void AGAApplyThemeBackground(ThemeBackgroundKind 	inKind,
 // status in a theme savvy manner, pen mode, patterns and fonts
 // attributes
 
-AGAPortHelper::AGAPortHelper( GrafPtr newport) 
-{
-  m_clip = NULL ;
-  Setup( newport ) ;
-}
-AGAPortHelper::AGAPortHelper()
-{
-	m_clip = NULL ;
-}
-
-void AGAPortHelper::Setup( GrafPtr newport )
-{
-	GetPort( &m_oldPort ) ;
-	SetPort( newport ) ;
-	wxASSERT_MSG( m_clip == NULL , "Cannot call setup twice" ) ;
-	m_clip = NewRgn() ;
-	GetClip( m_clip );
-	m_textFont = GetPortTextFont( newport);
-	m_textSize = GetPortTextSize( newport);
-	m_textStyle = GetPortTextFace( newport);
-	m_textMode = GetPortTextMode( newport);	
-	GetThemeDrawingState( &m_drawingState ) ;
-	m_currentPort = newport ;
-}
-void AGAPortHelper::Clear()
-{
-	if ( m_clip )
-	{
-		DisposeRgn( m_clip ) ;
-		DisposeThemeDrawingState( m_drawingState ) ;
-		m_clip = NULL ;
-	}
-}
-AGAPortHelper::~AGAPortHelper()
-{
-	if ( m_clip )
-	{
-		SetPort( m_currentPort ) ;
-		SetClip( m_clip ) ;
-		DisposeRgn( m_clip ) ;
-		TextFont( m_textFont );
-		TextSize( m_textSize );
-		TextFace( m_textStyle );
-		TextMode( m_textMode );
-		SetThemeDrawingState( m_drawingState , true ) ;
-		SetPort( m_oldPort ) ;
-	}
-}
 
diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp
index 1a02ff2e58..b16dcd492a 100644
--- a/src/mac/carbon/app.cpp
+++ b/src/mac/carbon/app.cpp
@@ -85,7 +85,7 @@ const short    kMacMinHeap = (29 * 1024) ;
 const short kwxMacMenuBarResource = 1 ;
 const short kwxMacAppleMenuId = 1 ;
 
-RgnHandle            wxApp::s_macCursorRgn = NULL;
+WXHRGN            wxApp::s_macCursorRgn = NULL;
 wxWindow*            wxApp::s_captureWindow = NULL ;
 int                    wxApp::s_lastMouseDown = 0 ;
 long                     wxApp::sm_lastMessageTime = 0;
@@ -125,7 +125,7 @@ pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long re
     return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
 }
 
-OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEODoc(const WXEVENTREF event , WXEVENTREF reply)
 {
     SysBeep(40) ;
     ProcessSerialNumber PSN ;
@@ -135,17 +135,17 @@ OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply)
     return noErr ;
 }
 
-OSErr wxApp::MacHandleAEPDoc(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF reply)
 {
     return noErr ;
 }
 
-OSErr wxApp::MacHandleAEOApp(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEOApp(const WXEVENTREF event , WXEVENTREF reply)
 {
     return noErr ;
 }
 
-OSErr wxApp::MacHandleAEQuit(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEQuit(const WXEVENTREF event , WXEVENTREF reply)
 {
     wxWindow* win = GetTopWindow() ;
     if ( win )
@@ -603,7 +603,7 @@ void wxApp::CleanUp()
 
     UMACleanupToolbox() ;
     if (s_macCursorRgn)
-        ::DisposeRgn(s_macCursorRgn);
+        ::DisposeRgn((RgnHandle)s_macCursorRgn);
 
     #if 0
         TerminateAE() ;
@@ -958,11 +958,11 @@ bool wxApp::Yield(bool onlyIfNeeded)
 
     long sleepTime = 1 ; //::GetCaretTime();
 
-    while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, wxApp::s_macCursorRgn))
+    while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn))
     {
         wxTheApp->MacHandleOneEvent( &event );
         if ( event.what != kHighLevelEvent )
-            SetRectRgn( wxApp::s_macCursorRgn , event.where.h , event.where.v ,  event.where.h + 1 , event.where.v + 1 ) ;
+            SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v ,  event.where.h + 1 , event.where.v + 1 ) ;
     }
 
     wxMacProcessNotifierAndPendingEvents() ;
@@ -1021,7 +1021,7 @@ void wxApp::MacDoOneEvent()
 
     long sleepTime = 1; // GetCaretTime() / 4 ;
 
-    if (WaitNextEvent(everyEvent, &event, sleepTime, s_macCursorRgn))
+    if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn))
     {
         MacHandleOneEvent( &event );
     }
@@ -1035,7 +1035,7 @@ void wxApp::MacDoOneEvent()
         wxTheApp->ProcessIdle() ;
     }
     if ( event.what != kHighLevelEvent )
-        SetRectRgn( s_macCursorRgn , event.where.h , event.where.v ,  event.where.h + 1 , event.where.v + 1 ) ;
+        SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v ,  event.where.h + 1 , event.where.v + 1 ) ;
 
     // repeaters
 
@@ -1043,8 +1043,9 @@ void wxApp::MacDoOneEvent()
     wxMacProcessNotifierAndPendingEvents() ;
 }
 
-void wxApp::MacHandleOneEvent( EventRecord *ev )
+void wxApp::MacHandleOneEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     m_macCurrentEvent = ev ;
 
     wxApp::sm_lastMessageTime = ev->when ;
@@ -1098,15 +1099,17 @@ void wxApp::MacHandleOneEvent( EventRecord *ev )
     wxMacProcessNotifierAndPendingEvents() ;
 }
 
-void wxApp::MacHandleHighLevelEvent( EventRecord *ev )
+void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     ::AEProcessAppleEvent( ev ) ;
 }
 
 bool s_macIsInModalLoop = false ;
 
-void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
+void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     wxToolTip::RemoveToolTips() ;
 
     WindowRef window;
@@ -1156,11 +1159,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                     GrafPtr port ;
                     GetPort( &port ) ;
                     Point pt = { 0, 0 } ;
-                    #if TARGET_CARBON
                     SetPort( GetWindowPort(window) ) ;
-                    #else
-                    SetPort( (window) ) ;
-                    #endif
                     LocalToGlobal( &pt ) ;
                     SetPort( port ) ;
                         win->SetSize( pt.h , pt.v , -1 ,
@@ -1226,11 +1225,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                 {
                     GrafPtr port ;
                     GetPort( &port ) ;
-                    #if TARGET_CARBON
                     SetPort( GetWindowPort(window) ) ;
-                    #else
-                    SetPort( (window) ) ;
-                    #endif
                     SetPort( port ) ;
                 }
                 if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
@@ -1263,8 +1258,9 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleMouseUpEvent( EventRecord *ev )
+void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     WindowRef window;
 
     short windowPart = ::FindWindow(ev->where, &window);
@@ -1394,8 +1390,9 @@ long wxMacTranslateKey(unsigned char key, unsigned char code)
     return retval;
 }
 
-void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
+void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     wxToolTip::RemoveToolTips() ;
 
     UInt32 menuresult = UMAMenuEvent(ev) ;
@@ -1511,8 +1508,9 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleKeyUpEvent( EventRecord *ev )
+void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     wxToolTip::RemoveToolTips() ;
 
     UInt32 menuresult = UMAMenuEvent(ev) ;
@@ -1546,8 +1544,9 @@ void wxApp::MacHandleKeyUpEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleActivateEvent( EventRecord *ev )
+void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     WindowRef window = (WindowRef) ev->message ;
     if ( window )
     {
@@ -1565,8 +1564,9 @@ void wxApp::MacHandleActivateEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleUpdateEvent( EventRecord *ev )
+void wxApp::MacHandleUpdateEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     WindowRef window = (WindowRef) ev->message ;
     wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ;
     if ( win )
@@ -1584,8 +1584,9 @@ void wxApp::MacHandleUpdateEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleDiskEvent( EventRecord *ev )
+void wxApp::MacHandleDiskEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     if ( HiWord( ev->message ) != noErr )
   {
  #if !TARGET_CARBON
@@ -1599,8 +1600,9 @@ void wxApp::MacHandleDiskEvent( EventRecord *ev )
     }
 }
 
-void wxApp::MacHandleOSEvent( EventRecord *ev )
+void wxApp::MacHandleOSEvent( WXEVENTREF evr )
 {
+    EventRecord* ev = (EventRecord*) evr ;
     switch( ( ev->message & osEvtMessageMask ) >> 24 )
     {
         case suspendResumeMessage :
diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp
index ba9371a821..ec5d91854e 100644
--- a/src/mac/carbon/bitmap.cpp
+++ b/src/mac/carbon/bitmap.cpp
@@ -313,7 +313,7 @@ static void DisposeBitmapRefData(wxBitmapRefData *data)
             {
                 if ( data->m_hPict )
                 {
-                    KillPicture( data->m_hPict ) ;
+                    KillPicture( MAC_WXHMETAFILE( data->m_hPict ) ) ;
                     data->m_hPict = NULL ;
                 }
             }
@@ -322,7 +322,7 @@ static void DisposeBitmapRefData(wxBitmapRefData *data)
             {
                 if ( data->m_hBitmap )
                 {
-                    wxMacDestroyGWorld( data->m_hBitmap ) ;
+                    wxMacDestroyGWorld( MAC_WXHBITMAP(data->m_hBitmap) ) ;
                     data->m_hBitmap = NULL ;
                 }
             }
@@ -330,7 +330,7 @@ static void DisposeBitmapRefData(wxBitmapRefData *data)
         case kMacBitmapTypeIcon :
             if ( data->m_hIcon )
             {
-                DisposeCIcon( data->m_hIcon ) ;
+                DisposeCIcon( MAC_WXHICON(data->m_hIcon) ) ;
                 data->m_hIcon = NULL ;
             }
         
@@ -377,15 +377,15 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
     if ( no_bits == 1 )
     {
         M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
-        M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( the_width , the_height , no_bits ) ;
-        M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
+        MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) = wxMacCreateGWorld( the_width , the_height , no_bits ) ;
+        M_BITMAPDATA->m_ok = (MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) != NULL ) ;
     
         CGrafPtr    origPort ;
         GDHandle    origDevice ;
     
         GetGWorld( &origPort , &origDevice ) ;
-        SetGWorld( M_BITMAPDATA->m_hBitmap , NULL ) ;
-        LockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
+        SetGWorld( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) , NULL ) ;
+        LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) ) ) ;
     
         // bits is a char array
     
@@ -417,7 +417,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
                 }
             }
         }
-        UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
+        UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) ) ) ;
     
         SetGWorld( origPort , origDevice ) ;
     }
@@ -474,7 +474,7 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
    wxBitmap ret( rect.width, rect.height, GetDepth() );
    wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
 
-   WXHBITMAP origPort;
+   GWorldPtr origPort;
    GDHandle  origDevice;
 
    GetGWorld( &origPort, &origDevice );
@@ -496,10 +496,10 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
        // Copy mask
        if(GetMask())
        {
-           WXHBITMAP submask, mask;
+           GWorldPtr submask, mask;
            RGBColor  color;
 
-           mask = GetMask()->GetMaskBitmap();
+           mask = (GWorldPtr) GetMask()->GetMaskBitmap();
            submask = wxMacCreateGWorld(rect.width, rect.height, 1);
            LockPixels(GetGWorldPixMap(mask));
            LockPixels(GetGWorldPixMap(submask));
@@ -523,11 +523,11 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
        // Copy bitmap
        if(GetHBITMAP())
        {
-           WXHBITMAP subbitmap, bitmap;
+           GWorldPtr subbitmap, bitmap;
            RGBColor  color;
 
-           bitmap = GetHBITMAP();
-           subbitmap = ref->m_hBitmap ;
+           bitmap = (GWorldPtr) GetHBITMAP();
+           subbitmap = (GWorldPtr) ref->m_hBitmap ;
            LockPixels(GetGWorldPixMap(bitmap));
            LockPixels(GetGWorldPixMap(subbitmap));
 
@@ -562,7 +562,7 @@ bool wxBitmap::Create(int w, int h, int d)
 
     M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
     M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( w , h , d ) ;
-    M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
+    M_BITMAPDATA->m_ok = ( M_BITMAPDATA->m_hBitmap != NULL ) ;
     return M_BITMAPDATA->m_ok;
 }
 
@@ -579,7 +579,7 @@ void wxBitmap::SetHBITMAP(WXHBITMAP bmp)
     
     M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
     M_BITMAPDATA->m_hBitmap = bmp ;
-      M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
+      M_BITMAPDATA->m_ok = ( M_BITMAPDATA->m_hBitmap != NULL ) ;
 }
 
 bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
@@ -641,11 +641,11 @@ wxBitmap::wxBitmap(const wxImage& image, int depth)
     CGrafPtr origPort ;
     GDHandle origDevice ;
 
-    PixMapHandle pixMap = GetGWorldPixMap(GetHBITMAP()) ;
+    PixMapHandle pixMap = GetGWorldPixMap((GWorldPtr)GetHBITMAP()) ;
     LockPixels( pixMap );
 
     GetGWorld( &origPort , &origDevice ) ;
-    SetGWorld( GetHBITMAP() , NULL ) ;
+    SetGWorld( (GWorldPtr) GetHBITMAP() , NULL ) ;
     
     // Render image
     RGBColor colorRGB ;
@@ -675,8 +675,8 @@ wxBitmap::wxBitmap(const wxImage& image, int depth)
       wxBitmap maskBitmap ;
 
       maskBitmap.Create( width, height, 1);
-      LockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) );
-      SetGWorld(maskBitmap.GetHBITMAP(), NULL);
+      LockPixels( GetGWorldPixMap( (GWorldPtr) maskBitmap.GetHBITMAP()) );
+      SetGWorld( (GWorldPtr) maskBitmap.GetHBITMAP(), NULL);
 
       for (int y = 0; y < height; y++)
       {
@@ -692,12 +692,12 @@ wxBitmap::wxBitmap(const wxImage& image, int depth)
               data += 3 ;
           }
       }  // for height
-      SetGWorld(GetHBITMAP(), NULL);
+      SetGWorld( (GWorldPtr) GetHBITMAP(), NULL);
       SetMask(new wxMask( maskBitmap ));
-      UnlockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) );
+      UnlockPixels( GetGWorldPixMap( (GWorldPtr) maskBitmap.GetHBITMAP()) );
     }
     
-    UnlockPixels( GetGWorldPixMap(GetHBITMAP()) );
+    UnlockPixels( GetGWorldPixMap( (GWorldPtr) GetHBITMAP()) );
     SetGWorld( origPort, origDevice );
 }
 
@@ -716,7 +716,7 @@ wxImage wxBitmap::ConvertToImage() const
 
     wxCHECK_MSG( data, wxNullImage, wxT("Could not allocate data for image") );
 
-    WXHBITMAP origPort;
+    GWorldPtr origPort;
     GDHandle  origDevice;
     int      index;
     RGBColor color;
@@ -726,8 +726,8 @@ wxImage wxBitmap::ConvertToImage() const
     wxMask  *mask = GetMask();
 
     GetGWorld( &origPort, &origDevice );
-    LockPixels(GetGWorldPixMap(GetHBITMAP()));
-    SetGWorld( GetHBITMAP(), NULL);
+    LockPixels(GetGWorldPixMap( (GWorldPtr) GetHBITMAP()));
+    SetGWorld(  (GWorldPtr) GetHBITMAP(), NULL);
 
     // Copy data into image
     index = 0;
@@ -761,7 +761,7 @@ wxImage wxBitmap::ConvertToImage() const
     }
 
     // Free resources
-    UnlockPixels(GetGWorldPixMap(GetHBITMAP()));
+    UnlockPixels(GetGWorldPixMap( (GWorldPtr) GetHBITMAP()));
     SetGWorld(origPort, origDevice);
 
     return image;
@@ -899,10 +899,10 @@ WXHBITMAP wxBitmap::GetHBITMAP() const
 {
    wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
 
-   return M_BITMAPDATA->m_hBitmap;
+   return MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap);
 }
 
-PicHandle wxBitmap::GetPict() const
+WXHMETAFILE wxBitmap::GetPict() const
 {
    wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
    
@@ -925,16 +925,16 @@ PicHandle wxBitmap::GetPict() const
    wxMask   *mask;
    Rect      portRect ;
 
-   GetPortBounds( GetHBITMAP() , &portRect ) ;
+   GetPortBounds(  (GWorldPtr) GetHBITMAP() , &portRect ) ;
    int width = portRect.right - portRect.left ;
    int height = portRect.bottom - portRect.top ;
 
-   LockPixels( GetGWorldPixMap( GetHBITMAP() ) ) ;
+   LockPixels( GetGWorldPixMap(  (GWorldPtr) GetHBITMAP() ) ) ;
    GetGWorld( &origPort , &origDev ) ;
 
    mask = GetMask();
 
-   SetGWorld( GetHBITMAP() , NULL ) ;
+   SetGWorld(  (GWorldPtr) GetHBITMAP() , NULL ) ;
 
    picture = OpenPicture(&portRect);   // open a picture, this disables drawing
    if(!picture) {
@@ -979,16 +979,16 @@ PicHandle wxBitmap::GetPict() const
        RGBForeColor( &black ) ;
        RGBBackColor( &white ) ;
 
-       CopyBits(GetPortBitMapForCopyBits(GetHBITMAP()), 
+       CopyBits(GetPortBitMapForCopyBits( (GWorldPtr) GetHBITMAP()), 
                 // src PixMap - we copy image over itself -
-                GetPortBitMapForCopyBits(GetHBITMAP()),
+                GetPortBitMapForCopyBits( (GWorldPtr) GetHBITMAP()),
                 //  dst PixMap - no drawing occurs
                 &portRect,    // srcRect - it will be recorded and compressed -
                 &portRect,    // dstRect - into the picture that is open -
                 srcCopy,NULL); // copyMode and no clip region
    }
    ClosePicture();                  // We are done recording the picture
-   UnlockPixels( GetGWorldPixMap( GetHBITMAP() ) ) ;
+   UnlockPixels( GetGWorldPixMap(  (GWorldPtr) GetHBITMAP() ) ) ;
    SetGWorld( origPort , origDev ) ;
 
    return picture;                  // return our groovy pict handle
@@ -1030,7 +1030,7 @@ wxMask::~wxMask()
 {
     if ( m_maskBitmap )
     {
-        wxMacDestroyGWorld( m_maskBitmap ) ;
+        wxMacDestroyGWorld(  (GWorldPtr) m_maskBitmap ) ;
         m_maskBitmap = NULL ;
     }
 }
@@ -1040,7 +1040,7 @@ bool wxMask::Create(const wxBitmap& bitmap)
 {
    if ( m_maskBitmap )
    {
-       wxMacDestroyGWorld( m_maskBitmap ) ;
+       wxMacDestroyGWorld(  (GWorldPtr) m_maskBitmap ) ;
        m_maskBitmap = NULL ;
    }
    wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false,
@@ -1055,13 +1055,13 @@ bool wxMask::Create(const wxBitmap& bitmap)
    m_maskBitmap = wxMacCreateGWorld(bitmap.GetWidth(), bitmap.GetHeight(), 1);
    Rect rect = { 0,0, bitmap.GetHeight(), bitmap.GetWidth() };
 
-   LockPixels( GetGWorldPixMap(m_maskBitmap) );
-   LockPixels( GetGWorldPixMap(bitmap.GetHBITMAP()) );
-   CopyBits(GetPortBitMapForCopyBits(bitmap.GetHBITMAP()),
-            GetPortBitMapForCopyBits(m_maskBitmap),
+   LockPixels( GetGWorldPixMap( (GWorldPtr) m_maskBitmap) );
+   LockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP()) );
+   CopyBits(GetPortBitMapForCopyBits( (GWorldPtr) bitmap.GetHBITMAP()),
+            GetPortBitMapForCopyBits( (GWorldPtr) m_maskBitmap),
             &rect, &rect, srcCopy, 0);
-   UnlockPixels( GetGWorldPixMap(m_maskBitmap) );
-   UnlockPixels( GetGWorldPixMap(bitmap.GetHBITMAP()) );
+   UnlockPixels( GetGWorldPixMap( (GWorldPtr) m_maskBitmap) );
+   UnlockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP()) );
 
    return FALSE;
 }
@@ -1081,7 +1081,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
 {
     if ( m_maskBitmap )
     {
-        wxMacDestroyGWorld( m_maskBitmap ) ;
+        wxMacDestroyGWorld(  (GWorldPtr) m_maskBitmap ) ;
         m_maskBitmap = NULL ;
     }
     wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false,
@@ -1091,9 +1091,9 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
     wxCHECK_MSG( bitmap.Ok(), false, wxT("Illigal bitmap"));
 
     m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 ); 
-    LockPixels( GetGWorldPixMap( m_maskBitmap ) );
-    LockPixels( GetGWorldPixMap( bitmap.GetHBITMAP() ) );
-    RGBColor maskColor = colour.GetPixel();
+    LockPixels( GetGWorldPixMap(  (GWorldPtr) m_maskBitmap ) );
+    LockPixels( GetGWorldPixMap(  (GWorldPtr) bitmap.GetHBITMAP() ) );
+    RGBColor maskColor = MAC_WXCOLORREF(colour.GetPixel());
 
     // this is not very efficient, but I can't think
     // of a better way of doing it
@@ -1109,9 +1109,9 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
     {
         for (int h = 0; h < bitmap.GetHeight(); h++)
         {       
-            SetGWorld( bitmap.GetHBITMAP(), NULL ) ;
+            SetGWorld(  (GWorldPtr) bitmap.GetHBITMAP(), NULL ) ;
             GetCPixel( w , h , &col ) ;
-            SetGWorld( m_maskBitmap , NULL ) ;
+            SetGWorld(  (GWorldPtr) m_maskBitmap , NULL ) ;
             if (col.red == maskColor.red && col.green == maskColor.green && col.blue == maskColor.blue)
             {
                 SetCPixel( w , h , &colors[0] ) ;
@@ -1123,7 +1123,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
         }
     }
     UnlockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ;
-    UnlockPixels( GetGWorldPixMap( bitmap.GetHBITMAP() ) ) ;
+    UnlockPixels( GetGWorldPixMap(  (GWorldPtr) bitmap.GetHBITMAP() ) ) ;
     SetGWorld( origPort , origDevice ) ;
 
     return TRUE;
@@ -1131,7 +1131,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
 
 bool wxMask::PointMasked(int x, int y)
 {
-   WXHBITMAP origPort;
+   GWorldPtr origPort;
    GDHandle  origDevice;
    RGBColor  color;
    bool masked = true;
@@ -1139,11 +1139,11 @@ bool wxMask::PointMasked(int x, int y)
    GetGWorld( &origPort, &origDevice);
 
    //Set port to mask and see if it masked (1) or not ( 0 )
-   SetGWorld(m_maskBitmap, NULL);
-   LockPixels(GetGWorldPixMap(m_maskBitmap));
+   SetGWorld( (GWorldPtr) m_maskBitmap, NULL);
+   LockPixels(GetGWorldPixMap( (GWorldPtr) m_maskBitmap));
    GetCPixel(x,y, &color);
    masked = !(color.red == 0 && color.green == 0 && color.blue == 0);
-   UnlockPixels(GetGWorldPixMap(m_maskBitmap));
+   UnlockPixels(GetGWorldPixMap( (GWorldPtr) m_maskBitmap));
 
    SetGWorld( origPort, origDevice);
 
diff --git a/src/mac/carbon/bmpbuttn.cpp b/src/mac/carbon/bmpbuttn.cpp
index 2a93999107..ed8ee2a469 100644
--- a/src/mac/carbon/bmpbuttn.cpp
+++ b/src/mac/carbon/bmpbuttn.cpp
@@ -57,11 +57,11 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
 	
 	MacPreControlCreate( parent , id ,  "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 
 		kControlBehaviorOffsetContents + 
 		    ( bmap->m_bitmapType == kMacBitmapTypeIcon ? kControlContentCIconHandle : kControlContentPictHandle ) , 0, 
 	  	(( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
-	wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+	wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
 	
 	ControlButtonContentInfo info ;
 	
@@ -70,31 +70,31 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
 	{
 		if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
 	    info.contentType = kControlContentPictHandle ;
-			info.u.picture = bmap->m_hPict ;
+			info.u.picture = MAC_WXHMETAFILE( bmap->m_hPict ) ;
 		}
 		else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
 		{
 			if ( m_buttonBitmap.GetMask() )
 			{
 		    info.contentType = kControlContentCIconHandle ;
-				info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ,
+				info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP( bmap->m_hBitmap ) , MAC_WXHBITMAP(m_buttonBitmap.GetMask()->GetMaskBitmap()) ,
 				    8 , 16 ) ;
 			}
 			else
 			{
 		    info.contentType = kControlContentCIconHandle ;
-				info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , NULL ,
+				info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP( bmap->m_hBitmap ) , NULL ,
 				    8 , 16 ) ;
 			}
 		}
 		else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
 		{
 	        info.contentType = kControlContentCIconHandle ;
-	        info.u.cIconHandle = bmap->m_hIcon ;
+	        info.u.cIconHandle = MAC_WXHICON(bmap->m_hIcon) ;
 		}
 	}
 	
-	::SetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
+	::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
 
 	MacPostControlCreate() ;
 
@@ -111,31 +111,31 @@ void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
 		wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
 		if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
 	    info.contentType = kControlContentPictHandle ;
-			info.u.picture = bmap->m_hPict ;
+			info.u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
 		}
 		else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
 		{
 			if ( m_buttonBitmap.GetMask() )
 			{
 		    info.contentType = kControlContentCIconHandle ;
-				info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ,
+				info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(m_buttonBitmap.GetMask()->GetMaskBitmap()) ,
 				    8 , 16 ) ;
 			}
 			else
 			{
 		    info.contentType = kControlContentCIconHandle ;
-				info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , NULL ,
+				info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
 				    8 , 16 ) ;
 			}
 		}
 		else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
 		{
 	        info.contentType = kControlContentCIconHandle ;
-	        info.u.cIconHandle = bmap->m_hIcon ;
+	        info.u.cIconHandle = MAC_WXHICON( bmap->m_hIcon ) ;
 		}
 
 		
-	    ::SetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
+	    ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
     }
 }
 
diff --git a/src/mac/carbon/brush.cpp b/src/mac/carbon/brush.cpp
index 5c87256763..f38b3782d9 100644
--- a/src/mac/carbon/brush.cpp
+++ b/src/mac/carbon/brush.cpp
@@ -17,10 +17,34 @@
 #include "wx/utils.h"
 #include "wx/brush.h"
 
+#include "wx/mac/private.h"
+
 #if !USE_SHARED_LIBRARIES
 IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
 #endif
 
+class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
+{
+    friend class WXDLLEXPORT wxBrush;
+public:
+    wxBrushRefData();
+    wxBrushRefData(const wxBrushRefData& data);
+    ~wxBrushRefData();
+
+protected:
+    wxMacBrushKind m_macBrushKind ;
+    int           m_style;
+    wxBitmap      m_stipple ;
+    wxColour      m_colour;
+    
+    ThemeBrush    m_macThemeBrush ;
+    
+    ThemeBackgroundKind m_macThemeBackground ;
+    Rect         m_macThemeBackgroundExtent ;
+};
+
+#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
+
 wxBrushRefData::wxBrushRefData()
 {
     m_style = wxSOLID;
@@ -149,13 +173,13 @@ void wxBrush::SetMacTheme(ThemeBrush macThemeBrush)
     RealizeResource();
 }
 
-void wxBrush::SetMacThemeBackground(ThemeBackgroundKind macThemeBackground, const Rect &extent)
+void wxBrush::SetMacThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent)
 {
     Unshare();
 
     M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground;
     M_BRUSHDATA->m_macThemeBackground = macThemeBackground;
-    M_BRUSHDATA->m_macThemeBackgroundExtent = extent ;
+    M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent ;
     RealizeResource();
 }
 
@@ -164,12 +188,12 @@ bool wxBrush::RealizeResource()
     return TRUE;
 }
 
-ThemeBackgroundKind wxBrush::GetMacThemeBackground(Rect *extent)  const 
+unsigned long wxBrush::GetMacThemeBackground( WXRECTPTR extent)  const 
 {
   if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground )
   {
     if ( extent )
-      *extent = M_BRUSHDATA->m_macThemeBackgroundExtent ;
+      *(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent ;
     return M_BRUSHDATA->m_macThemeBackground ;
   }
   else
@@ -178,3 +202,25 @@ ThemeBackgroundKind wxBrush::GetMacThemeBackground(Rect *extent)  const
   }
 }
 
+short wxBrush::GetMacTheme()  const 
+{ 
+  return (M_BRUSHDATA ? ( M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack); 
+};
+
+wxColour& wxBrush::GetColour() const 
+{ return (M_BRUSHDATA ? M_BRUSHDATA->m_colour : wxNullColour); };
+
+int wxBrush::GetStyle() const 
+{ 
+  return (M_BRUSHDATA ? M_BRUSHDATA->m_style : 0); 
+};
+
+wxBitmap *wxBrush::GetStipple() const 
+{ 
+  return (M_BRUSHDATA ? & M_BRUSHDATA->m_stipple : 0); 
+};
+
+wxMacBrushKind wxBrush::MacGetBrushKind()  const 
+{ 
+  return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour); 
+};
diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp
index 072ba01720..cbc1d846d9 100644
--- a/src/mac/carbon/button.cpp
+++ b/src/mac/carbon/button.cpp
@@ -37,9 +37,9 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
 	
 	MacPreControlCreate( parent , id ,  label , pos , size ,style, validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlPushButtonProc , (long) this ) ;
-	wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+	wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
 	
 	MacPostControlCreate() ;
 
@@ -61,13 +61,13 @@ void wxButton::SetDefault()
 	if ( btnOldDefault && btnOldDefault->m_macControl )
 	{
   		inData = 0;
-		::SetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
+		::SetControlData( (ControlHandle) btnOldDefault->m_macControl , kControlButtonPart ,
 						   kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
 	}
-	if ( m_macControl )
+	if ( (ControlHandle) m_macControl )
 	{
   		inData = 1;
-		::SetControlData( m_macControl , kControlButtonPart ,
+		::SetControlData(  (ControlHandle) m_macControl , kControlButtonPart ,
 						   kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
 	}
 }
@@ -95,17 +95,17 @@ wxSize wxButton::GetDefaultSize()
 
 void wxButton::Command (wxCommandEvent & event)
 {
-	if ( m_macControl )
+	if ( (ControlHandle) m_macControl )
 	{
-		HiliteControl( m_macControl , kControlButtonPart ) ;
+		HiliteControl(  (ControlHandle) m_macControl , kControlButtonPart ) ;
 		unsigned long finalTicks ;
 		Delay( 8 , &finalTicks ) ;
-		HiliteControl( m_macControl , 0 ) ;
+		HiliteControl(  (ControlHandle) m_macControl , 0 ) ;
 	}
     ProcessCommand (event);
 }
 
-void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
   if ( controlpart != kControlNoPart )
   {
diff --git a/src/mac/carbon/checkbox.cpp b/src/mac/carbon/checkbox.cpp
index d6d532e538..85ebcf2391 100644
--- a/src/mac/carbon/checkbox.cpp
+++ b/src/mac/carbon/checkbox.cpp
@@ -36,7 +36,7 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
 	
 	MacPreControlCreate( parent , id ,  label , pos , size ,style, validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlCheckBoxProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
@@ -46,13 +46,13 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
 
 void wxCheckBox::SetValue(bool val)
 {
-   ::SetControlValue( m_macControl , val ) ;
+   ::SetControlValue( (ControlHandle) m_macControl , val ) ;
    MacRedrawControl() ;
 }
 
 bool wxCheckBox::GetValue() const
 {
-    return ::GetControlValue( m_macControl ) ;
+    return ::GetControlValue( (ControlHandle) m_macControl ) ;
 }
 
 void wxCheckBox::Command (wxCommandEvent & event)
@@ -61,7 +61,7 @@ void wxCheckBox::Command (wxCommandEvent & event)
     ProcessCommand (event);
 }
 
-void wxCheckBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxCheckBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
 	SetValue( !GetValue() ) ;
     wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
diff --git a/src/mac/carbon/checklst.cpp b/src/mac/carbon/checklst.cpp
index 7d8bec19e8..743fea9aac 100644
--- a/src/mac/carbon/checklst.cpp
+++ b/src/mac/carbon/checklst.cpp
@@ -109,10 +109,10 @@ static pascal void wxMacCheckListDefinition( short message, Boolean isSelected,
             //  appropriate QuickDraw transform mode.
             
             if( isSelected ) {
-                savedPenMode = GetPortPenMode( grafPtr );
-                SetPortPenMode( grafPtr, hilitetransfermode );
+                savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
+                SetPortPenMode( (CGrafPtr) grafPtr, hilitetransfermode );
                 PaintRect( drawRect );
-                SetPortPenMode( grafPtr, savedPenMode );
+                SetPortPenMode( (CGrafPtr) grafPtr, savedPenMode );
             }
             
             //  Restore the saved clip region.
@@ -127,10 +127,10 @@ static pascal void wxMacCheckListDefinition( short message, Boolean isSelected,
             //  appropriate QuickDraw transform mode.
             
             GetPort( &grafPtr );
-            savedPenMode = GetPortPenMode( grafPtr );
-            SetPortPenMode( grafPtr, hilitetransfermode );
+            savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
+            SetPortPenMode( (CGrafPtr) grafPtr, hilitetransfermode );
             PaintRect( drawRect );
-            SetPortPenMode( grafPtr, savedPenMode );
+            SetPortPenMode( (CGrafPtr) grafPtr, savedPenMode );
             break;
         default :
           break ;
@@ -183,36 +183,36 @@ bool wxCheckListBox::Create(wxWindow *parent,
     CreateListBoxControl( parent->MacGetRootWindow(), &bounds, false, 0, 1, false, true,
                           14, 14, false, &listDef, &m_macControl );
 
-    GetControlData(m_macControl, kControlNoPart, kControlListBoxListHandleTag,
+    GetControlData( (ControlHandle) m_macControl, kControlNoPart, kControlListBoxListHandleTag,
                    sizeof(ListHandle), (Ptr) &m_macList, &asize);
 
-    SetControlReference(m_macControl, (long) this);
-    SetControlVisibility(m_macControl, false, false);
+    SetControlReference( (ControlHandle) m_macControl, (long) this);
+    SetControlVisibility( (ControlHandle) m_macControl, false, false);
 
 #else
 
     long    result ;
 
-    m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false ,
+    m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
                   kwxMacListWithVerticalScrollbar , 0 , 0, 
                   kControlListBoxProc , (long) this ) ;
-    ::GetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
+    ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
                sizeof( ListHandle ) , (char*) &m_macList  , &result ) ;
 
     HLock( (Handle) m_macList ) ;
     ldefHandle ldef ;
     ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ;
-    if (  (**m_macList).listDefProc != NULL )
+    if (  (**(ListHandle)m_macList).listDefProc != NULL )
     {
       (**ldef).instruction = 0x4EF9;  /* JMP instruction */
       (**ldef).function = (void(*)()) listDef.u.userProc;
-      (**m_macList).listDefProc = (Handle) ldef ;
+      (**(ListHandle)m_macList).listDefProc = (Handle) ldef ;
     }
         
-    Point pt = (**m_macList).cellSize ;
+    Point pt = (**(ListHandle)m_macList).cellSize ;
     pt.v = 14 ;
-    LCellSize( pt , m_macList ) ;
-    LAddColumn( 1 , 0 , m_macList ) ;
+    LCellSize( pt , (ListHandle)m_macList ) ;
+    LAddColumn( 1 , 0 , (ListHandle)m_macList ) ;
 #endif
     OptionBits  options = 0;
     if ( style & wxLB_MULTIPLE )
@@ -227,7 +227,7 @@ bool wxCheckListBox::Create(wxWindow *parent,
     {
         options = lOnlyOne ;
     }
-    SetListSelectionFlags(m_macList, options);
+    SetListSelectionFlags((ListHandle)m_macList, options);
     
     MacPostControlCreate() ;
     
@@ -236,7 +236,7 @@ bool wxCheckListBox::Create(wxWindow *parent,
         Append( choices[i] ) ;
     }
     
-    LSetDrawingMode( true , m_macList ) ;
+    LSetDrawingMode( true , (ListHandle) m_macList ) ;
 
     return TRUE;
 }
@@ -358,8 +358,8 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event)
     GetListVisibleCells( m_macList , &visible ) ;
     topcell = visible.top ;
 #else
-    lineheight =  (**m_macList).cellSize.v ;
-    topcell = (**m_macList).visible.top ;
+    lineheight =  (**(ListHandle)m_macList).cellSize.v ;
+    topcell = (**(ListHandle)m_macList).visible.top ;
 #endif
     size_t nItem = ((size_t)event.GetY()) / lineheight + topcell ;
     
diff --git a/src/mac/carbon/choice.cpp b/src/mac/carbon/choice.cpp
index 2ec18bc546..f8068ff829 100644
--- a/src/mac/carbon/choice.cpp
+++ b/src/mac/carbon/choice.cpp
@@ -45,15 +45,15 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id,
 	
 		MacPreControlCreate( parent , id ,  "" , pos , size ,style, validator , name , &bounds , title ) ;
 
-		m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , -12345 , 0 , 
+		m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , -12345 , 0 , 
 	  	kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ; 
 	
 		m_macPopUpMenuHandle =  NewUniqueMenu() ;
-		SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
-	 	SetControlMinimum( m_macControl , 0 ) ;
-		SetControlMaximum( m_macControl , 0) ;
+		SetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
+	 	SetControlMinimum( (ControlHandle) m_macControl , 0 ) ;
+		SetControlMaximum( (ControlHandle) m_macControl , 0) ;
 		if ( n > 0 )
-			SetControlValue( m_macControl , 1 ) ;
+			SetControlValue( (ControlHandle) m_macControl , 1 ) ;
 
 		MacPostControlCreate() ;
 
@@ -72,12 +72,12 @@ int wxChoice::DoAppend(const wxString& item)
 {
 	Str255 label;
 	wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
-	AppendMenu( m_macPopUpMenuHandle , label ) ;
+	AppendMenu( MAC_WXHMENU( m_macPopUpMenuHandle ) , label ) ;
 	m_strings.Add( item ) ;
 	m_datas.Add( NULL ) ;
 	int index = m_strings.GetCount()  - 1  ;
 	DoSetItemClientData( index , NULL ) ;
-	SetControlMaximum( m_macControl , GetCount()) ;
+	SetControlMaximum( (ControlHandle) m_macControl , GetCount()) ;
 	return index ;
 }
 
@@ -90,10 +90,10 @@ void wxChoice::Delete(int n)
         delete GetClientObject(n);
     }
 
-    ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
+    ::DeleteMenuItem( MAC_WXHMENU(m_macPopUpMenuHandle) , n + 1) ;
     m_strings.Remove( n ) ;
     m_datas.RemoveAt( n ) ;
-	SetControlMaximum( m_macControl , GetCount()) ;
+	SetControlMaximum( (ControlHandle) m_macControl , GetCount()) ;
 }
 
 void wxChoice::Clear()
@@ -102,11 +102,11 @@ void wxChoice::Clear()
 
     for ( int i = 0 ; i < GetCount() ; i++ )
     {
-    	::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
+    	::DeleteMenuItem( MAC_WXHMENU(m_macPopUpMenuHandle) , 1 ) ;
 	  }
     m_strings.Empty() ;
     m_datas.Empty() ;
-	SetControlMaximum( m_macControl , 0 ) ;
+	SetControlMaximum( (ControlHandle) m_macControl , 0 ) ;
 }
 
 void wxChoice::Free()
@@ -127,12 +127,12 @@ void wxChoice::Free()
 
 int wxChoice::GetSelection() const
 {
-    return GetControlValue( m_macControl ) -1 ;
+    return GetControlValue( (ControlHandle) m_macControl ) -1 ;
 }
 
 void wxChoice::SetSelection(int n)
 {
-    SetControlValue( m_macControl , n + 1 ) ;
+    SetControlValue( (ControlHandle) m_macControl , n + 1 ) ;
 }
 
 // ----------------------------------------------------------------------------
@@ -208,7 +208,7 @@ wxClientData* wxChoice::DoGetItemClientObject( int n ) const
     return (wxClientData *)DoGetItemClientData(n);
 }
 
-void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxChoice::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
     wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
 	  event.SetInt(GetSelection());
diff --git a/src/mac/carbon/clipbrd.cpp b/src/mac/carbon/clipbrd.cpp
index 0d59db9a44..8e3cd77678 100644
--- a/src/mac/carbon/clipbrd.cpp
+++ b/src/mac/carbon/clipbrd.cpp
@@ -22,6 +22,8 @@
 #include "wx/clipbrd.h"
 #include "wx/intl.h"
 
+#include "wx/mac/private.h"
+
 #define wxUSE_DATAOBJ 1
 
 #include <string.h>
@@ -254,7 +256,7 @@ bool wxClipboard::AddData( wxDataObject *data )
               wxMetafileDataObject* metaFileDataObject =
                 (wxMetafileDataObject*) data;
               wxMetafile metaFile = metaFileDataObject->GetMetafile();
-      				PicHandle pict = metaFile.GetHMETAFILE() ;
+      				PicHandle pict = (PicHandle) metaFile.GetHMETAFILE() ;
       				HLock( (Handle) pict ) ;
       #if !TARGET_CARBON
       				err = PutScrap( GetHandleSize(  (Handle) pict ) , 'PICT' , *pict ) ;
diff --git a/src/mac/carbon/colordlg.cpp b/src/mac/carbon/colordlg.cpp
index c6037a9f96..90326e713d 100644
--- a/src/mac/carbon/colordlg.cpp
+++ b/src/mac/carbon/colordlg.cpp
@@ -20,6 +20,8 @@
 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
 #endif
 
+#include "wx/mac/private.h"
+
 /*
  * wxColourDialog
  */
@@ -46,13 +48,13 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
 int wxColourDialog::ShowModal()
 {
 	Point where ;
-	RGBColor currentColor = m_colourData.dataColour.GetPixel() , newColor ;
+	RGBColor currentColor = *((RGBColor*)m_colourData.dataColour.GetPixel()) , newColor ;
 	
 	where.h = where.v = -1;
 
 	if (GetColor( where, "\pSelect a new palette color.", &currentColor, &newColor ))
 	{
-		m_colourData.dataColour.Set( newColor ) ;
+		m_colourData.dataColour.Set( (WXCOLORREF*) &newColor ) ;
     	return wxID_OK;
 	}
 	else
diff --git a/src/mac/carbon/colour.cpp b/src/mac/carbon/colour.cpp
index cc549b5f11..82fb8a7928 100644
--- a/src/mac/carbon/colour.cpp
+++ b/src/mac/carbon/colour.cpp
@@ -22,9 +22,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
 
 // Colour
 
-static void wxComposeRGBColor( RGBColor * col , int red, int blue, int green ) ;
-static void wxComposeRGBColor( RGBColor * col , int red, int blue, int green ) 
+#include "wx/mac/private.h"
+
+static void wxComposeRGBColor( WXCOLORREF* color , int red, int blue, int green ) ;
+static void wxComposeRGBColor( WXCOLORREF* color , int red, int blue, int green ) 
 {
+    RGBColor* col = (RGBColor*) color ;
 	col->red = (red << 8) + red;
 	col->blue = (blue << 8) + blue;
 	col->green = (green << 8) + green;
@@ -55,7 +58,7 @@ wxColour::wxColour (const wxColour& col)
     m_blue = col.m_blue;
     m_isInit = col.m_isInit;
 
-    m_pixel = col.m_pixel;
+    memcpy( &m_pixel , &col.m_pixel , 6 ) ;
 }
 
 wxColour::wxColour (const wxColour* col)
@@ -65,7 +68,7 @@ wxColour::wxColour (const wxColour* col)
     m_blue = col->m_blue;
     m_isInit = col->m_isInit;
 
-    m_pixel = col->m_pixel;
+    memcpy( &m_pixel , &col->m_pixel , 6 ) ;
 }
 
 wxColour& wxColour::operator =(const wxColour& col)
@@ -75,7 +78,7 @@ wxColour& wxColour::operator =(const wxColour& col)
   m_blue = col.m_blue;
   m_isInit = col.m_isInit;
  
-  m_pixel = col.m_pixel;
+  memcpy( &m_pixel , &col.m_pixel , 6 ) ;
 
   return *this;
 }
@@ -114,3 +117,12 @@ void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
 
 	wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
 }
+
+void wxColour::Set( const WXCOLORREF* color )
+{ 
+    RGBColor* col = (RGBColor*) color ;
+    memcpy( &m_pixel , color , 6 ) ;
+    m_red = col->red>>8 ;
+    m_blue = col->blue>>8 ;
+    m_green = col->green>>8 ;
+}
\ No newline at end of file
diff --git a/src/mac/carbon/combobox.cpp b/src/mac/carbon/combobox.cpp
index 712a6dddbf..d55e591e52 100644
--- a/src/mac/carbon/combobox.cpp
+++ b/src/mac/carbon/combobox.cpp
@@ -47,20 +47,20 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
 	
 		MacPreControlCreate( parent , id ,  "" , pos , size ,style, validator , name , &bounds , title ) ;
 	
-		m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , -12345 , 0, 
+		m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , -12345 , 0, 
 	  	kControlPopupButtonProc , (long) this ) ; 
 	
 		m_macPopUpMenuHandle =  NewUniqueMenu() ;
-		SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
+		SetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
 		for ( int i = 0 ; i < n ; i++ )
 		{
 			Str255 label;
 			wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
-			AppendMenu( m_macPopUpMenuHandle , label ) ;
+			AppendMenu( (MenuHandle) m_macPopUpMenuHandle , label ) ;
 		}
-		SetControlMinimum( m_macControl , 0 ) ;
-		SetControlMaximum( m_macControl , m_noStrings) ;
-		SetControlValue( m_macControl , 1 ) ;
+		SetControlMinimum( (ControlHandle) m_macControl , 0 ) ;
+		SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ;
+		SetControlValue( (ControlHandle) m_macControl , 1 ) ;
 
 		MacPostControlCreate() ;
 
@@ -139,37 +139,37 @@ void wxComboBox::Append(const wxString& item)
 {
 	Str255 label;
 	wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
-	AppendMenu( m_macPopUpMenuHandle , label ) ;
+	AppendMenu( (MenuHandle) m_macPopUpMenuHandle , label ) ;
     m_noStrings ++;
-	SetControlMaximum( m_macControl , m_noStrings) ;
+	SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ;
 }
 
 void wxComboBox::Delete(int n)
 {
 	wxASSERT( n < m_noStrings ) ;
-    ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
+    ::DeleteMenuItem( (MenuHandle) m_macPopUpMenuHandle , n + 1) ;
     m_noStrings --;
-	SetControlMaximum( m_macControl , m_noStrings) ;
+	SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ;
 }
 
 void wxComboBox::Clear()
 {
     for ( int i = 0 ; i < m_noStrings ; i++ )
     {
-    	::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
+    	::DeleteMenuItem((MenuHandle) m_macPopUpMenuHandle , 1 ) ;
 	}
     m_noStrings = 0;
-	SetControlMaximum( m_macControl , m_noStrings) ;
+	SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ;
 }
 
 int wxComboBox::GetSelection() const
 {
-    return GetControlValue( m_macControl ) -1 ;
+    return GetControlValue( (ControlHandle) m_macControl ) -1 ;
 }
 
 void wxComboBox::SetSelection(int n)
 {
-    SetControlValue( m_macControl , n + 1 ) ;
+    SetControlValue( (ControlHandle) m_macControl , n + 1 ) ;
 }
 
 int wxComboBox::FindString(const wxString& s) const
@@ -186,7 +186,7 @@ wxString wxComboBox::GetString(int n) const
 {
     Str255 p_text ;
     char   c_text[255];
-    ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , p_text ) ;
+    ::GetMenuItemText( (MenuHandle) m_macPopUpMenuHandle , n+1 , p_text ) ;
 #if TARGET_CARBON
     p2cstrcpy( c_text, p_text ) ;
 #else
@@ -217,7 +217,7 @@ bool wxComboBox::SetStringSelection(const wxString& sel)
         return FALSE;
 }
 
-void wxComboBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxComboBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
     wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
 	event.SetInt(GetSelection());
diff --git a/src/mac/carbon/control.cpp b/src/mac/carbon/control.cpp
index 9ee03b8a4e..0dcfb505d0 100644
--- a/src/mac/carbon/control.cpp
+++ b/src/mac/carbon/control.cpp
@@ -110,9 +110,9 @@ wxControl::~wxControl()
         if (parent->GetDefaultItem() == (wxButton*) this)
             parent->SetDefaultItem(NULL);
     }
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
-        ::DisposeControl( m_macControl ) ;
+        ::DisposeControl( (ControlHandle) m_macControl ) ;
         m_macControl = NULL ;
     }
 }
@@ -121,7 +121,7 @@ void wxControl::SetLabel(const wxString& title)
 {
     m_label = title ;
 
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         Str255 maclabel ;
         wxString label ;
@@ -137,7 +137,7 @@ void wxControl::SetLabel(const wxString& title)
         strcpy( (char *) maclabel , label ) ;
         c2pstr( (char *) maclabel ) ;
 #endif
-        ::SetControlTitle( m_macControl , maclabel ) ;
+        ::SetControlTitle( (ControlHandle) m_macControl , maclabel ) ;
     }
     Refresh() ;
 }
@@ -147,7 +147,7 @@ wxSize wxControl::DoGetBestSize() const
     Rect    bestsize = { 0 , 0 , 0 , 0 } ;
     short   baselineoffset ;
     int bestWidth, bestHeight ;
-    ::GetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ;
+    ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
 
     if ( EmptyRect( &bestsize ) )
     {
@@ -239,7 +239,7 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
              const wxPoint& pos,
              const wxSize& size, long style,
              const wxValidator& validator,
-             const wxString& name , Rect *outBounds , StringPtr maclabel ) 
+             const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel ) 
 {
     m_label = label ;
   SetName(name);
@@ -264,10 +264,10 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
     m_x = pos.x ;
     m_y = pos.y ;
         
-    outBounds->top = -10;
-    outBounds->left = -10;
-    outBounds->bottom = 0;
-    outBounds->right = 0;
+    ((Rect*)outBounds)->top = -10;
+    ((Rect*)outBounds)->left = -10;
+    ((Rect*)outBounds)->bottom = 0;
+    ((Rect*)outBounds)->right = 0;
 
     char c_text[255];
     strcpy( c_text , label ) ;
@@ -286,7 +286,7 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
 
 void wxControl::MacPostControlCreate()
 {
-    wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+    wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
     
     if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
     {
@@ -298,7 +298,7 @@ void wxControl::MacPostControlCreate()
         controlstyle.flags = kControlUseFontMask ;
         controlstyle.font = kControlFontSmallBoldSystemFont ;
         
-        ::SetControlFontStyle( m_macControl , &controlstyle ) ;
+        ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
     }
     else
     {
@@ -306,14 +306,14 @@ void wxControl::MacPostControlCreate()
         controlstyle.flags = kControlUseFontMask ;
         controlstyle.font = kControlFontSmallSystemFont ;
         
-        ::SetControlFontStyle( m_macControl , &controlstyle ) ;
+        ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
     }
-    ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
+    ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
     wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
-    ::EmbedControl( m_macControl , container ) ;
+    ::EmbedControl( (ControlHandle) m_macControl , container ) ;
     m_macControlIsShown  = true ;
 
-    wxAssociateControlWithMacControl( m_macControl , this ) ;
+    wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ;
 
  
      // Adjust the controls size and position
@@ -332,19 +332,19 @@ void wxControl::MacPostControlCreate()
  
      SetSize(pos.x, pos.y, new_size.x, new_size.y);
  
-     UMAShowControl( m_macControl ) ;
+     UMAShowControl( (ControlHandle) m_macControl ) ;
      Refresh() ;
 }
 
 void wxControl::MacAdjustControlRect() 
 {
-    wxASSERT_MSG( m_macControl != NULL , wxT("No valid mac control") ) ;
+    wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
     if ( m_width == -1 || m_height == -1 )
     {
         Rect    bestsize = { 0 , 0 , 0 , 0 } ;
         short   baselineoffset ;
         
-        ::GetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ;
+        ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
 
         if ( EmptyRect( &bestsize ) )
         {
@@ -388,10 +388,11 @@ void wxControl::MacAdjustControlRect()
             m_height += 2 * m_macVerticalBorder;
         }
         
-        UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height -  2 * m_macVerticalBorder ) ;
+        UMASizeControl( (ControlHandle) m_macControl , m_width - 2 * m_macHorizontalBorder, m_height -  2 * m_macVerticalBorder ) ;
     }
 }
-ControlHandle wxControl::MacGetContainerForEmbedding() 
+
+WXWidget wxControl::MacGetContainerForEmbedding() 
 {
     if ( m_macControl )
         return m_macControl ;
@@ -401,17 +402,17 @@ ControlHandle wxControl::MacGetContainerForEmbedding()
 
 void wxControl::MacSuperChangedPosition() 
 {
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         Rect contrlRect ;       
-        GetControlBounds( m_macControl , &contrlRect ) ; 
+        GetControlBounds( (ControlHandle) m_macControl , &contrlRect ) ; 
         int former_mac_x = contrlRect.left ;
         int former_mac_y = contrlRect.top ;
         int mac_x = m_x ;
         int mac_y = m_y ;
         GetParent()->MacWindowToRootWindow( & mac_x , & mac_y ) ;
         
-        WindowRef rootwindow = MacGetRootWindow() ;
+        WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
 
         if ( mac_x + m_macHorizontalBorder != former_mac_x || 
             mac_y + m_macVerticalBorder != former_mac_y )
@@ -420,7 +421,7 @@ void wxControl::MacSuperChangedPosition()
                 Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ;
                 InvalWindowRect( rootwindow , &inval ) ;
             }
-            UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ;
+            UMAMoveControl( (ControlHandle) m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ;
             {
                 Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
                 InvalWindowRect( rootwindow , &inval ) ;
@@ -439,13 +440,13 @@ void wxControl::MacSuperEnabled( bool enabled )
 
 void  wxControl::MacSuperShown( bool show ) 
 {
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         if ( !show )
         {
             if ( m_macControlIsShown )
             {
-                ::UMAHideControl( m_macControl ) ;
+                ::UMAHideControl( (ControlHandle) m_macControl ) ;
                 m_macControlIsShown = false ;
             }
         }
@@ -453,7 +454,7 @@ void  wxControl::MacSuperShown( bool show )
         {
             if ( MacIsReallyShown() && !m_macControlIsShown )
             {
-                ::UMAShowControl( m_macControl ) ;
+                ::UMAShowControl( (ControlHandle) m_macControl ) ;
                 m_macControlIsShown = true ;
             }
         }
@@ -466,7 +467,7 @@ void  wxControl::DoSetSize(int x, int y,
             int width, int height,
             int sizeFlags )
 {
-    if ( m_macControl == NULL )
+    if ( (ControlHandle) m_macControl == NULL )
     {
         wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
         return ;
@@ -515,7 +516,7 @@ void  wxControl::DoSetSize(int x, int y,
      if(GetParent()) {
          GetParent()->MacWindowToRootWindow(&mac_x, &mac_y);
      }
-     GetControlBounds(m_macControl, &oldbounds);
+     GetControlBounds( (ControlHandle) m_macControl, &oldbounds);
      oldbounds.right = oldbounds.left + m_width;
      oldbounds.bottom = oldbounds.top + m_height;
  
@@ -556,7 +557,7 @@ void  wxControl::DoSetSize(int x, int y,
              m_x = new_x;
              m_y = new_y;
  
-             UMAMoveControl(m_macControl,
+             UMAMoveControl( (ControlHandle) m_macControl,
                             mac_x + m_macHorizontalBorder, mac_y + m_macVerticalBorder);
 
              wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
@@ -568,7 +569,7 @@ void  wxControl::DoSetSize(int x, int y,
              m_width = new_width;
              m_height = new_height;
  
-             UMASizeControl( m_macControl,
+             UMASizeControl( (ControlHandle) m_macControl,
                              m_width - 2 * m_macHorizontalBorder,
                              m_height -  2 * m_macVerticalBorder ) ;
  
@@ -587,13 +588,13 @@ bool  wxControl::Show(bool show)
     if ( !wxWindow::Show( show ) )
         return FALSE ;
         
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         if ( !show )
         {
             if ( m_macControlIsShown )
             {
-                ::UMAHideControl( m_macControl ) ;
+                ::UMAHideControl( (ControlHandle) m_macControl ) ;
                 m_macControlIsShown = false ;
             }
         }
@@ -601,7 +602,7 @@ bool  wxControl::Show(bool show)
         {
             if ( MacIsReallyShown() && !m_macControlIsShown )
             {
-                ::UMAShowControl( m_macControl ) ;
+                ::UMAShowControl( (ControlHandle) m_macControl ) ;
                 m_macControlIsShown = true ;
             }
         }
@@ -614,12 +615,12 @@ bool  wxControl::Enable(bool enable)
     if ( !wxWindow::Enable(enable) )
         return FALSE;
 
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         if ( enable )
-            UMAActivateControl( m_macControl ) ;
+            UMAActivateControl( (ControlHandle) m_macControl ) ;
         else
-            UMADeactivateControl( m_macControl ) ;
+            UMADeactivateControl( (ControlHandle) m_macControl ) ;
     }
     return TRUE ;
 }
@@ -631,7 +632,7 @@ void wxControl::Refresh(bool eraseBack, const wxRect *rect)
 
 void wxControl::MacRedrawControl()
 {
-    if ( m_macControl && MacGetRootWindow() )
+    if ( (ControlHandle) m_macControl && MacGetRootWindow() )
     {
         wxClientDC dc(this) ;
         wxMacPortSetter helper(&dc) ;
@@ -643,13 +644,13 @@ void wxControl::MacRedrawControl()
         Rect r = { 0 , 0 , 32000 , 32000 } ;
         ClipRect( &r ) ;
         wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
-        UMADrawControl( m_macControl ) ;
+        UMADrawControl( (ControlHandle) m_macControl ) ;
     }
 }
 
 void wxControl::OnPaint(wxPaintEvent& event)
 {
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         wxPaintDC dc(this) ;
         wxMacPortSetter helper(&dc) ;
@@ -661,7 +662,7 @@ void wxControl::OnPaint(wxPaintEvent& event)
         ClipRect( &r ) ;
 
         wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
-        UMADrawControl( m_macControl ) ;
+        UMADrawControl( (ControlHandle) m_macControl ) ;
     }
     else
     {
@@ -676,21 +677,21 @@ void wxControl::OnEraseBackground(wxEraseEvent& event)
 
 void  wxControl::OnKeyDown( wxKeyEvent &event ) 
 {
-    if ( m_macControl == NULL )
+    if ( (ControlHandle) m_macControl == NULL )
         return ;
     
-    EventRecord *ev = wxTheApp->MacGetCurrentEvent() ;
+    EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
     short keycode ;
     short keychar ;
     keychar = short(ev->message & charCodeMask);
     keycode = short(ev->message & keyCodeMask) >> 8 ;
 
-    ::HandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ;
+    ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
 }
 
 void  wxControl::OnMouseEvent( wxMouseEvent &event ) 
 {
-    if ( m_macControl == NULL )
+    if ( (ControlHandle) m_macControl == NULL )
     {
         event.Skip() ;
         return ;
@@ -707,7 +708,7 @@ void  wxControl::OnMouseEvent( wxMouseEvent &event )
         ControlHandle   control ;
         Point       localwhere ;
         SInt16      controlpart ;
-        WindowRef   window = MacGetRootWindow() ;
+        WindowRef   window = (WindowRef) MacGetRootWindow() ;
         
         localwhere.h = x ;
         localwhere.v = y ;
@@ -742,7 +743,7 @@ void  wxControl::OnMouseEvent( wxMouseEvent &event )
                 SetFocus() ;
             }
         */
-            control = m_macControl ;
+            control = (ControlHandle) m_macControl ;
             if ( control && ::IsControlActive( control ) )
             {
                 {
@@ -762,15 +763,15 @@ void  wxControl::OnMouseEvent( wxMouseEvent &event )
 
 bool wxControl::MacCanFocus() const
 {
-        { if ( m_macControl == NULL ) 
+        { if ( (ControlHandle) m_macControl == NULL ) 
                 return true ; 
             else
             return false ; 
         }
 }
 
-void wxControl::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
-    wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+    wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
 }
 
diff --git a/src/mac/carbon/cursor.cpp b/src/mac/carbon/cursor.cpp
index fa0bbf76b2..c65a32ecb1 100644
--- a/src/mac/carbon/cursor.cpp
+++ b/src/mac/carbon/cursor.cpp
@@ -15,6 +15,7 @@
 
 #include "wx/cursor.h"
 #include "wx/icon.h"
+#include "wx/mac/private.h"
 
 #if !USE_SHARED_LIBRARIES
 IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
@@ -195,8 +196,8 @@ void wxCursor::MacInstall() const
 {
 	if ( m_refData && M_CURSORDATA->m_hCursor )
 	{
-		::SetCursor( *M_CURSORDATA->m_hCursor ) ;
-		gMacCurrentCursor = M_CURSORDATA->m_hCursor ;
+		::SetCursor(  *((CursHandle)M_CURSORDATA->m_hCursor) ) ;
+		gMacCurrentCursor = (CursHandle)M_CURSORDATA->m_hCursor ;
 	}
 	else
 	{
diff --git a/src/mac/carbon/dataobj.cpp b/src/mac/carbon/dataobj.cpp
index ff91434d91..bffbbe55e9 100644
--- a/src/mac/carbon/dataobj.cpp
+++ b/src/mac/carbon/dataobj.cpp
@@ -33,6 +33,7 @@
 #include "wx/dataobj.h"
 #include "wx/mstream.h"
 #include "wx/image.h"
+#include "wx/mac/private.h"
 
 // ----------------------------------------------------------------------------
 // functions
diff --git a/src/mac/carbon/dc.cpp b/src/mac/carbon/dc.cpp
index 59472ddfa5..5e62998da3 100644
--- a/src/mac/carbon/dc.cpp
+++ b/src/mac/carbon/dc.cpp
@@ -20,6 +20,8 @@
 #include "wx/region.h"
 #include "wx/image.h"
 
+#include "wx/mac/private.h"
+
 #if __MSL__ >= 0x6000
 #include "math.h"
 #endif
@@ -42,6 +44,10 @@ IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
 const double M_PI = 3.14159265358979 ;
 #endif
 const double RAD2DEG  = 180.0 / M_PI;
+const short kEmulatedMode = -1 ;
+const short kUnsupportedMode = -2 ;
+
+#define wxMAC_EXPERIMENTAL_PATTERN 0
 
 //-----------------------------------------------------------------------------
 // Local functions
@@ -55,6 +61,95 @@ static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
 // wxDC
 //-----------------------------------------------------------------------------
 
+// this function emulates all wx colour manipulations, used to verify the implementation
+// by setting the mode in the blitting functions to kEmulatedMode
+
+void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColor &dstColor ) ;
+void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColor &dstColor )
+{
+    switch ( logical_func )
+    {
+    	case wxAND:        // src AND dst
+    	    dstColor.red = dstColor.red & srcColor.red ;
+    	    dstColor.green = dstColor.green & srcColor.green ;
+    	    dstColor.blue = dstColor.blue & srcColor.blue ;
+    	    break ;
+    	case wxAND_INVERT: // (NOT src) AND dst
+    	    dstColor.red = dstColor.red & ~srcColor.red ;
+    	    dstColor.green = dstColor.green & ~srcColor.green ;
+    	    dstColor.blue = dstColor.blue & ~srcColor.blue ;
+    	    break ;
+    	case wxAND_REVERSE:// src AND (NOT dst)
+    	    dstColor.red = ~dstColor.red & srcColor.red ;
+    	    dstColor.green = ~dstColor.green & srcColor.green ;
+    	    dstColor.blue = ~dstColor.blue & srcColor.blue ;
+    	    break ;
+    	case wxCLEAR:      // 0
+    	    dstColor.red = 0 ;
+    	    dstColor.green = 0 ;
+    	    dstColor.blue = 0 ;
+    	    break ;
+        case wxCOPY:       // src
+    	    dstColor.red = srcColor.red ;
+    	    dstColor.green = srcColor.green ;
+    	    dstColor.blue = srcColor.blue ;
+    		break ;
+    	case wxEQUIV:      // (NOT src) XOR dst
+    	    dstColor.red = dstColor.red ^ ~srcColor.red ;
+    	    dstColor.green = dstColor.green ^ ~srcColor.green ;
+    	    dstColor.blue = dstColor.blue ^ ~srcColor.blue ;
+    	    break ;
+    	case wxINVERT:     // NOT dst
+    	    dstColor.red = ~dstColor.red ;
+    	    dstColor.green = ~dstColor.green ;
+    	    dstColor.blue = ~dstColor.blue ;
+    		break ;
+    	case wxNAND:       // (NOT src) OR (NOT dst)
+    	    dstColor.red = ~dstColor.red | ~srcColor.red ;
+    	    dstColor.green = ~dstColor.green | ~srcColor.green ;
+    	    dstColor.blue = ~dstColor.blue | ~srcColor.blue ;
+    	    break ;
+    	case wxNOR:        // (NOT src) AND (NOT dst)
+    	    dstColor.red = ~dstColor.red & ~srcColor.red ;
+    	    dstColor.green = ~dstColor.green & ~srcColor.green ;
+    	    dstColor.blue = ~dstColor.blue & ~srcColor.blue ;
+    	    break ;
+    	case wxNO_OP:      // dst
+    	    break ;
+    	case wxOR:         // src OR dst
+    	    dstColor.red = dstColor.red | srcColor.red ;
+    	    dstColor.green = dstColor.green | srcColor.green ;
+    	    dstColor.blue = dstColor.blue | srcColor.blue ;
+    	    break ;
+    	case wxOR_INVERT:  // (NOT src) OR dst
+    	    dstColor.red = dstColor.red | ~srcColor.red ;
+    	    dstColor.green = dstColor.green | ~srcColor.green ;
+    	    dstColor.blue = dstColor.blue | ~srcColor.blue ;
+    	    break ;
+    	case wxOR_REVERSE: // src OR (NOT dst)
+    	    dstColor.red = ~dstColor.red | srcColor.red ;
+    	    dstColor.green = ~dstColor.green | srcColor.green ;
+    	    dstColor.blue = ~dstColor.blue | srcColor.blue ;
+    		break ;
+    	case wxSET:        // 1
+    	    dstColor.red = 0xFFFF ;
+    	    dstColor.green = 0xFFFF ;
+    	    dstColor.blue = 0xFFFF ;
+    	    break ;
+    	case wxSRC_INVERT: // (NOT src)
+    	    dstColor.red = ~srcColor.red ;
+    	    dstColor.green = ~srcColor.green ;
+    	    dstColor.blue = ~srcColor.blue ;
+    		break ;
+    	case wxXOR:        // src XOR dst
+    	    dstColor.red = dstColor.red ^ srcColor.red ;
+    	    dstColor.green = dstColor.green ^ srcColor.green ;
+    	    dstColor.blue = dstColor.blue ^ srcColor.blue ;
+    		break ;
+    }
+
+}
+
 wxDC::wxDC()
 {
   m_ok = FALSE;
@@ -78,9 +173,6 @@ wxDC::wxDC()
   m_needComputeScaleX = FALSE;
   m_needComputeScaleY = FALSE;
   
-  m_maxX = m_maxY = -100000;
-  m_minY = m_minY =  100000;
-
   m_macPort = NULL ;
   m_macMask = NULL ;
   m_ok = FALSE ;
@@ -89,19 +181,19 @@ wxDC::wxDC()
 	m_macBrushInstalled = false ;
 	m_macPenInstalled = false ;
 	
-	m_macLocalOrigin.h = m_macLocalOrigin.v = 0 ;
+	m_macLocalOrigin.x = m_macLocalOrigin.y = 0 ;
 	m_macBoundaryClipRgn = NewRgn() ;
 	m_macCurrentClipRgn = NewRgn() ;
 
-	SetRectRgn( m_macBoundaryClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
-	SetRectRgn( m_macCurrentClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
+	SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
+	SetRectRgn( (RgnHandle) m_macCurrentClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
 
     m_pen = *wxBLACK_PEN;
     m_font = *wxNORMAL_FONT;
     m_brush = *wxWHITE_BRUSH;
 }
 wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) :
-	m_ph( dc->m_macPort ) 
+	m_ph( (GrafPtr) dc->m_macPort ) 
 {
 	wxASSERT( dc->Ok() ) ;
 	
@@ -114,12 +206,12 @@ wxMacPortSetter::~wxMacPortSetter()
 
 wxDC::~wxDC(void)
 {
-  DisposeRgn( m_macBoundaryClipRgn ) ;
-  DisposeRgn( m_macCurrentClipRgn ) ;
+    DisposeRgn( (RgnHandle) m_macBoundaryClipRgn ) ;
+    DisposeRgn( (RgnHandle) m_macCurrentClipRgn ) ;
 }
-void wxDC::MacSetupPort(AGAPortHelper* help) const
+void wxDC::MacSetupPort(wxMacPortStateHelper* help) const
 {
-	SetClip( m_macCurrentClipRgn);
+	SetClip( (RgnHandle) m_macCurrentClipRgn);
 
 	m_macFontInstalled = false ;
 	m_macBrushInstalled = false ;
@@ -159,18 +251,18 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
      if ( bmp.GetBitmapType() == kMacBitmapTypePict ) {
          Rect bitmaprect = { 0 , 0 , hh, ww };
          ::OffsetRect( &bitmaprect, xx, yy ) ;
-         ::DrawPicture( bmp.GetPict(), &bitmaprect ) ;
+         ::DrawPicture( (PicHandle) bmp.GetPict(), &bitmaprect ) ;
     }
      else if ( bmp.GetBitmapType() == kMacBitmapTypeGrafWorld )
      {
-         GWorldPtr    bmapworld = bmp.GetHBITMAP();
+         GWorldPtr    bmapworld = MAC_WXHBITMAP( bmp.GetHBITMAP() );
          PixMapHandle bmappixels ;
  
          // Set foreground and background colours (for bitmaps depth = 1)
          if(bmp.GetDepth() == 1)
         {
-             RGBColor fore = m_textForegroundColour.GetPixel();
-             RGBColor back = m_textBackgroundColour.GetPixel();
+             RGBColor fore = MAC_WXCOLORREF(m_textForegroundColour.GetPixel());
+             RGBColor back = MAC_WXCOLORREF(m_textBackgroundColour.GetPixel());
              RGBForeColor(&fore);
              RGBBackColor(&back);
          }
@@ -192,21 +284,21 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
  
          if ( useMask && bmp.GetMask() )
          {
-             if( LockPixels(GetGWorldPixMap(bmp.GetMask()->GetMaskBitmap())))
+             if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap()))))
              {
                  CopyDeepMask
                      (
                       GetPortBitMapForCopyBits(bmapworld),
-                      GetPortBitMapForCopyBits(bmp.GetMask()->GetMaskBitmap()),
-                      GetPortBitMapForCopyBits( m_macPort ),
+                      GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())),
+                      GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
                       &source, &source, &dest, mode, NULL
                       );
-                 UnlockPixels(GetGWorldPixMap(bmp.GetMask()->GetMaskBitmap()));
+                 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())));
              }
          }
          else {
              CopyBits( GetPortBitMapForCopyBits( bmapworld ),
-                       GetPortBitMapForCopyBits( m_macPort ),
+                       GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
                        &source, &dest, mode, NULL ) ;
          }
          UnlockPixels( bmappixels ) ;
@@ -215,7 +307,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
      {
         Rect bitmaprect = { 0 , 0 , bmp.GetHeight(), bmp.GetWidth() } ;
         OffsetRect( &bitmaprect, xx, yy ) ;
-        PlotCIconHandle( &bitmaprect , atNone , ttNone , bmp.GetHICON() ) ;
+        PlotCIconHandle( &bitmaprect , atNone , ttNone , MAC_WXHICON(bmp.GetHICON()) ) ;
      }
      m_macPenInstalled = false ;
      m_macBrushInstalled = false ;
@@ -241,8 +333,8 @@ void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord hei
     ww = XLOG2DEVREL(width);
     hh = YLOG2DEVREL(height);
 
-    SetRectRgn( m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
-    SectRgn( m_macCurrentClipRgn , m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+    SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
+    SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
     
     if( m_clipping )
     {
@@ -290,12 +382,12 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region  )
     }
     else
     {
-        CopyRgn( region.GetWXHRGN() , m_macCurrentClipRgn ) ;
+        CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ;
         if ( xx != x || yy != y )
         {
-            OffsetRgn( m_macCurrentClipRgn , xx - x , yy - y ) ;
+            OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ;
         }
-        SectRgn( m_macCurrentClipRgn , m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+        SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
         if( m_clipping )
         {
             m_clipX1 = wxMax( m_clipX1 , xx );
@@ -318,7 +410,7 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region  )
 void wxDC::DestroyClippingRegion()
 {
   wxMacPortSetter helper(this) ;
-  CopyRgn( m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+  CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
   m_clipping = FALSE;
 }    
 void wxDC::DoGetSize( int* width, int* height ) const
@@ -418,15 +510,8 @@ void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
   m_signX = (xLeftRight ?  1 : -1);
   m_signY = (yBottomUp  ? -1 :  1);
   ComputeScaleAndOrigin();
-}/*
-    
-void wxDC::CalcBoundingBox( long x, long y )
-{
-  if (x < m_minX) m_minX = x;
-  if (y < m_minY) m_minY = y;
-  if (x > m_maxX) m_maxX = x;
-  if (y > m_maxY) m_maxY = y;
-}*/
+}
+
 wxSize wxDC::GetPPI() const
 {
     return wxSize(72, 72);
@@ -787,13 +872,19 @@ void  wxDC::DoDrawPolygon(int n, wxPoint points[],
 	y1 = YLOG2DEVMAC(points[0].y + yoffset);   
 	::MoveTo(x1,y1);
 
-	for (int i = 0; i < n-1; i++)
+	for (int i = 1; i < n; i++)
 	{
-		x2 = XLOG2DEVMAC(points[i+1].x + xoffset);
-		y2 = YLOG2DEVMAC(points[i+1].y + yoffset);
+		x2 = XLOG2DEVMAC(points[i].x + xoffset);
+		y2 = YLOG2DEVMAC(points[i].y + yoffset);
 		::LineTo(x2, y2);
 	}
 
+    // close the polyline if necessary
+    if ( x1 != x2 || y1 != y2 )
+    {
+        ::LineTo(x1,y1 ) ;
+    }
+    
 	ClosePoly();
 
   	if (m_brush.GetStyle() != wxTRANSPARENT)
@@ -959,82 +1050,222 @@ bool  wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
 {
     wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
     wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit  Illegal source DC"));
-    wxMacPortSetter helper(this) ;
+    
+    if ( logical_func == wxNO_OP )
+        return TRUE ;
 
-    /* TODO: use the mask origin when drawing transparently */
     if (xsrcMask == -1 && ysrcMask == -1)
     {
         xsrcMask = xsrc; ysrcMask = ysrc;
     }
 
+    // correct the parameter in case this dc does not have a mask at all
+    
+    if ( useMask && !source->m_macMask )
+        useMask = false ;
+        
+	Rect srcrect , dstrect ;
+	srcrect.top = source->YLOG2DEVMAC(ysrc) ;
+	srcrect.left = source->XLOG2DEVMAC(xsrc)  ;
+	srcrect.right = source->XLOG2DEVMAC(xsrc + width ) ;
+	srcrect.bottom = source->YLOG2DEVMAC(ysrc + height) ;
+	dstrect.top = YLOG2DEVMAC(ydest) ;
+	dstrect.left = XLOG2DEVMAC(xdest) ;
+	dstrect.bottom = YLOG2DEVMAC(ydest + height )  ;
+	dstrect.right = XLOG2DEVMAC(xdest + width ) ;
+
+    short mode = kUnsupportedMode ;
+    bool invertDestinationFirst = false ;
+    switch ( logical_func )
+    {
+		case wxAND:        // src AND dst
+		    mode = srcOr ; // ok
+		    break ;
+		case wxAND_INVERT: // (NOT src) AND dst
+		    mode = notSrcOr  ; // ok
+		    break ;
+		case wxAND_REVERSE:// src AND (NOT dst)
+		    invertDestinationFirst = true ;
+		    mode = srcOr ; 
+		    break ;
+		case wxCLEAR:      // 0
+		    mode = kEmulatedMode ; 
+		    break ;
+        case wxCOPY:       // src
+			mode = srcCopy ; // ok
+			break ;
+		case wxEQUIV:      // (NOT src) XOR dst
+		    mode = srcXor ; // ok
+		    break ;
+		case wxINVERT:     // NOT dst
+			mode = kEmulatedMode ; //or hilite ;
+			break ;
+		case wxNAND:       // (NOT src) OR (NOT dst)
+		    invertDestinationFirst = true ;
+		    mode = srcBic ; 
+		    break ;
+		case wxNOR:        // (NOT src) AND (NOT dst)
+		    invertDestinationFirst = true ;
+		    mode = notSrcOr ; 
+		    break ;
+		case wxNO_OP:      // dst
+		    mode = kEmulatedMode ; // this has already been handled upon entry
+		    break ;
+		case wxOR:         // src OR dst
+		    mode = notSrcBic ;
+		    break ;
+		case wxOR_INVERT:  // (NOT src) OR dst
+		    mode = srcBic ; 
+		    break ;
+		case wxOR_REVERSE: // src OR (NOT dst)
+		    invertDestinationFirst = true ;
+			mode = notSrcBic ;
+			break ;
+		case wxSET:        // 1
+		    mode = kEmulatedMode ; 
+		    break ;
+		case wxSRC_INVERT: // (NOT src)
+			mode = notSrcCopy ; // ok
+			break ;
+		case wxXOR:        // src XOR dst
+			mode = notSrcXor ; // ok
+			break ;
+
+        default :
+			break ;
+
+    }
+
+    if ( mode == kUnsupportedMode )
+    {
+        wxFAIL_MSG("unsupported blitting mode" )
+        return FALSE ;
+    }
+    
 	CGrafPtr			sourcePort = (CGrafPtr) source->m_macPort ;
 	PixMapHandle	bmappixels =  GetGWorldPixMap( sourcePort ) ; 
-	RGBColor	white = { 0xFFFF, 0xFFFF,0xFFFF} ;
-	RGBColor	black = { 0,0,0} ;
-	RGBColor        forecolor = m_textForegroundColour.GetPixel();
-	RGBColor        backcolor = m_textBackgroundColour.GetPixel();
-	RGBForeColor( &forecolor ) ;
-	RGBBackColor( &backcolor ) ;
-
 	if ( LockPixels(bmappixels) )
 	{
-		Rect srcrect , dstrect ;
-		srcrect.top = source->YLOG2DEVMAC(ysrc) ;
-		srcrect.left = source->XLOG2DEVMAC(xsrc)  ;
-		srcrect.right = source->XLOG2DEVMAC(xsrc + width ) ;
-		srcrect.bottom = source->YLOG2DEVMAC(ysrc + height) ;
-		dstrect.top = YLOG2DEVMAC(ydest) ;
-		dstrect.left = XLOG2DEVMAC(xdest) ;
-		dstrect.bottom = YLOG2DEVMAC(ydest + height )  ;
-		dstrect.right = XLOG2DEVMAC(xdest + width ) ;
-
-    	short  mode = (logical_func == wxCOPY ? srcCopy :
- //   	logical_func == wxCLEAR ? WHITENESS :
- //   	logical_func == wxSET ? BLACKNESS :
-   		logical_func == wxINVERT ? hilite :
-  //  	logical_func == wxAND ? MERGECOPY :
-    	logical_func == wxOR ? srcOr :
-    	logical_func == wxSRC_INVERT ? notSrcCopy :
-    	logical_func == wxXOR ? srcXor :
-  //  	logical_func == wxOR_REVERSE ? MERGEPAINT :
-  //  	logical_func == wxAND_REVERSE ? SRCERASE :
-  //  	logical_func == wxSRC_OR ? srcOr :
-  //  	logical_func == wxSRC_AND ? SRCAND :
-    		srcCopy );
+        wxMacPortSetter helper(this) ;
+        RGBColor tempColor ;
+    
+    	if ( source->GetDepth() == 1 )
+    	{
+    	    RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour.GetPixel()) ) ;
+    	    RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour.GetPixel()) ) ;
+        }
+        else
+        {
+            // the modes need this, otherwise we'll end up having really nice colors...
+    	    RGBColor	white = { 0xFFFF, 0xFFFF,0xFFFF} ;
+    	    RGBColor	black = { 0,0,0} ;
+    	    RGBForeColor( &black ) ;
+    	    RGBBackColor( &white ) ;
+        }
 
 		if ( useMask && source->m_macMask )
 		{
 		    if ( mode == srcCopy )
 		    {
-    			if ( LockPixels( GetGWorldPixMap( source->m_macMask ) ) )
+    			if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) )
     			{
     				CopyMask( GetPortBitMapForCopyBits( sourcePort ) , 
-    				            GetPortBitMapForCopyBits( source->m_macMask ) , 
-    				            GetPortBitMapForCopyBits( m_macPort ) ,
+    				            GetPortBitMapForCopyBits( MAC_WXHBITMAP(source->m_macMask) ) , 
+    				            GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
     					        &srcrect, &srcrect , &dstrect ) ;
-    				UnlockPixels( GetGWorldPixMap( source->m_macMask )  ) ;
+    				UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) )  ) ;
     			}
 		    }
 		    else
 		    {
                 RgnHandle clipRgn = NewRgn() ;
-                
-                LockPixels( GetGWorldPixMap( source->m_macMask ) ) ;
-                BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( source->m_macMask ) ) ;
-                UnlockPixels( GetGWorldPixMap( source->m_macMask ) ) ;
-                //OffsetRgn( clipRgn , -source->m_macMask->portRect.left , -source->m_macMask->portRect.top ) ;
+                LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
+                BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
+                UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
                 OffsetRgn( clipRgn , -srcrect.left + dstrect.left, -srcrect.top +  dstrect.top ) ;
-    			CopyBits( GetPortBitMapForCopyBits( sourcePort ) , 
-    			    GetPortBitMapForCopyBits( m_macPort ) ,
-    				&srcrect, &dstrect, mode, clipRgn ) ;
+                if ( mode == kEmulatedMode )
+                {
+                    Pattern pat ;
+		            ::PenPat(GetQDGlobalsBlack(&pat));
+                    if ( logical_func == wxSET )
+                    {
+                        RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
+		                ::RGBForeColor( &col  ) ;
+                        ::PaintRgn( clipRgn ) ;
+                    }
+                    else if ( logical_func == wxCLEAR )
+                    {
+                        RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
+		                ::RGBForeColor( &col  ) ;
+                        ::PaintRgn( clipRgn ) ;
+                    }
+                    else if ( logical_func == wxINVERT )
+                    {
+                        MacInvertRgn( clipRgn ) ;
+                    }
+                    else
+                    {
+                        for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )
+                        {
+                            for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )
+                            {
+                                Point dstPoint = { dstrect.top + y , dstrect.left + x } ;
+                                Point srcPoint = { srcrect.top + y , srcrect.left + x } ;
+                                if ( PtInRgn( dstPoint , clipRgn ) )
+                                {
+                                    RGBColor srcColor ;
+                                    RGBColor dstColor ;
+                                    
+                                    SetPort( (GrafPtr) sourcePort ) ;
+                                    GetCPixel(  srcPoint.h , srcPoint.v , &srcColor) ;
+                                    SetPort( (GrafPtr) m_macPort ) ;
+                                    GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
+                                    
+                                    wxMacCalculateColour( logical_func , srcColor ,  dstColor ) ;
+                                    SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
+                                }
+                            }
+                        }
+                        // wxFAIL_MSG("unimplemented emulated mode") ;
+                    }
+                }
+                else
+                {
+                    if ( invertDestinationFirst )
+                    {
+                        MacInvertRgn( clipRgn ) ;
+                    }
+        			CopyBits( GetPortBitMapForCopyBits( sourcePort ) , 
+        			    GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
+        				&srcrect, &dstrect, mode, clipRgn ) ;
+        	    }
     		    DisposeRgn( clipRgn ) ;
     		}
 		}
 		else
 		{
-			CopyBits( GetPortBitMapForCopyBits( sourcePort ) , 
-			    GetPortBitMapForCopyBits( m_macPort ) ,
-				&srcrect, &dstrect, mode, NULL ) ;
+		    if ( mode == kEmulatedMode )
+		    {
+    			CopyBits( GetPortBitMapForCopyBits( sourcePort ) , 
+    			    GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
+    				&srcrect, &dstrect, mode, NULL ) ;
+    		}
+    		else
+    		{
+                    Pattern pat ;
+		            ::PenPat(GetQDGlobalsBlack(&pat));
+                    if ( logical_func == wxSET )
+                    {
+                        RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
+		                ::RGBForeColor( &col  ) ;
+                    }
+                    else
+                    {
+                        RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
+		                ::RGBForeColor( &col  ) ;
+                    }
+                    ::PaintRect( &dstrect ) ;
+    		}
 		}
 		UnlockPixels( bmappixels ) ;
 	} 
@@ -1100,8 +1331,8 @@ void  wxDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
     // prepare to blit-with-rotate the bitmap to the DC
     wxImage image(src);
 
-    RGBColor colText = m_textForegroundColour.GetPixel();
-    RGBColor colBack = m_textBackgroundColour.GetPixel();
+    RGBColor colText = MAC_WXCOLORREF( m_textForegroundColour.GetPixel() );
+    RGBColor colBack = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel() );
 
     unsigned char *data = image.GetData();
 
@@ -1336,7 +1567,8 @@ void  wxDC::Clear(void)
 	
 	if (m_backgroundBrush.GetStyle() != wxTRANSPARENT) 
 	{
-		MacInstallBrush() ;
+        MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ;
+	
 		::EraseRect( &rect ) ;
 	}
 }
@@ -1360,8 +1592,8 @@ void wxDC::MacInstallFont() const
 		m_macBrushInstalled = false ;
 		m_macPenInstalled = false ;
 
-		RGBColor forecolor = m_textForegroundColour.GetPixel();
-		RGBColor backcolor = m_textBackgroundColour.GetPixel();
+		RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
+		RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
 		::RGBForeColor( &forecolor );
 		::RGBBackColor( &backcolor );
 	}
@@ -1380,8 +1612,8 @@ void wxDC::MacInstallFont() const
 		m_macBrushInstalled = false ;
 		m_macPenInstalled = false ;
 
-		RGBColor forecolor = m_textForegroundColour.GetPixel();
-		RGBColor backcolor = m_textBackgroundColour.GetPixel();
+		RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
+		RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
 		::RGBForeColor( &forecolor );
 		::RGBBackColor( &backcolor );
 	}
@@ -1470,8 +1702,8 @@ void wxDC::MacInstallPen() const
 //	if ( m_macPenInstalled )
 //		return ;
 
-	RGBColor forecolor = m_pen.GetColour().GetPixel();
-	RGBColor backcolor = m_backgroundBrush.GetColour().GetPixel();
+	RGBColor forecolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel());
+	RGBColor backcolor = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel());
 	::RGBForeColor( &forecolor );
 	::RGBBackColor( &backcolor );
 	
@@ -1604,7 +1836,7 @@ void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background )
         }
       case kwxMacBrushColour :
         {
-       	  ::RGBBackColor( &background.GetColour().GetPixel() );
+       	  ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) );
         	int brushStyle = background.GetStyle();
         	if (brushStyle == wxSOLID)
         		::BackPat(GetQDGlobalsWhite(&whiteColor));
@@ -1632,8 +1864,10 @@ void wxDC::MacInstallBrush() const
 //		return ;
 
 	// foreground
+	
+	bool backgroundTransparent = (GetBackgroundMode() == wxTRANSPARENT) ;
 
-	::RGBForeColor( &m_brush.GetColour().GetPixel() );
+	::RGBForeColor( &MAC_WXCOLORREF( m_brush.GetColour().GetPixel()) );
 
 	int brushStyle = m_brush.GetStyle();
 	if (brushStyle == wxSOLID)
@@ -1646,62 +1880,109 @@ void wxDC::MacInstallBrush() const
 	}
 	else if ( m_brush.GetStyle() == wxSTIPPLE || m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
 	{
+	    // we force this in order to be compliant with wxMSW
+	    backgroundTransparent = false ;
 	    // for these the text fore (and back for MASK_OPAQUE) colors are used
 	    wxBitmap* bitmap = m_brush.GetStipple() ;
 	    int width = bitmap->GetWidth() ;
 	    int height = bitmap->GetHeight() ;
-	    int depth = bitmap->GetDepth() ;
+        GWorldPtr gw = NULL ;
+
 	    if ( m_brush.GetStyle() == wxSTIPPLE )
+	        gw = MAC_WXHBITMAP(bitmap->GetHBITMAP())  ;
+	    else 
+	        gw = MAC_WXHBITMAP(bitmap->GetMask()->GetMaskBitmap()) ;
+	        
+        PixMapHandle gwpixmaphandle = GetGWorldPixMap( gw ) ;
+        LockPixels( gwpixmaphandle ) ;
+
+	    bool isMonochrome = !IsPortColor( gw ) ;
+
+        if ( !isMonochrome )
+        {
+            if ( (**gwpixmaphandle).pixelSize == 1 )
+                isMonochrome = true ;
+        }
+
+
+	    if ( isMonochrome )
 	    {
-	        GWorldPtr gw = bitmap->GetHBITMAP() ;
-	        if ( width == 8 && height == 8 && depth == 1)
-	        {
-	            Pattern pat ;
-                LockPixels( GetGWorldPixMap( gw ) ) ;
-                BitMap* gwbitmap = (BitMap*) *GetGWorldPixMap( gw ) ; // since the color depth is 1 it is a BitMap
-	            int alignment = gwbitmap->rowBytes & 0x7FFF ;
-                UInt8 *gwbits = (UInt8*) gwbitmap->baseAddr ;
+	        ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) );
+
+            BitMap* gwbitmap = (BitMap*) *gwpixmaphandle ; // since the color depth is 1 it is a BitMap
+            UInt8 *gwbits = (UInt8*) gwbitmap->baseAddr ;
+            int alignment = gwbitmap->rowBytes & 0x7FFF ;
+
+    	    if( width == 8 && height == 8 )
+    	    {
+                Pattern pat ;
                 for ( int i = 0 ; i < 8 ; ++i )
                 {
                     pat.pat[i] = gwbits[i*alignment+0] ;
                 }
                 UnlockPixels( GetGWorldPixMap( gw ) ) ;
-	            
-	            ::PenPat( &pat ) ;
-	        }
-	        else
-	        {
-		        ::PenPat(GetQDGlobalsBlack(&blackColor));
-		    }
+                ::PenPat( &pat ) ;
+    	    }
+    	    else
+    	    {
+ #if wxMAC_EXPERIMENTAL_PATTERN
+ // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
+ // caching scheme before putting this into production
+            	Handle      image;
+            	long		imageSize;
+    	        PixPatHandle pixpat = NewPixPat() ;
+
+		        CopyPixMap(gwpixmaphandle, (**pixpat).patMap);
+	            imageSize = GetPixRowBytes((**pixpat).patMap) *
+				    ((**(**pixpat).patMap).bounds.bottom -
+				    (**(**pixpat).patMap).bounds.top);
+				
+	            PtrToHand( (**gwpixmaphandle).baseAddr, &image, imageSize );
+	            (**pixpat).patData = image;
+	            CTabHandle ctable = ((**((**pixpat).patMap)).pmTable) ;
+	            ColorSpecPtr ctspec = (ColorSpecPtr) &(**ctable).ctTable ;
+	            if ( ctspec[0].rgb.red == 0x0000 )
+	            {
+	                ctspec[1].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ;
+	                ctspec[0].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ;
+	            }
+	            else
+	            {
+	                ctspec[0].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ;
+	                ctspec[1].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ;
+	            }
+	            ::CTabChanged( ctable ) ;
+	            ::PenPixPat(pixpat);
+#endif
+    	    }
 	    }
-	    else if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
+	    else
 	    {
-	        ::RGBForeColor( &m_textForegroundColour.GetPixel() );
-	        ::RGBForeColor( &m_textBackgroundColour.GetPixel() );
-		    ::PenPat(GetQDGlobalsBlack(&blackColor));
 	    }
+	    UnlockPixels( gwpixmaphandle ) ;
 	}
     else
     {
 	    ::PenPat(GetQDGlobalsBlack(&blackColor));
 	}
-
-	
-	// background
 	
-    MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ;
-	
-
-	// todo :
+    if ( !backgroundTransparent )
+        ::RGBBackColor( &MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ) ;
 	
 	short mode = patCopy ;
 	switch( m_logicalFunction )
 	{
 		case wxCOPY:       // src
-			mode = patCopy ;
+		    if ( backgroundTransparent )
+		        mode = patOr ;
+		    else
+			    mode = patCopy ;
 			break ;
 		case wxINVERT:     // NOT dst
-			::PenPat(GetQDGlobalsBlack(&blackColor));
+		    if ( !backgroundTransparent )
+		    {
+			    ::PenPat(GetQDGlobalsBlack(&blackColor));
+			}
 			mode = patXor ;
 			break ;
 		case wxXOR:        // src XOR dst
diff --git a/src/mac/carbon/dcclient.cpp b/src/mac/carbon/dcclient.cpp
index 467bc66238..eb9d6e467b 100644
--- a/src/mac/carbon/dcclient.cpp
+++ b/src/mac/carbon/dcclient.cpp
@@ -19,6 +19,7 @@
 #include "wx/window.h"
 #include "wx/toplevel.h"
 #include <math.h>
+#include "wx/mac/private.h"
 
 //-----------------------------------------------------------------------------
 // constants
@@ -49,16 +50,16 @@ wxWindowDC::wxWindowDC()
 wxWindowDC::wxWindowDC(wxWindow *the_canvas) 
 {
 	wxTopLevelWindowMac* rootwindow = the_canvas->MacGetTopLevelWindow() ;
-	WindowRef windowref = rootwindow->MacGetWindowRef() ;
+	WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
 	
 	int x , y ;
 	x = y = 0 ;
 	the_canvas->MacWindowToRootWindow( &x , &y ) ;
-	m_macLocalOrigin.h = x ;
-	m_macLocalOrigin.v = y ;
-	CopyRgn( the_canvas->MacGetVisibleRegion().GetWXHRGN() , m_macBoundaryClipRgn ) ;
-	OffsetRgn( m_macBoundaryClipRgn , m_macLocalOrigin.h , m_macLocalOrigin.v ) ;
-	CopyRgn( m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+	m_macLocalOrigin.x = x ;
+	m_macLocalOrigin.y = y ;
+	CopyRgn( (RgnHandle) the_canvas->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
+	OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
+	CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
 	m_macPort = UMAGetWindowPort( windowref ) ;
 	m_minY = m_minX =  0;
 	wxSize size = the_canvas->GetSize() ;
@@ -84,20 +85,20 @@ wxClientDC::wxClientDC()
 wxClientDC::wxClientDC(wxWindow *window)
 {
 	wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
-	WindowRef windowref = rootwindow->MacGetWindowRef() ;
+	WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
 	wxPoint origin = window->GetClientAreaOrigin() ;
 	wxSize size = window->GetClientSize() ;
 	int x , y ;
 	x = origin.x ;
 	y = origin.y ;
 	window->MacWindowToRootWindow( &x , &y ) ;
-	m_macLocalOrigin.h = x ;
-	m_macLocalOrigin.v = y ;
-	SetRectRgn( m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
-	SectRgn( m_macBoundaryClipRgn , window->MacGetVisibleRegion().GetWXHRGN() , m_macBoundaryClipRgn ) ;
-	OffsetRgn( m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
-	OffsetRgn( m_macBoundaryClipRgn , m_macLocalOrigin.h , m_macLocalOrigin.v ) ;
-	CopyRgn( m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+	m_macLocalOrigin.x = x ;
+	m_macLocalOrigin.y = y ;
+	SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
+	SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
+	OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
+	OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
+	CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle)  m_macCurrentClipRgn ) ;
 	m_macPort = UMAGetWindowPort( windowref ) ;
 	m_minY = m_minX =  0;
 	m_maxX = size.x  ;
@@ -122,21 +123,21 @@ wxPaintDC::wxPaintDC()
 wxPaintDC::wxPaintDC(wxWindow *window)
 {
 	wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
-	WindowRef windowref = rootwindow->MacGetWindowRef() ;
+	WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
 	wxPoint origin = window->GetClientAreaOrigin() ;
 	wxSize size = window->GetClientSize() ;
 	int x , y ;
 	x = origin.x ;
 	y = origin.y ;
 	window->MacWindowToRootWindow( &x , &y ) ;
-	m_macLocalOrigin.h = x ;
-	m_macLocalOrigin.v = y ;
-	SetRectRgn( m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
-	SectRgn( m_macBoundaryClipRgn , window->MacGetVisibleRegion().GetWXHRGN() , m_macBoundaryClipRgn ) ;
-	OffsetRgn( m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
-  SectRgn( m_macBoundaryClipRgn  , window->GetUpdateRegion().GetWXHRGN() , m_macBoundaryClipRgn ) ;
-	OffsetRgn( m_macBoundaryClipRgn , m_macLocalOrigin.h , m_macLocalOrigin.v ) ;
-	CopyRgn( m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+	m_macLocalOrigin.x = x ;
+	m_macLocalOrigin.y = y ;
+	SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
+	SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
+	OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
+  SectRgn( (RgnHandle) m_macBoundaryClipRgn  , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
+	OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
+	CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
 	m_macPort = UMAGetWindowPort( windowref ) ;
 	m_minY = m_minX =  0;
 	m_maxX = size.x  ;
diff --git a/src/mac/carbon/dcmemory.cpp b/src/mac/carbon/dcmemory.cpp
index 85f1af33c5..ad67ca77c0 100644
--- a/src/mac/carbon/dcmemory.cpp
+++ b/src/mac/carbon/dcmemory.cpp
@@ -14,6 +14,7 @@
 #endif
 
 #include "wx/dcmemory.h"
+#include "wx/mac/private.h"
 
 //-----------------------------------------------------------------------------
 // wxMemoryDC
@@ -43,7 +44,7 @@ wxMemoryDC::~wxMemoryDC()
 {
 	if ( m_selected.Ok() )
 	{
- 		UnlockPixels( GetGWorldPixMap(m_selected.GetHBITMAP()) );
+ 		UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
 	}
 };
 
@@ -51,7 +52,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
 {
 	if ( m_selected.Ok() )
 	{
- 		UnlockPixels( GetGWorldPixMap(m_selected.GetHBITMAP()) );
+ 		UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
 	}
     m_selected = bitmap;
     if (m_selected.Ok())
diff --git a/src/mac/carbon/dcprint.cpp b/src/mac/carbon/dcprint.cpp
index 36d8757f67..e81573f6bc 100644
--- a/src/mac/carbon/dcprint.cpp
+++ b/src/mac/carbon/dcprint.cpp
@@ -63,9 +63,9 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
 	}
 	
 #if !TARGET_CARBON
-	if ( ::PrValidate( m_printData.m_macPrintInfo ) )
+	if ( ::PrValidate( (THPrint) m_printData.m_macPrintInfo ) )
 	{
-		::PrStlDialog( m_printData.m_macPrintInfo ) ;
+		::PrStlDialog( (THPrint) m_printData.m_macPrintInfo ) ;
 		// the driver has changed in the mean time, should we pop up a page setup dialog ?
 	}
 	err = PrError() ;
@@ -79,7 +79,7 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
 		return;
 	}
 	::GetPort( &macPrintFormerPort ) ;
-	m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ;
+	m_macPrintPort = ::PrOpenDoc( (THPrint) m_printData.m_macPrintInfo , NULL , NULL ) ;
 	err = PrError() ;
 	if ( err )
 	{
@@ -143,8 +143,8 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
 	m_maxX = rPaper.right - rPaper.left ;
 	m_maxY = rPaper.bottom - rPaper.top ;
 #else
-	m_maxX = (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ;
-	m_maxY = (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ;
+	m_maxX = (**(THPrint)m_printData.m_macPrintInfo).rPaper.right - (**(THPrint)m_printData.m_macPrintInfo).rPaper.left ;
+	m_maxY = (**(THPrint)m_printData.m_macPrintInfo).rPaper.bottom - (**(THPrint)m_printData.m_macPrintInfo).rPaper.top ;
 #endif
 }
 
@@ -155,15 +155,15 @@ wxPrinterDC::~wxPrinterDC(void)
 #if !TARGET_CARBON
 	if ( m_ok )
 	{
-		::PrCloseDoc( m_macPrintPort  ) ;
+		::PrCloseDoc( (TPPrPort) m_macPrintPort  ) ;
 		err = PrError() ;
 		
 		if ( err == noErr )
 		{
-			if ( (**m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop )
+			if ( (**(THPrint)m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop )
 			{
 				TPrStatus status ;
-				::PrPicFile( m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ;
+				::PrPicFile( (THPrint) m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ;
 			}
 		}
 		else
@@ -233,9 +233,9 @@ void wxPrinterDC::StartPage(void)
 	wxString message ;
 
 #if !TARGET_CARBON
-  	PrOpenPage( m_macPrintPort , NULL ) ;
-  	m_macLocalOrigin.h =  (**m_printData.m_macPrintInfo).rPaper.left ;
-  	m_macLocalOrigin.v =  (**m_printData.m_macPrintInfo).rPaper.top ;
+  	PrOpenPage( (TPPrPort) m_macPrintPort , NULL ) ;
+  	m_macLocalOrigin.x =  (**(THPrint)m_printData.m_macPrintInfo).rPaper.left ;
+  	m_macLocalOrigin.y =  (**(THPrint)m_printData.m_macPrintInfo).rPaper.top ;
   	
 	Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
 	::ClipRect( &clip ) ;
@@ -245,8 +245,8 @@ void wxPrinterDC::StartPage(void)
 		message.Printf( "Print Error %d", err ) ;
 		wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
 		dialog.ShowModal();
-   		::PrClosePage( m_macPrintPort ) ;
-		::PrCloseDoc( m_macPrintPort ) ;
+   		::PrClosePage( (TPPrPort) m_macPrintPort ) ;
+		::PrCloseDoc( (TPPrPort) m_macPrintPort ) ;
 		::UMAPrClose() ;
 	   	::SetPort( macPrintFormerPort ) ;
 	   	m_ok = FALSE ;
@@ -288,14 +288,14 @@ void wxPrinterDC::EndPage(void)
 	wxString message ;
 
 #if !TARGET_CARBON
-   	PrClosePage(  (TPrPort*) m_macPort ) ;
+   	PrClosePage(  (TPPrPort) m_macPort ) ;
 	err = PrError() ;
 	if ( err != noErr )
 	{
 		message.Printf( "Print Error %d", err ) ;
 		wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
 		dialog.ShowModal();
-		::PrCloseDoc( m_macPrintPort  ) ;
+		::PrCloseDoc( (TPPrPort) m_macPrintPort  ) ;
 		::UMAPrClose() ;
 	   	::SetPort( macPrintFormerPort ) ;
 	   	m_ok = FALSE ;
diff --git a/src/mac/carbon/dirdlg.cpp b/src/mac/carbon/dirdlg.cpp
index 83533f1236..079663908a 100644
--- a/src/mac/carbon/dirdlg.cpp
+++ b/src/mac/carbon/dirdlg.cpp
@@ -20,6 +20,8 @@
 
 #include "wx/cmndata.h"
 
+#include "wx/mac/private.h"
+
 #ifdef __DARWIN__
   #include <Carbon/Carbon.h>
 #else
@@ -30,423 +32,11 @@
 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
 #endif
 
-bool gUseNavServices = NavServicesAvailable() ;
-
-// the data we need to pass to our standard file hook routine
-// includes a pointer to the dialog, a pointer to the standard
-// file reply record (so we can inspect the current selection)
-// and a copy of the "previous" file spec of the reply record
-// so we can see if the selection has changed
-
-#if !TARGET_CARBON
-
-struct UserDataRec {
-	StandardFileReply	*sfrPtr;
-	FSSpec				oldSelectionFSSpec;
-	DialogPtr			theDlgPtr;
-};
-typedef struct UserDataRec
-	UserDataRec, *UserDataRecPtr;
-
-enum {
-	kSelectItem = 10, 			// select button item number
-	kSFGetFolderDlgID = 250,	// dialog resource number
-	kStrListID = 250,			// our strings
-	kSelectStrNum = 1,			// word 'Select: ' for button
-	kDesktopStrNum = 2,			// word 'Desktop' for button
-	kSelectNoQuoteStrNum = 3,	// word 'Select: ' for button
-	
-	kUseQuotes = true,			// parameter for SetButtonName
-	kDontUseQuotes = false
-};
-
-
-static void GetLabelString(StringPtr theStr, short stringNum)
-{
-	GetIndString(theStr, kStrListID, stringNum);
-}
-
-static void CopyPStr(StringPtr src, StringPtr dest)
-{
-	BlockMoveData(src, dest, 1 + src[0]);
-}
-
-static char GetSelectKey(void)
-{
-	// this is the key used to trigger the select button
-	
-	// NOT INTERNATIONAL SAVVY; should at least grab it from resources
-	
-	return 's';
-}
-
-
-// SetButtonName sets the name of the Select button in the dialog
-//
-// To do this, we need to call the Script Manager to truncate the
-// label in the middle to fit the button and to merge the button
-// name with the word Select (possibly followed by quotes).  Using
-// the Script Manager avoids all sorts of problems internationally.
-//
-// buttonName is the name to appear following the word Select
-// quoteFlag should be true if the name is to appear in quotes
-
-static void SetButtonName(DialogPtr theDlgPtr, short buttonID, StringPtr buttonName,
-					Boolean quoteFlag)
-{
-	short 	buttonType;
-	Handle	buttonHandle;
-	Rect	buttonRect;
-	short	textWidth;
-	Handle	labelHandle;
-	Handle	nameHandle;
-	Str15	keyStr;
-	Str255	labelStr;
-	OSErr	err;
-	
-	nameHandle = nil;
-	labelHandle = nil;
-	
-	// get the details of the button from the dialog
-	
-	GetDialogItem(theDlgPtr, buttonID, &buttonType, &buttonHandle, &buttonRect);
-	
-	// get the string for the select button label, "Select ^0" or "Select Ò^0Ó"
-	
-	GetLabelString(labelStr, (quoteFlag == kUseQuotes) ? kSelectStrNum : kSelectNoQuoteStrNum);
-	
-	// make string handles containing the select button label and the
-	// file name to be stuffed into the button
-	
-	err = PtrToHand(&labelStr[1], &labelHandle, labelStr[0]);
-	if (err != noErr) goto Bail;
-	
-	// cut out the middle of the file name to fit the button
-	//
-	// we'll temporarily use labelStr here to hold the modified button name
-	// since we don't own the buttonName string storage space
-	
-	textWidth = (buttonRect.right - buttonRect.left) - StringWidth(labelStr);
-
-	CopyPStr(buttonName, labelStr);
-	(void) TruncString(textWidth, labelStr, smTruncMiddle);
-	
-	err = PtrToHand(&labelStr[1], &nameHandle, labelStr[0]);
-	if (err != noErr) goto Bail;
-	
-	// replace the ^0 in the Select string with the file name
-	
-	CopyPStr("\p^0", keyStr);
-	
-	(void) ReplaceText(labelHandle, nameHandle, keyStr);
-	
-	labelStr[0] = (unsigned char) GetHandleSize(labelHandle);
-	BlockMoveData(*labelHandle, &labelStr[1], labelStr[0]);
-	
-	// now set the control title, and re-validate the area
-	// above the control to avoid a needless redraw
-	
-	SetControlTitle((ControlHandle) buttonHandle, labelStr);
-	
-	ValidRect(&buttonRect);
-
-Bail:
-	if (nameHandle)		DisposeHandle(nameHandle);
-	if (labelHandle)	DisposeHandle(labelHandle);
-	
-}
-
-// FlashButton briefly highlights the dialog button 
-// as feedback for key equivalents
-
-static void FlashButton(DialogPtr theDlgPtr, short buttonID)
-{
-	short	buttonType;
-	Handle	buttonHandle;
-	Rect	buttonRect;
-	unsigned long	finalTicks;
-	
-	GetDialogItem(theDlgPtr, buttonID, &buttonType, &buttonHandle, &buttonRect);
-	HiliteControl((ControlHandle) buttonHandle, kControlButtonPart);
-	Delay(10, &finalTicks);
-	HiliteControl((ControlHandle) buttonHandle, 0);
-}
-
-static Boolean SameFSSpec(FSSpecPtr spec1, FSSpecPtr spec2)
-{
-	return (spec1->vRefNum == spec2->vRefNum
-			&& spec1->parID == spec2->parID
-			&& EqualString(spec1->name, spec2->name, false, false));
-}
-// MyModalDialogFilter maps a key to the Select button, and handles
-// flashing of the button when the key is hit
-
-static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRecord *eventRec,
-											short *item, void *dataPtr)
-{
-#pragma unused (dataPtr)
-
-	// make certain the proper dialog is showing, 'cause standard file
-	// can nest dialogs but calls the same filter for each
-	
-	if (((WindowPeek) theDlgPtr)->refCon == sfMainDialogRefCon)
-	{
-		// check if the select button was hit
-		
-		if ((eventRec->what == keyDown)
-			&& (eventRec->modifiers & cmdKey) 
-			&& ((eventRec->message & charCodeMask) == GetSelectKey()))
-		{
-			*item = kSelectItem;
-			FlashButton(theDlgPtr, kSelectItem);
-			return true;
-		}
-	}
-		
-	return false;
-}
-
-
-// MyDlgHook is a hook routine that maps the select button to Open
-// and sets the Select button name
-
-static pascal short SFGetFolderDialogHook(short item, DialogPtr theDlgPtr, void *dataPtr)
-{
-	UserDataRecPtr	theUserDataRecPtr;
-	long			desktopDirID;
-	short			desktopVRefNum;
-	FSSpec			tempSpec;
-	Str63			desktopName;
-	OSErr			err;
-	
-	// be sure Std File is really showing us the intended dialog,
-	// not a nested modal dialog
-	
-	if (((WindowPeek) theDlgPtr)->refCon != sfMainDialogRefCon)
-	{
-		return item;
-	}
-	
-	theUserDataRecPtr = (UserDataRecPtr) dataPtr;
-	
-	// map the Select button to Open
-	
-	if (item == kSelectItem)
-	{
-		item = sfItemOpenButton;
-	}
-	
-	// find the desktop folder
-	
-	err = FindFolder(theUserDataRecPtr->sfrPtr->sfFile.vRefNum,
-					kDesktopFolderType, kDontCreateFolder,
-					&desktopVRefNum, &desktopDirID);
-	
-	if (err != noErr)
-	{
-		// for errors, get value that won't match any real vRefNum/dirID
-		desktopVRefNum = 0;
-		desktopDirID = 0;
-	}
-	
-	// change the Select button label if the selection has changed or
-	// if this is the first call to the hook
-	
-	if (item == sfHookFirstCall
-		|| item == sfHookChangeSelection
-		|| item == sfHookRebuildList
-		|| ! SameFSSpec(&theUserDataRecPtr->sfrPtr->sfFile,
-					&theUserDataRecPtr->oldSelectionFSSpec))
-	{
-		// be sure there is a file name selected
-		
-		if (theUserDataRecPtr->sfrPtr->sfFile.name[0] != '\0')
-		{
-			SetButtonName(theDlgPtr, kSelectItem, 
-							theUserDataRecPtr->sfrPtr->sfFile.name, 
-							kUseQuotes);	// true -> use quotes
-		}
-		else
-		{
-			// is the desktop selected?
-			
-			if (theUserDataRecPtr->sfrPtr->sfFile.vRefNum == desktopVRefNum
-				&& theUserDataRecPtr->sfrPtr->sfFile.parID == desktopDirID)
-			{
-				// set button to "Select Desktop"
-				
-				GetLabelString(desktopName, kDesktopStrNum);
-				SetButtonName(theDlgPtr, kSelectItem, 
-								desktopName, kDontUseQuotes);	// false -> no quotes
-			}
-			else
-			{
-				// get parent directory's name for the Select button
-				//
-				// passing an empty name string to FSMakeFSSpec gets the
-				// name of the folder specified by the parID parameter
-				
-				(void) FSMakeFSSpec(theUserDataRecPtr->sfrPtr->sfFile.vRefNum,
-					theUserDataRecPtr->sfrPtr->sfFile.parID, "\p",
-					&tempSpec);
-				SetButtonName(theDlgPtr, kSelectItem, 
-							tempSpec.name, kUseQuotes); // true -> use quotes
-			}
-		}
-	}
-	
-	// save the current selection as the old selection for comparison next time
-	//
-	// it's not valid on the first call, though, or if we don't have a 
-	// name available from standard file
-	
-	if (item != sfHookFirstCall || theUserDataRecPtr->sfrPtr->sfFile.name[0] != '\0')
-	{
-		theUserDataRecPtr->oldSelectionFSSpec = theUserDataRecPtr->sfrPtr->sfFile;
-	}
-	else
-	{
-		// on first call, empty string won't set the button correctly, 
-		// so invalidate oldSelection
-		
-		theUserDataRecPtr->oldSelectionFSSpec.vRefNum = 999;
-		theUserDataRecPtr->oldSelectionFSSpec.parID = 0;
-	}
-	
-	return item;
-}
-
-void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileFilterYDUPP fileFilter, StandardFileReply *theSFR)
-{
-	Point 				thePt;
-	SFTypeList			mySFTypeList;
-	UserDataRec			myData;
-	FSSpec				tempSpec;
-	Boolean				folderFlag;
-	Boolean				wasAliasedFlag;
-	DlgHookYDUPP		dlgHookUPP;
-	ModalFilterYDUPP	myModalFilterUPP;
-	OSErr				err;
-	
-	
-	// presumably we're running System 7 or later so CustomGetFile is
-	// available
-	
-	// set initial contents of Select button to a space
-	
-	memcpy(theSFR->sfFile.name, "\p ", 2);
-	
-	// point the user data parameter at the reply record so we can get to it later
-	
-	myData.sfrPtr = theSFR;
-	
-	// display the dialog
-	
-	#if !TARGET_CARBON
-	
-	dlgHookUPP = NewDlgHookYDProc(SFGetFolderDialogHook);
-	myModalFilterUPP = NewModalFilterYDProc(SFGetFolderModalDialogFilter);
-	
-	thePt.h = thePt.v = -1;	// center dialog
-	
-	ParamText( message , NULL , NULL , NULL ) ;
-	
-	CustomGetFile(	fileFilter, 
-					-1,					// show all types
-					mySFTypeList,
-					theSFR,
-					kSFGetFolderDlgID,
-					thePt,				// top left point
-					dlgHookUPP,
-					myModalFilterUPP,
-					nil,				// activate list
-					nil,				// activate proc
-					&myData);
-					
-	DisposeRoutineDescriptor(dlgHookUPP);
-	DisposeRoutineDescriptor(myModalFilterUPP);
-	#else
-	#endif
-	
-	// if cancel wasn't pressed and no fatal error occurred...
-	
-	if (theSFR->sfGood)
-	{
-		// if no name is in the reply record file spec,
-		// use the file spec of the parent folder
-		
-		if (theSFR->sfFile.name[0] == '\0')
-		{
-			err = FSMakeFSSpec(theSFR->sfFile.vRefNum, theSFR->sfFile.parID,
-								"\p", &tempSpec);
-			if (err == noErr)
-			{
-				theSFR->sfFile = tempSpec;
-			}
-			else
-			{
-				// no name to return, forget it
-				
-				theSFR->sfGood = false;
-			}
-		}
-		
-		// if there is now a name in the file spec, check if it's
-		// for a folder or a volume
-		
-		if (theSFR->sfFile.name[0] != '\0')
-		{
-			// the parID of the root of a disk is always fsRtParID == 1
-			
-			if (theSFR->sfFile.parID == fsRtParID)
-			{
-				theSFR->sfIsVolume = true;
-				theSFR->sfIsFolder = false;	// it would be reasonable for this to be true, too
-			}
-			
-			// we have a valid FSSpec, now let's make sure it's not for an alias file
-			
-			err = ResolveAliasFile(&theSFR->sfFile, true, &folderFlag, &wasAliasedFlag);
-			if (err != noErr)
-			{
-				theSFR->sfGood = false;
-			}
-			
-			// did the alias resolve to a folder?
-			
-			if (folderFlag  && ! theSFR->sfIsVolume)
-			{
-				theSFR->sfIsFolder = true;
-			}
-		}
-	}
-}
-
-static pascal Boolean OnlyVisibleFoldersCustomFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr)
-{
-#pragma unused (dataPtr)
-
-	// return true if this item is invisible or a file
-
-	Boolean visibleFlag;
-	Boolean folderFlag;
-	
-	visibleFlag = ! (myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible);
-	folderFlag = (myCInfoPBPtr->hFileInfo.ioFlAttrib & 0x10);
-	
-	// because the semantics of the filter proc are "true means don't show
-	// it" we need to invert the result that we return
-	
-	return !(visibleFlag && folderFlag);
-}
-
-#endif
-
-
 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
         const wxString& defaultPath,
         long style, const wxPoint& pos)
 {
+	wxASSERT_MSG( NavServicesAvailable() , "Navigation Services are not running" ) ;
     m_message = message;
     m_dialogStyle = style;
     m_parent = parent;
@@ -455,145 +45,98 @@ wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
 
 int wxDirDialog::ShowModal()
 {
-	#if !TARGET_CARBON
-	if ( !gUseNavServices )
-	{
-		Str255				prompt ;
-		Str255				path ;
-
-#if TARGET_CARBON
-		c2pstrcpy((StringPtr)prompt, m_message) ;
-#else
-		strcpy((char *)prompt, m_message) ;
-		c2pstr((char *)prompt ) ;
-#endif
-#if TARGET_CARBON
-		c2pstrcpy((StringPtr)path, m_path ) ;
-#else
-		strcpy((char *)path, m_path ) ;
-		c2pstr((char *)path ) ;
-#endif
-
-		StandardFileReply	reply ;
-		FileFilterYDUPP 	invisiblesExcludedCustomFilterUPP = 0 ;
-		invisiblesExcludedCustomFilterUPP = 
-			NewFileFilterYDProc(OnlyVisibleFoldersCustomFileFilter);
-
-
-		StandardGetFolder( prompt , path , invisiblesExcludedCustomFilterUPP, &reply);
+	NavDialogOptions		mNavOptions;
+	NavObjectFilterUPP		mNavFilterUPP = NULL;
+	NavPreviewUPP			mNavPreviewUPP = NULL ;
+	NavReplyRecord			mNavReply;
+	AEDesc*					mDefaultLocation = NULL ;
+	bool					mSelectDefault = false ;
+	
+	::NavGetDefaultDialogOptions(&mNavOptions);
+
+	mNavFilterUPP	= nil;
+	mNavPreviewUPP	= nil;
+	mSelectDefault	= false;
+	mNavReply.validRecord				= false;
+	mNavReply.replacing					= false;
+	mNavReply.isStationery				= false;
+	mNavReply.translationNeeded			= false;
+	mNavReply.selection.descriptorType = typeNull;
+	mNavReply.selection.dataHandle		= nil;
+	mNavReply.keyScript					= smSystemScript;
+	mNavReply.fileTranslation			= nil;
+	
+	// Set default location, the location
+	//   that's displayed when the dialog
+	//   first appears
+	
+	if ( mDefaultLocation ) {
+		
+		if (mSelectDefault) {
+			mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
+		} else {
+			mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
+		}
+	}
 	
+	OSErr err = ::NavChooseFolder(
+						mDefaultLocation,
+						&mNavReply,
+						&mNavOptions,
+						NULL,
+						mNavFilterUPP,
+						0L);							// User Data
+	
+	if ( (err != noErr) && (err != userCanceledErr) ) {
+		m_path = "" ;
+		return wxID_CANCEL ;
+	}
 
-		DisposeRoutineDescriptor(invisiblesExcludedCustomFilterUPP);
-
-		if ( reply.sfGood == false )
-		{
+	if (mNavReply.validRecord) {		// User chose a folder
+	
+		FSSpec	folderInfo;
+		FSSpec  outFileSpec ;
+		AEDesc specDesc ;
+		
+		OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
+		if ( err != noErr ) {
 			m_path = "" ;
 			return wxID_CANCEL ;
+		}			
+		folderInfo = **(FSSpec**) specDesc.dataHandle;
+		if (specDesc.dataHandle != nil) {
+			::AEDisposeDesc(&specDesc);
 		}
-		else
-		{
-			m_path = wxMacFSSpec2MacFilename( &reply.sfFile ) ;
-			return wxID_OK ;
-		}
-		return wxID_CANCEL;
-	}
-	else
-	#endif
-	{
-		NavDialogOptions		mNavOptions;
-		NavObjectFilterUPP		mNavFilterUPP = NULL;
-		NavPreviewUPP			mNavPreviewUPP = NULL ;
-		NavReplyRecord			mNavReply;
-		AEDesc*					mDefaultLocation = NULL ;
-		bool					mSelectDefault = false ;
-		
-		::NavGetDefaultDialogOptions(&mNavOptions);
-	
-		mNavFilterUPP	= nil;
-		mNavPreviewUPP	= nil;
-		mSelectDefault	= false;
-		mNavReply.validRecord				= false;
-		mNavReply.replacing					= false;
-		mNavReply.isStationery				= false;
-		mNavReply.translationNeeded			= false;
-		mNavReply.selection.descriptorType = typeNull;
-		mNavReply.selection.dataHandle		= nil;
-		mNavReply.keyScript					= smSystemScript;
-		mNavReply.fileTranslation			= nil;
-		
-		// Set default location, the location
-		//   that's displayed when the dialog
-		//   first appears
+
+//			mNavReply.GetFileSpec(folderInfo);
 		
-		if ( mDefaultLocation ) {
-			
-			if (mSelectDefault) {
-				mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
-			} else {
-				mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
-			}
-		}
+			// The FSSpec from NavChooseFolder is NOT the file spec
+			// for the folder. The parID field is actually the DirID
+			// of the folder itself, not the folder's parent, and
+			// the name field is empty. We must call PBGetCatInfo
+			// to get the parent DirID and folder name
 		
-		OSErr err = ::NavChooseFolder(
-							mDefaultLocation,
-							&mNavReply,
-							&mNavOptions,
-							NULL,
-							mNavFilterUPP,
-							0L);							// User Data
+		Str255		name;
+		CInfoPBRec	thePB;			// Directory Info Parameter Block
+		thePB.dirInfo.ioCompletion	= nil;
+		thePB.dirInfo.ioVRefNum		= folderInfo.vRefNum;	// Volume is right
+		thePB.dirInfo.ioDrDirID		= folderInfo.parID;		// Folder's DirID
+		thePB.dirInfo.ioNamePtr		= name;
+		thePB.dirInfo.ioFDirIndex	= -1;	// Lookup using Volume and DirID
 		
-		if ( (err != noErr) && (err != userCanceledErr) ) {
+		err = ::PBGetCatInfoSync(&thePB);
+		if ( err != noErr ) {
 			m_path = "" ;
 			return wxID_CANCEL ;
-		}
-
-		if (mNavReply.validRecord) {		// User chose a folder
-		
-			FSSpec	folderInfo;
-			FSSpec  outFileSpec ;
-			AEDesc specDesc ;
-			
-			OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
-			if ( err != noErr ) {
-				m_path = "" ;
-				return wxID_CANCEL ;
-			}			
-			folderInfo = **(FSSpec**) specDesc.dataHandle;
-			if (specDesc.dataHandle != nil) {
-				::AEDisposeDesc(&specDesc);
-			}
-
-//			mNavReply.GetFileSpec(folderInfo);
-			
-				// The FSSpec from NavChooseFolder is NOT the file spec
-				// for the folder. The parID field is actually the DirID
-				// of the folder itself, not the folder's parent, and
-				// the name field is empty. We must call PBGetCatInfo
-				// to get the parent DirID and folder name
-			
-			Str255		name;
-			CInfoPBRec	thePB;			// Directory Info Parameter Block
-			thePB.dirInfo.ioCompletion	= nil;
-			thePB.dirInfo.ioVRefNum		= folderInfo.vRefNum;	// Volume is right
-			thePB.dirInfo.ioDrDirID		= folderInfo.parID;		// Folder's DirID
-			thePB.dirInfo.ioNamePtr		= name;
-			thePB.dirInfo.ioFDirIndex	= -1;	// Lookup using Volume and DirID
-			
-			err = ::PBGetCatInfoSync(&thePB);
-			if ( err != noErr ) {
-				m_path = "" ;
-				return wxID_CANCEL ;
-			}			
-												// Create cannonical FSSpec
-			::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
-						   name, &outFileSpec);
-							
-			// outFolderDirID = thePB.dirInfo.ioDrDirID;
-			m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
-			return wxID_OK ;
-		}
-		return wxID_CANCEL;
-
+		}			
+											// Create cannonical FSSpec
+		::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
+					   name, &outFileSpec);
+						
+		// outFolderDirID = thePB.dirInfo.ioDrDirID;
+		m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
+		return wxID_OK ;
 	}
+	return wxID_CANCEL;
 }
 
diff --git a/src/mac/carbon/dirmac.cpp b/src/mac/carbon/dirmac.cpp
index c1b010f5f7..1acff5b7ca 100644
--- a/src/mac/carbon/dirmac.cpp
+++ b/src/mac/carbon/dirmac.cpp
@@ -40,6 +40,8 @@
   #include <windows.h>
 #endif
 
+#include "wx/mac/private.h"
+
 #include "MoreFiles.h"
 #include "MoreFilesExtras.h"
 
diff --git a/src/mac/carbon/dnd.cpp b/src/mac/carbon/dnd.cpp
index 2965b50d5c..e81ad045d2 100644
--- a/src/mac/carbon/dnd.cpp
+++ b/src/mac/carbon/dnd.cpp
@@ -22,6 +22,7 @@
 #include "wx/toplevel.h"
 #include "wx/app.h"
 #include "wx/gdicmn.h"
+#include "wx/mac/private.h"
 
 // ----------------------------------------------------------------------------
 // global
@@ -104,17 +105,17 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
     {
       UInt16 items ;
       OSErr result;
-      CountDragItems(m_currentDrag, &items);
+      CountDragItems((DragReference)m_currentDrag, &items);
       for (UInt16 index = 1; index <= items && supported == false ; ++index) 
       {
           ItemReference theItem;
           FlavorType theType ;
           UInt16 flavors = 0 ;
-          GetDragItemReferenceNumber(m_currentDrag, index, &theItem);
-          CountDragItemFlavors( m_currentDrag, theItem , &flavors ) ;
+          GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
+          CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
           for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
           {
-            result = GetFlavorType(m_currentDrag, theItem, flavor , &theType);
+            result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
             if ( m_dataObject->IsSupportedFormat( wxDataFormat( theType ) ) )
             {
               supported = true ;
@@ -172,31 +173,31 @@ bool wxDropTarget::GetData()
     {
       UInt16 items ;
       OSErr result;
-      CountDragItems(m_currentDrag, &items);
+      CountDragItems((DragReference)m_currentDrag, &items);
       for (UInt16 index = 1; index <= items; ++index) 
       {
           ItemReference theItem;
           FlavorType theType ;
           UInt16 flavors = 0 ;
-          GetDragItemReferenceNumber(m_currentDrag, index, &theItem);
-          CountDragItemFlavors( m_currentDrag, theItem , &flavors ) ;
+          GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
+          CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
           for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
           {
-            result = GetFlavorType(m_currentDrag, theItem, flavor , &theType);
+            result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
             wxDataFormat format(theType) ;
             if ( m_dataObject->IsSupportedFormat( format ) )
             {
               FlavorFlags theFlags;
-              result = GetFlavorFlags(m_currentDrag, theItem, theType, &theFlags);
+              result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
               if (result == noErr) 
               {
                   Size dataSize ;
                   Ptr theData ;
-                  GetFlavorDataSize(m_currentDrag, theItem, theType, &dataSize);
+                  GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
           			  if ( theType == 'TEXT' )
           			    dataSize++ ;
                   theData = new char[dataSize];
-                  GetFlavorData(m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L); 
+                  GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L); 
                   if( theType == 'TEXT' )
                   {
                     theData[dataSize]=0 ;       
@@ -335,7 +336,7 @@ wxDragResult wxDropSource::DoDragDrop( bool allowMove )
     dragRegion = NewRgn();
     RgnHandle tempRgn = NewRgn() ;
     
-    EventRecord* ev = wxTheApp->MacGetCurrentEvent() ;
+    EventRecord* ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
     const short dragRegionOuterBoundary = 10 ;
     const short dragRegionInnerBoundary = 9 ;
     
diff --git a/src/mac/carbon/filedlg.cpp b/src/mac/carbon/filedlg.cpp
index 6ca66d390f..87e7846177 100644
--- a/src/mac/carbon/filedlg.cpp
+++ b/src/mac/carbon/filedlg.cpp
@@ -31,6 +31,8 @@ IMPLEMENT_CLASS(wxFileDialog, wxDialog)
 
 // begin wxmac
 
+#include "wx/mac/private.h"
+
 #include <Navigation.h>
 
 #include "MoreFiles.h"
@@ -112,132 +114,6 @@ OSType gfiltersmac[] =
 } ;
 
 
-#if !TARGET_CARBON
-
-static void wxMacSetupStandardFile(short newVRefNum, long newDirID) 
-{ 
-	enum 
-	{ SFSaveDisk = 0x214, CurDirStore = 0x398 };
-	*(short *) SFSaveDisk = -1 * newVRefNum; 
-	*(long *) CurDirStore = newDirID; 
-}
-
-static void wxMacSetupStandardFileFromPath( const char* s )
-{
-	Str255	volume ;
-	Str255	path ;
-	short	vRefNum ;
-	long dirRef ;
-	short	i,j ;
-	Boolean isDirectory ;
-	
-	for (i=0 ; (s[i]!=0) && (s[i]!=':') ;i++)
-		{
-		volume[i]=s[i] ;
-		}
-	volume[i]=':' ;
-	volume[i+1]=0 ;
-	
-	// then copy the rest of the filename
-	
-	for (j=0;(s[i]!=0);i++,j++)
-		{
-		path[j]=s[i] ;		
-		}
-	path[j]=0 ;
-	
-	c2pstr((Ptr) volume) ;
-	c2pstr((Ptr) path) ;
-	
-	SetVol(volume, 0) ;
-	GetVol( NULL, &vRefNum ) ;
-		
-	GetDirectoryID( vRefNum , fsRtDirID , path , &dirRef , &isDirectory ) ;
-	wxMacSetupStandardFile(vRefNum, dirRef) 	;
-}
-
-enum {
-	kSelectItem = 10, 			// select button item number
-	kSFGetFileDlgID = 251,	// dialog resource number
-	kStrListID = 251,			// our strings
-	kSelectStrNum = 1,			// word 'Select: ' for button
-	kDesktopStrNum = 2,			// word 'Desktop' for button
-	kSelectNoQuoteStrNum = 3,	// word 'Select: ' for button
-	
-	kUseQuotes = true,			// parameter for SetButtonName
-	kDontUseQuotes = false
-};
-
-static void GetLabelString(StringPtr theStr, short stringNum)
-{
-	GetIndString(theStr, kStrListID, stringNum);
-}
-
-static void CopyPStr(StringPtr src, StringPtr dest)
-{
-	BlockMoveData(src, dest, 1 + src[0]);
-}
-
-static char GetSelectKey(void)
-{
-	// this is the key used to trigger the select button
-	
-	// NOT INTERNATIONAL SAVVY; should at least grab it from resources
-	
-	return 's';
-}
-
-// FlashButton briefly highlights the dialog button 
-// as feedback for key equivalents
-
-static void FlashButton(DialogPtr theDlgPtr, short buttonID)
-{
-	short	buttonType;
-	Handle	buttonHandle;
-	Rect	buttonRect;
-	unsigned long	finalTicks;
-	
-	GetDialogItem(theDlgPtr, buttonID, &buttonType, &buttonHandle, &buttonRect);
-	HiliteControl((ControlHandle) buttonHandle, kControlButtonPart);
-	Delay(10, &finalTicks);
-	HiliteControl((ControlHandle) buttonHandle, 0);
-}
-
-static Boolean SameFSSpec(FSSpecPtr spec1, FSSpecPtr spec2)
-{
-	return (spec1->vRefNum == spec2->vRefNum
-			&& spec1->parID == spec2->parID
-			&& EqualString(spec1->name, spec2->name, false, false));
-}
-// MyModalDialogFilter maps a key to the Select button, and handles
-// flashing of the button when the key is hit
-
-static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRecord *eventRec,
-											short *item, void *dataPtr)
-{
-#pragma unused (dataPtr)
-
-	// make certain the proper dialog is showing, 'cause standard file
-	// can nest dialogs but calls the same filter for each
-	
-	if (((WindowPeek) theDlgPtr)->refCon == sfMainDialogRefCon)
-	{
-		// check if the select button was hit
-		/*
-		if ((eventRec->what == keyDown)
-			&& (eventRec->modifiers & cmdKey) 
-			&& ((eventRec->message & charCodeMask) == GetSelectKey()))
-		{
-			*item = kSelectItem;
-			FlashButton(theDlgPtr, kSelectItem);
-			return true;
-		}
-		*/
-	}
-		
-	return false;
-}
-#endif !TARGET_CARBON
 
 void MakeUserDataRec(OpenUserDataRec	*myData , const wxString& filter )
 {
@@ -300,113 +176,6 @@ void MakeUserDataRec(OpenUserDataRec	*myData , const wxString& filter )
 
 }
 
-#ifndef __DARWIN__
-void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const char *filter , FileFilterYDUPP fileFilter, StandardFileReply *theSFR )
-{
-	Point 				thePt;
-	OpenUserDataRec			myData;
-	FSSpec				tempSpec;
-	Boolean				folderFlag;
-	Boolean				wasAliasedFlag;
-	DlgHookYDUPP		dlgHookUPP;
-	ModalFilterYDUPP	myModalFilterUPP;
-	OSErr				err;
-	SFTypeList			types ;
-	
-	
-	// presumably we're running System 7 or later so CustomGetFile is
-	// available
-	
-	// set initial contents of Select button to a space
-	
-	memcpy( theSFR->sfFile.name , "\p " , 2 ) ;
-	
-	// point the user data parameter at the reply record so we can get to it later
-	
-	MakeUserDataRec( &myData , filter ) ;
-	// display the dialog
-
-#if !TARGET_CARBON
-	
-	dlgHookUPP = NULL ;
-//	dlgHookUPP = NewDlgHookYDProc(SFGetFolderDialogHook);
-	myModalFilterUPP = NewModalFilterYDProc(SFGetFolderModalDialogFilter);
-	
-	thePt.h = thePt.v = -1;	// center dialog
-	
-	ParamText( message , NULL , NULL , NULL ) ;
-	
-	CustomGetFile(	fileFilter, 
-			-1,		       		// show all types
-			NULL,
-			theSFR,
-			kSFGetFileDlgID,
-			thePt,				// top left point
-			dlgHookUPP,
-			myModalFilterUPP,
-			nil,				// activate list
-			nil,				// activate proc
-			&myData);
-					
-	DisposeRoutineDescriptor(dlgHookUPP);
-	DisposeRoutineDescriptor(myModalFilterUPP);
-#else
-#endif	
-	// if cancel wasn't pressed and no fatal error occurred...
-	
-	if (theSFR->sfGood)
-	{
-		// if no name is in the reply record file spec,
-		// use the file spec of the parent folder
-		
-		if (theSFR->sfFile.name[0] == '\0')
-		{
-			err = FSMakeFSSpec(theSFR->sfFile.vRefNum, theSFR->sfFile.parID,
-					   "\p", &tempSpec);
-			if (err == noErr)
-			{
-				theSFR->sfFile = tempSpec;
-			}
-			else
-			{
-				// no name to return, forget it
-				
-				theSFR->sfGood = false;
-			}
-		}
-		
-		// if there is now a name in the file spec, check if it's
-		// for a folder or a volume
-		
-		if (theSFR->sfFile.name[0] != '\0')
-		{
-			// the parID of the root of a disk is always fsRtParID == 1
-			
-			if (theSFR->sfFile.parID == fsRtParID)
-			{
-				theSFR->sfIsVolume = true;
-				theSFR->sfIsFolder = false;	// it would be reasonable for this to be true, too
-			}
-			
-			// we have a valid FSSpec, now let's make sure it's not for an alias file
-			
-			err = ResolveAliasFile(&theSFR->sfFile, true, &folderFlag, &wasAliasedFlag);
-			if (err != noErr)
-			{
-				theSFR->sfGood = false;
-			}
-			
-			// did the alias resolve to a folder?
-			
-			if (folderFlag  && ! theSFR->sfIsVolume)
-			{
-				theSFR->sfIsFolder = true;
-			}
-		}
-	}
-}
-#endif
-
 static Boolean CheckFile( ConstStr255Param name , OSType type , OpenUserDataRecPtr data)
 {
     Str255 			filename ;
@@ -541,6 +310,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
         const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
         long style, const wxPoint& pos)
 {
+	  wxASSERT_MSG( NavServicesAvailable() , "Navigation Services are not running" ) ;
     m_message = message;
     m_dialogStyle = style;
     m_parent = parent;
@@ -578,70 +348,6 @@ pascal Boolean CrossPlatformFilterCallback (
 
 int wxFileDialog::ShowModal()
 {
-#if !TARGET_CARBON
-	if ( !gUseNavServices )
-	{
-	if ( m_dialogStyle & wxSAVE )
-	{
-		StandardFileReply	reply ;
-		Str255				prompt ;
-		Str255				filename ;
-
-		strcpy((char *)prompt, m_message) ;
-		c2pstr((char *)prompt ) ;
-		strcpy((char *)filename, m_fileName) ;
-		c2pstr((char *)filename ) ;
-
-		StandardPutFile( prompt , filename , &reply ) ;
-		if ( reply.sfGood == false )
-		{
-			m_path = "" ;
-			return wxID_CANCEL ;
-		}
-		else
-		{
-			m_path = wxMacFSSpec2MacFilename( &reply.sfFile ) ;
-			return wxID_OK ;
-		}
-	}
-	else
-	{
-		OSType types = '????' ;
-		Str255				prompt ;
-		Str255				path ;
-
-		strcpy((char *)prompt, m_message) ;
-		c2pstr((char *)prompt ) ;
-		strcpy((char *)path, m_dir ) ;
-		c2pstr((char *)path ) ;
-
-		StandardFileReply	reply ;
-		FileFilterYDUPP crossPlatformFileFilterUPP = 0 ;
-		#if !TARGET_CARBON
-		crossPlatformFileFilterUPP = 
-			NewFileFilterYDProc(CrossPlatformFileFilter);
-		#endif
-
-		ExtendedOpenFile( prompt , path , m_wildCard , crossPlatformFileFilterUPP, &reply);
-		#if !TARGET_CARBON
-		DisposeFileFilterYDUPP(crossPlatformFileFilterUPP);
-		#endif
-		if ( reply.sfGood == false )
-		{
-			m_path = "" ;
-			return wxID_CANCEL ;
-		}
-		else
-		{
-			m_path = wxMacFSSpec2UnixFilename( &reply.sfFile ) ;
-			return wxID_OK ;
-		}
-	}
-    return wxID_CANCEL;
-}
-	else
-#endif
-	{
 		NavDialogOptions		mNavOptions;
 		NavObjectFilterUPP		mNavFilterUPP = NULL;
 		NavPreviewUPP			mNavPreviewUPP = NULL ;
@@ -800,7 +506,6 @@ int wxFileDialog::ShowModal()
 			return wxID_OK ;
 		}
 		return wxID_CANCEL;
-	}
 }
 
 // Generic file load/save dialog
diff --git a/src/mac/carbon/font.cpp b/src/mac/carbon/font.cpp
index 2d3e5f9033..2335e5d262 100644
--- a/src/mac/carbon/font.cpp
+++ b/src/mac/carbon/font.cpp
@@ -22,6 +22,9 @@
 
 #include "wx/fontutil.h"
 
+#include "wx/mac/private.h"
+
+
 #if !USE_SHARED_LIBRARIES
 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
 #endif
diff --git a/src/mac/carbon/fontenum.cpp b/src/mac/carbon/fontenum.cpp
index 14491d79e9..e1b1347c6d 100644
--- a/src/mac/carbon/fontenum.cpp
+++ b/src/mac/carbon/fontenum.cpp
@@ -37,6 +37,8 @@
 #include "wx/fontmap.h"
 #include "wx/fontutil.h"
 
+#include "wx/mac/private.h"
+
 // ----------------------------------------------------------------------------
 // private classes
 // ----------------------------------------------------------------------------
diff --git a/src/mac/carbon/gauge.cpp b/src/mac/carbon/gauge.cpp
index 38367d88c6..cdaaf58a71 100644
--- a/src/mac/carbon/gauge.cpp
+++ b/src/mac/carbon/gauge.cpp
@@ -41,7 +41,7 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id,
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style & 0xE0FFFFFF /* no borders on mac */ , validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , range, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , range, 
 	  	kControlProgressBarProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
@@ -60,13 +60,13 @@ void wxGauge::SetBezelFace(int w)
 void wxGauge::SetRange(int r)
 {
     m_rangeMax = r;
-    ::SetControlMaximum( m_macControl , m_rangeMax ) ;
+    ::SetControlMaximum( (ControlHandle) m_macControl , m_rangeMax ) ;
 }
 
 void wxGauge::SetValue(int pos)
 {
     m_gaugePos = pos;
-   	::SetControlValue( m_macControl , m_gaugePos ) ;
+   	::SetControlValue( (ControlHandle) m_macControl , m_gaugePos ) ;
 }
 
 int wxGauge::GetShadowWidth() const
diff --git a/src/mac/carbon/glcanvas.cpp b/src/mac/carbon/glcanvas.cpp
index ae60210ef3..62d9c307c4 100644
--- a/src/mac/carbon/glcanvas.cpp
+++ b/src/mac/carbon/glcanvas.cpp
@@ -45,7 +45,7 @@ wxGLContext::wxGLContext(
 {
     m_window = win;
 
-    m_drawable = (AGLDrawable) UMAGetWindowPort(win->MacGetRootWindow());
+    m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetRootWindow()));
 
     m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL);
     wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") );
@@ -251,7 +251,7 @@ void wxGLCanvas::SetViewport()
     int width, height;
     GetClientSize(& width, & height);
     Rect bounds ;
-    GetWindowPortBounds( MacGetRootWindow() , &bounds ) ;
+    GetWindowPortBounds( MAC_WXHWND(MacGetRootWindow()) , &bounds ) ;
     GLint parms[4] ;
     parms[0] = x ;
     parms[1] = bounds.bottom - bounds.top - ( y + height ) ;
diff --git a/src/mac/carbon/gsocket.c b/src/mac/carbon/gsocket.c
index ef89f1a511..7fed13e8c4 100644
--- a/src/mac/carbon/gsocket.c
+++ b/src/mac/carbon/gsocket.c
@@ -29,6 +29,7 @@
     #define TRUE 1
   #endif
 #else
+  #include <MacHeaders.c>
   #define OTUNIXERRORS 1
   #include <OpenTransport.h>
   #include <OpenTransportProviders.h>
diff --git a/src/mac/carbon/icon.cpp b/src/mac/carbon/icon.cpp
index 0133e45534..2ae29d1859 100644
--- a/src/mac/carbon/icon.cpp
+++ b/src/mac/carbon/icon.cpp
@@ -19,6 +19,9 @@
 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
 #endif
 
+#include "wx/mac/private.h"
+
+
 /*
  * Icons
  */
@@ -43,18 +46,18 @@ wxIcon::wxIcon( char **bits ) :
 {
 }
 
-wxIcon::wxIcon(const wxString& icon_file, long flags,
+wxIcon::wxIcon(const wxString& icon_file, int flags,
     int desiredWidth, int desiredHeight)
 
 {
-    LoadFile(icon_file, flags, desiredWidth, desiredHeight);
+    LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight);
 }
 
 wxIcon::~wxIcon()
 {
 }
 
-bool wxIcon::LoadFile(const wxString& filename, long type,
+bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
     int desiredWidth, int desiredHeight)
 {
   UnRef();
diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp
index 8aa4fda2a3..9533882e9e 100644
--- a/src/mac/carbon/listbox.cpp
+++ b/src/mac/carbon/listbox.cpp
@@ -93,10 +93,10 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect
             //  appropriate QuickDraw transform mode.
             
             if( isSelected ) {
-                savedPenMode = GetPortPenMode( grafPtr );
-                SetPortPenMode( grafPtr, hilitetransfermode );
+                savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
+                SetPortPenMode( (CGrafPtr)grafPtr, hilitetransfermode );
                 PaintRect( drawRect );
-                SetPortPenMode( grafPtr, savedPenMode );
+                SetPortPenMode( (CGrafPtr)grafPtr, savedPenMode );
             }
             
             //  Restore the saved clip region.
@@ -111,10 +111,10 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect
             //  appropriate QuickDraw transform mode.
             
             GetPort( &grafPtr );
-            savedPenMode = GetPortPenMode( grafPtr );
-            SetPortPenMode( grafPtr, hilitetransfermode );
+            savedPenMode = GetPortPenMode( (CGrafPtr)grafPtr );
+            SetPortPenMode( (CGrafPtr)grafPtr, hilitetransfermode );
             PaintRect( drawRect );
-            SetPortPenMode( grafPtr, savedPenMode );
+            SetPortPenMode( (CGrafPtr)grafPtr, savedPenMode );
             break;
         default :
           break ;
@@ -171,36 +171,36 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
     CreateListBoxControl( parent->MacGetRootWindow(), &bounds, false, 0, 1, false, true,
                           kwxMacListItemHeight, kwxMacListItemHeight, false, &listDef, &m_macControl );
 
-    GetControlData(m_macControl, kControlNoPart, kControlListBoxListHandleTag,
+    GetControlData( (ControlHandle) m_macControl, kControlNoPart, kControlListBoxListHandleTag,
                    sizeof(ListHandle), (Ptr) &m_macList, &asize);
 
-    SetControlReference(m_macControl, (long) this);
-    SetControlVisibility(m_macControl, false, false);
+    SetControlReference( (ControlHandle) m_macControl, (long) this);
+    SetControlVisibility( (ControlHandle) m_macControl, false, false);
 
 #else
 
     long    result ;
 
-    m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false ,
+    m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
                   kwxMacListWithVerticalScrollbar , 0 , 0, 
                   kControlListBoxProc , (long) this ) ;
-    ::GetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
+    ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
                sizeof( ListHandle ) , (char*) &m_macList  , &result ) ;
 
     HLock( (Handle) m_macList ) ;
     ldefHandle ldef ;
     ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ;
-    if (  (**m_macList).listDefProc != NULL )
+    if (  (**(ListHandle)m_macList).listDefProc != NULL )
     {
       (**ldef).instruction = 0x4EF9;  /* JMP instruction */
       (**ldef).function = (void(*)()) listDef.u.userProc;
-      (**m_macList).listDefProc = (Handle) ldef ;
+      (**(ListHandle)m_macList).listDefProc = (Handle) ldef ;
     }
         
-    Point pt = (**m_macList).cellSize ;
+    Point pt = (**(ListHandle)m_macList).cellSize ;
     pt.v = kwxMacListItemHeight ;
-    LCellSize( pt , m_macList ) ;
-    LAddColumn( 1 , 0 , m_macList ) ;
+    LCellSize( pt , (ListHandle)m_macList ) ;
+    LAddColumn( 1 , 0 , (ListHandle)m_macList ) ;
 #endif
     OptionBits  options = 0;
     if ( style & wxLB_MULTIPLE )
@@ -215,7 +215,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
     {
         options = lOnlyOne ;
     }
-    SetListSelectionFlags(m_macList, options);
+    SetListSelectionFlags((ListHandle)m_macList, options);
     
     MacPostControlCreate() ;
     
@@ -224,7 +224,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
         Append( choices[i] ) ;
     }
     
-    LSetDrawingMode( true , m_macList ) ;
+    LSetDrawingMode( true , (ListHandle)m_macList ) ;
 
     return TRUE;
 }
@@ -235,8 +235,8 @@ wxListBox::~wxListBox()
     if ( m_macList )
     {
 #if !TARGET_CARBON
-      DisposeHandle( (**m_macList).listDefProc ) ;
-      (**m_macList).listDefProc = NULL ;
+      DisposeHandle( (**(ListHandle)m_macList).listDefProc ) ;
+      (**(ListHandle)m_macList).listDefProc = NULL ;
 #endif
         m_macList = NULL ;
     }
@@ -272,7 +272,7 @@ void  wxListBox::DoSetSize(int x, int y,
     wxControl::DoSetSize( x , y , width , height , sizeFlags ) ;
 #if TARGET_CARBON
     Rect bounds ;
-    GetControlBounds( m_macControl , &bounds ) ;
+    GetControlBounds( (ControlHandle) m_macControl , &bounds ) ;
     ControlRef control = GetListVerticalScrollBar( m_macList ) ;
     if ( control )
     {
@@ -633,7 +633,7 @@ void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refC
 
 void wxListBox::MacDelete( int N )
 {
-    LDelRow( 1 , N , m_macList) ;
+    LDelRow( 1 , N , (ListHandle)m_macList) ;
     Refresh();
 }
 
@@ -641,7 +641,7 @@ void wxListBox::MacInsert( int n , const char * text)
 {
     Cell cell = { 0 , 0 } ;
     cell.v = n ;
-    LAddRow( 1 , cell.v , m_macList ) ;
+    LAddRow( 1 , cell.v , (ListHandle)m_macList ) ;
 //    LSetCell(text, strlen(text), cell, m_macList);
     Refresh();
 }
@@ -649,15 +649,15 @@ void wxListBox::MacInsert( int n , const char * text)
 void wxListBox::MacAppend( const char * text) 
 {
     Cell cell = { 0 , 0 } ;
-    cell.v = (**m_macList).dataBounds.bottom ;
-    LAddRow( 1 , cell.v , m_macList ) ;
+    cell.v = (**(ListHandle)m_macList).dataBounds.bottom ;
+    LAddRow( 1 , cell.v , (ListHandle)m_macList ) ;
  //   LSetCell(text, strlen(text), cell, m_macList);
     Refresh();
 }
 
 void wxListBox::MacClear() 
 {
-    LDelRow( (**m_macList).dataBounds.bottom , 0 , m_macList ) ;
+    LDelRow( (**(ListHandle)m_macList).dataBounds.bottom , 0 ,(ListHandle) m_macList ) ;
     Refresh();
 }
 
@@ -666,15 +666,15 @@ void wxListBox::MacSetSelection( int n , bool select )
     Cell cell = { 0 , 0 } ;
     if ( ! (m_windowStyle & wxLB_MULTIPLE) )
     {
-    if ( LGetSelect( true , &cell , m_macList ) )
+    if ( LGetSelect( true , &cell , (ListHandle)m_macList ) )
     {
-        LSetSelect( false , cell , m_macList ) ;
+        LSetSelect( false , cell , (ListHandle)m_macList ) ;
     }
     }
     
     cell.v = n ;
-    LSetSelect( select , cell , m_macList ) ;
-    LAutoScroll( m_macList ) ;
+    LSetSelect( select , cell , (ListHandle)m_macList ) ;
+    LAutoScroll( (ListHandle)m_macList ) ;
     Refresh();
 }
 
@@ -682,7 +682,7 @@ bool wxListBox::MacIsSelected( int n ) const
 {
     Cell cell = { 0 , 0 } ;
     cell.v = n ;
-    return LGetSelect( false , &cell , m_macList ) ;
+    return LGetSelect( false , &cell , (ListHandle)m_macList ) ;
 }
 
 void wxListBox::MacDestroy()
@@ -693,7 +693,7 @@ void wxListBox::MacDestroy()
 int wxListBox::MacGetSelection() const
 {
     Cell cell = { 0 , 0 } ;
-    if ( LGetSelect( true , &cell , m_macList ) )
+    if ( LGetSelect( true , &cell , (ListHandle)m_macList ) )
         return cell.v ;
     else
         return -1 ;
@@ -708,7 +708,7 @@ int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
     Cell cell = { 0 , 0 } ;
     cell.v = 0 ;
     
-    while ( LGetSelect( true , &cell , m_macList ) )
+    while ( LGetSelect( true , &cell ,(ListHandle) m_macList ) )
     {
         aSelections.Add( cell.v ) ;
         no_sel++ ;
@@ -739,18 +739,18 @@ void wxListBox::OnSize( const wxSizeEvent &event)
 #if TARGET_CARBON
     GetListCellSize(m_macList, &pt);
 #else
-    pt = (**m_macList).cellSize ;
+    pt = (**(ListHandle)m_macList).cellSize ;
 #endif
     pt.h =  m_width - 15  ;
-    LCellSize( pt , m_macList ) ;
+    LCellSize( pt , (ListHandle)m_macList ) ;
 }
 
-void wxListBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
     Boolean wasDoubleClick = false ;
     long    result ;
 
-    ::GetControlData( m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick  , &result ) ;
+    ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick  , &result ) ;
     if ( !wasDoubleClick )
     {
         MacDoClick() ;
@@ -763,7 +763,7 @@ void wxListBox::MacHandleControlClick( ControlHandle control , SInt16 controlpar
 
 void wxListBox::MacSetRedraw( bool doDraw ) 
 {
-    LSetDrawingMode( doDraw , m_macList ) ;
+    LSetDrawingMode( doDraw , (ListHandle)m_macList ) ;
     
 }
 
diff --git a/src/mac/carbon/macnotfy.cpp b/src/mac/carbon/macnotfy.cpp
index a47fce31e5..9d0a2a8346 100644
--- a/src/mac/carbon/macnotfy.cpp
+++ b/src/mac/carbon/macnotfy.cpp
@@ -8,6 +8,9 @@
  */
 
 #include "wx/wx.h"
+
+#include "wx/mac/private.h"
+
 #include "wx/mac/macnotfy.h"
 
 const short kMaxEvents = 1000 ;
@@ -74,6 +77,7 @@ void wxMacAddEvent(
 	short wakeUp ) 
 {
 	wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
+	wxASSERT_MSG( handler != NULL , "illegal notification proc ptr" ) ;
 	/* this should be protected eventually */
 	short index = e->top++ ;
 	
@@ -125,7 +129,8 @@ void wxMacProcessNotifierEvents()
 	gMacNotificationEvents.events[index] = NULL ;
 	gMacNotificationEvents.proc[index]  = NULL ;
     
-	handler( event , data  ) ;
+    if ( handler )
+	    handler( event , data  ) ;
   }
   gInProcessing = false ;
 }
diff --git a/src/mac/carbon/mdi.cpp b/src/mac/carbon/mdi.cpp
index b41f8735e8..6f7ff1e805 100644
--- a/src/mac/carbon/mdi.cpp
+++ b/src/mac/carbon/mdi.cpp
@@ -17,6 +17,8 @@
 #include "wx/menu.h"
 #include "wx/settings.h"
 
+#include "wx/mac/private.h"
+
 extern wxWindowList wxModelessWindows;
 
 #if !USE_SHARED_LIBRARY
diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp
index df302f9e69..17e8679a5b 100644
--- a/src/mac/carbon/menu.cpp
+++ b/src/mac/carbon/menu.cpp
@@ -88,8 +88,8 @@ void wxMenu::Init()
 
 wxMenu::~wxMenu()
 {
-	if (m_hMenu)
-		::DisposeMenu(m_hMenu);
+	if (MAC_WXHMENU(m_hMenu))
+		::DisposeMenu(MAC_WXHMENU(m_hMenu));
 
 #if wxUSE_ACCEL
     // delete accels
@@ -164,11 +164,11 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
 	{
 		if ( pos == (size_t)-1 )
 		{
-			MacAppendMenu(m_hMenu, "\p-");
+			MacAppendMenu(MAC_WXHMENU(m_hMenu), "\p-");
 		}
 		else
 		{
-			MacInsertMenuItem(m_hMenu, "\p-" , pos);
+			MacInsertMenuItem(MAC_WXHMENU(m_hMenu), "\p-" , pos);
 		}
 	}
 	else 
@@ -183,16 +183,16 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
 		
 			if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar) 
 			{
-				::InsertMenu( pSubMenu->m_hMenu , -1 ) ;
+				::InsertMenu( MAC_WXHMENU( pSubMenu->m_hMenu ) , -1 ) ;
 			}
 			
 			if ( pos == (size_t)-1 )
 			{
-				UMAAppendSubMenuItem(m_hMenu, label, pSubMenu->m_macMenuId);
+				UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu), label, pSubMenu->m_macMenuId);
 			}
 			else
 			{
-				UMAInsertSubMenuItem(m_hMenu, label , pos, pSubMenu->m_macMenuId);
+				UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), label , pos, pSubMenu->m_macMenuId);
 			}
 		}
 		else
@@ -209,21 +209,21 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
 			}
 			if ( pos == (size_t)-1 )
 			{
-				UMAAppendMenuItem(m_hMenu, label,key,modifiers);
+				UMAAppendMenuItem(MAC_WXHMENU(m_hMenu), label,key,modifiers);
 			}
 			else
 			{
-				UMAInsertMenuItem(m_hMenu, label , pos,key,modifiers);
+				UMAInsertMenuItem(MAC_WXHMENU(m_hMenu), label , pos,key,modifiers);
 			}
   			if ( pItem->GetId() == idMenuTitle ) 
   			{
   				if ( pos == (size_t)-1 )
 				{
-					UMADisableMenuItem( m_hMenu , CountMenuItems( m_hMenu ) ) ;
+					UMADisableMenuItem(MAC_WXHMENU(m_hMenu) , CountMenuItems(MAC_WXHMENU(m_hMenu) ) ) ;
 				}
 				else
 				{
-					UMADisableMenuItem( m_hMenu , pos + 1 ) ;
+					UMADisableMenuItem(MAC_WXHMENU(m_hMenu) , pos + 1 ) ;
 				}
   			}
 		}
@@ -274,7 +274,7 @@ wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
     //else: this item doesn't have an accel, nothing to do
 #endif // wxUSE_ACCEL
 
-	::DeleteMenuItem( m_hMenu , pos + 1);
+	::DeleteMenuItem(MAC_WXHMENU(m_hMenu) , pos + 1);
 
     if ( IsAttached() )
     {
@@ -312,7 +312,7 @@ void wxMenu::SetTitle(const wxString& label)
 	Str255 title ;
     m_title = label ;
 	wxMenuItem::MacBuildMenuString( title, NULL , NULL , label , false );
-	UMASetMenuTitle( m_hMenu , title ) ;
+	UMASetMenuTitle(MAC_WXHMENU(m_hMenu) , title ) ;
 }
 bool wxMenu::ProcessCommand(wxCommandEvent & event)
 {
@@ -399,9 +399,9 @@ int wxMenu::MacGetIndexFromItem( wxMenuItem *pItem )
 void wxMenu::MacEnableMenu( bool bDoEnable ) 
 {
 	if ( bDoEnable )
-		UMAEnableMenuItem( m_hMenu , 0 ) ;
+		UMAEnableMenuItem(MAC_WXHMENU(m_hMenu) , 0 ) ;
 	else
-		UMADisableMenuItem( m_hMenu , 0 ) ;
+		UMADisableMenuItem(MAC_WXHMENU(m_hMenu) , 0 ) ;
 		
 	::DrawMenuBar() ;
 }
@@ -691,7 +691,7 @@ void wxMenuBar::MacInstallMenuBar()
 			else
 			{
 				wxMenuItem::MacBuildMenuString( label, NULL , NULL , m_titles[i] , false );
-				UMASetMenuTitle( menu->GetHMenu() , label ) ;
+				UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , label ) ;
 					wxArrayPtrVoid submenus ;
 					
 		  		for (pos = 0, node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) 
@@ -703,7 +703,7 @@ void wxMenuBar::MacInstallMenuBar()
   					  submenus.Add(subMenu) ;
 					}
 				}
-				::InsertMenu(m_menus[i]->GetHMenu(), 0);
+				::InsertMenu(MAC_WXHMENU(m_menus[i]->GetHMenu()), 0);
 				for ( int i = 0 ; i < submenus.GetCount() ; ++i )
 				{
 				  wxMenu* submenu = (wxMenu*) submenus[i] ;
@@ -719,7 +719,7 @@ void wxMenuBar::MacInstallMenuBar()
   						submenus.Add(itsSubMenu) ;
   					}  				
   				}
-					::InsertMenu( submenu->GetHMenu() , -1 ) ;
+					::InsertMenu( MAC_WXHMENU(submenu->GetHMenu()) , -1 ) ;
   			}
 			}
 		}
@@ -802,14 +802,14 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
 			{
 				Str255 	label;
 				wxMenuItem::MacBuildMenuString( label, NULL , NULL , title , false );
-				UMASetMenuTitle( menu->GetHMenu() , label ) ;
+				UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , label ) ;
 				if ( pos == m_menus.GetCount() - 1)
 				{
-					::InsertMenu( menu->GetHMenu() , 0 ) ;
+					::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
 				}
 				else
 				{
-					::InsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ;
+					::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , m_menus[pos+1]->MacGetMenuId() ) ;
 				}
 			}
 		}
@@ -842,11 +842,11 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
     {
     	if ( pos == (size_t) -1 )
 		{
-			::InsertMenu( menu->GetHMenu() , 0 ) ;
+			::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
 		}
 		else
 		{
-			::InsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ;
+			::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , m_menus[pos+1]->MacGetMenuId() ) ;
 		}
 
 #if wxUSE_ACCEL
@@ -951,7 +951,7 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
     {
 		if (s_macInstalledMenuBar == this)
 		{
-			::InsertMenu( menu->GetHMenu() , 0 ) ;
+			::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
 		}
 
 #if wxUSE_ACCEL
diff --git a/src/mac/carbon/menuitem.cpp b/src/mac/carbon/menuitem.cpp
index 33b337518e..52e68bfdad 100644
--- a/src/mac/carbon/menuitem.cpp
+++ b/src/mac/carbon/menuitem.cpp
@@ -249,30 +249,30 @@ void wxMenuItem::Enable(bool bDoEnable)
     if ( m_subMenu == NULL ) 
     {     
     	// normal menu item
-	    if ( m_parentMenu->GetHMenu() )
+	    if ( MAC_WXHMENU(m_parentMenu->GetHMenu()) )
 	    {
 	   	 	int index = m_parentMenu->MacGetIndexFromItem( this ) ;
 	   	 	if ( index >= 1 )
 	   	 	{
 	   	 		if ( bDoEnable )
-	   	 			UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
+	   	 			UMAEnableMenuItem( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index ) ;
 	   	 		else
-	   	 			UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
+	   	 			UMADisableMenuItem( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index ) ;
 	   	 	}
 	    }
     }
     else                            
     {
   		// submenu
-	    if ( m_parentMenu->GetHMenu() )
+	    if ( MAC_WXHMENU(m_parentMenu->GetHMenu()) )
 	    {
 	   	 	int index = m_parentMenu->MacGetIndexFromItem( this ) ;
 	   	 	if ( index >= 1 )
 	   	 	{
 	   	 		if ( bDoEnable )
-	   	 			UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
+	   	 			UMAEnableMenuItem( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index ) ;
 	   	 		else
-	   	 			UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
+	   	 			UMADisableMenuItem( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index ) ;
 	   	 	}
 	    }
     }
@@ -288,15 +288,15 @@ void wxMenuItem::Check(bool bDoCheck)
   if ( m_isChecked != bDoCheck ) 
   {
     m_isChecked = bDoCheck;
-   	if ( m_parentMenu->GetHMenu() )
+   	if ( MAC_WXHMENU(m_parentMenu->GetHMenu()) )
     {
    	 	int index = m_parentMenu->MacGetIndexFromItem( this ) ;
    	 	if ( index >= 1 )
    	 	{
    	 		if ( bDoCheck )
-					::SetItemMark( m_parentMenu->GetHMenu() , index , 0x12 ) ; // checkmark
+					::SetItemMark( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index , 0x12 ) ; // checkmark
 				else
- 					::SetItemMark( m_parentMenu->GetHMenu() , index , 0 ) ; // no mark
+ 					::SetItemMark( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index , 0 ) ; // no mark
   	 	}
   	}
   }
@@ -312,14 +312,14 @@ void wxMenuItem::SetText(const wxString& text)
 //    OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
 
     wxCHECK_RET( m_parentMenu && m_parentMenu->GetHMenu(), wxT("menuitem without menu") );
-   	if ( m_parentMenu->GetHMenu() )
+   	if ( MAC_WXHMENU(m_parentMenu->GetHMenu()) )
     {
    	 	int index = m_parentMenu->MacGetIndexFromItem( this ) ;
    	 	if ( index >= 1 )
    	 	{
  			Str255 label;
 			MacBuildMenuString( label , NULL , NULL , text ,false);
-   	 		::SetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark
+   	 		::SetMenuItemText( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index , label ) ; // checkmark
   	 	}
   	}
 
diff --git a/src/mac/carbon/metafile.cpp b/src/mac/carbon/metafile.cpp
index 9bdbb223fb..2380c96edc 100644
--- a/src/mac/carbon/metafile.cpp
+++ b/src/mac/carbon/metafile.cpp
@@ -34,6 +34,8 @@
 #include "wx/metafile.h"
 #include "wx/clipbrd.h"
 
+#include "wx/mac/private.h"
+
 #include <stdio.h>
 #include <string.h>
 
@@ -59,7 +61,7 @@ wxMetafileRefData::~wxMetafileRefData(void)
 {
     if (m_metafile)
     {
-		KillPicture( m_metafile ) ;
+		KillPicture( (PicHandle) m_metafile ) ;
         m_metafile = 0;
     }
 }
@@ -104,7 +106,7 @@ bool wxMetaFile::SetClipboard(int width, int height)
     return TRUE ;
 }
 
-void wxMetafile::SetHMETAFILE(PicHandle mf)
+void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
 {
     if (!m_refData)
         m_refData = new wxMetafileRefData;
@@ -122,7 +124,7 @@ bool wxMetaFile::Play(wxDC *dc)
 		
 	{
 		wxMacPortSetter helper( dc ) ;
-		PicHandle pict = GetHMETAFILE() ;
+		PicHandle pict = (PicHandle) GetHMETAFILE() ;
 		DrawPicture( pict , &(**pict).picFrame ) ;
 	}
     return TRUE;
@@ -149,7 +151,7 @@ wxMetaFileDC::wxMetaFileDC(const wxString& file)
   Rect r={0,0,1000,1000} ;
 	
   m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
-  ::GetPort( &m_macPort ) ;	
+  ::GetPort( (GrafPtr*) &m_macPort ) ;	
   m_ok = TRUE ;
 
   SetMapMode(wxMM_TEXT); 
@@ -171,7 +173,7 @@ wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, i
 	Rect r={yorg,xorg,yorg+yext,xorg+xext} ;
 	
 	m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
-	::GetPort( &m_macPort ) ;	
+	::GetPort( (GrafPtr*) &m_macPort ) ;	
   m_ok = TRUE ;
 
   SetMapMode(wxMM_TEXT); 
@@ -195,7 +197,7 @@ size_t wxMetafileDataObject::GetDataSize() const
 
 bool wxMetafileDataObject::GetDataHere(void *buf) const
 {
-  memcpy( buf , (*(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
+  memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
     GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
   return true ;
 }
diff --git a/src/mac/carbon/notebmac.cpp b/src/mac/carbon/notebmac.cpp
index 9edaae2764..aa5351acc5 100644
--- a/src/mac/carbon/notebmac.cpp
+++ b/src/mac/carbon/notebmac.cpp
@@ -130,7 +130,7 @@ bool wxNotebook::Create(wxWindow *parent,
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlTabSmallProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
@@ -168,7 +168,7 @@ int wxNotebook::SetSelection(int nPage)
     return m_nSelection ;
 
     ChangePage(m_nSelection, nPage);
-	SetControlValue( m_macControl , m_nSelection + 1 ) ;
+	SetControlValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ;
 
     return m_nSelection;
 }
@@ -291,7 +291,7 @@ bool wxNotebook::InsertPage(int nPage,
  */
 void wxNotebook::MacSetupTabs()
 {
-    SetControlMaximum( m_macControl , GetPageCount() ) ;
+    SetControlMaximum( (ControlHandle) m_macControl , GetPageCount() ) ;
 
     wxNotebookPage *page;
     ControlTabInfoRec info;
@@ -307,14 +307,14 @@ void wxNotebook::MacSetupTabs()
 		strcpy( (char *) info.name , page->GetLabel() ) ;
 		c2pstr( (char *) info.name ) ;
 #endif
-        SetControlData( m_macControl, ii+1, kControlTabInfoTag,
+        SetControlData( (ControlHandle) m_macControl, ii+1, kControlTabInfoTag,
                         sizeof( ControlTabInfoRec) , (char*) &info ) ;
-        SetControlData( m_macControl, ii+1, kControlTabEnabledFlagTag,
+        SetControlData( (ControlHandle) m_macControl, ii+1, kControlTabEnabledFlagTag,
                         sizeof( Boolean ), (Ptr)&enabled );
     }
     Rect bounds;
-    GetControlBounds(m_macControl, &bounds);
-    InvalWindowRect(MacGetRootWindow(), &bounds);
+    GetControlBounds((ControlHandle)m_macControl, &bounds);
+    InvalWindowRect((WindowRef)MacGetRootWindow(), &bounds);
 }
 
 // ----------------------------------------------------------------------------
@@ -436,9 +436,9 @@ void wxNotebook::ChangePage(int nOldSel, int nSel)
     m_nSelection = nSel;
 }
 
-void wxNotebook::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxNotebook::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
-  wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControlValue(m_macControl) - 1, m_nSelection);
+  wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControlValue((ControlHandle)m_macControl) - 1, m_nSelection);
   event.SetEventObject(this);
 
   ProcessEvent(event);
diff --git a/src/mac/carbon/printdlg.cpp b/src/mac/carbon/printdlg.cpp
index ffe0ba15ba..38c128ac21 100644
--- a/src/mac/carbon/printdlg.cpp
+++ b/src/mac/carbon/printdlg.cpp
@@ -76,7 +76,7 @@ int wxPrintDialog::ShowModal()
 	if ( err == noErr )
 	{
 		m_printDialogData.ConvertToNative() ;
-		if  ( ::PrJobDialog( m_printDialogData.GetPrintData().m_macPrintInfo ) )
+		if  ( ::PrJobDialog( (THPrint) m_printDialogData.GetPrintData().m_macPrintInfo ) )
 		{
 			m_printDialogData.ConvertFromNative() ;
 			result = wxID_OK ;
@@ -228,7 +228,7 @@ int wxPageSetupDialog::ShowModal()
 	if ( err == noErr )
 	{
 		m_pageSetupData.ConvertToNative() ;
-		if  ( ::PrStlDialog( m_pageSetupData.GetPrintData().m_macPrintInfo ) )
+		if  ( ::PrStlDialog(  (THPrint) m_pageSetupData.GetPrintData().m_macPrintInfo ) )
 		{
 			m_pageSetupData.ConvertFromNative() ;
 			result = wxID_OK ;
diff --git a/src/mac/carbon/printmac.cpp b/src/mac/carbon/printmac.cpp
index 426bd42de3..33506c4548 100644
--- a/src/mac/carbon/printmac.cpp
+++ b/src/mac/carbon/printmac.cpp
@@ -29,6 +29,8 @@
 #include "wx/msgdlg.h"
 #endif
 
+#include "wx/mac/private.h"
+
 #include "wx/mac/printmac.h"
 #include "wx/dcprint.h"
 #include "wx/printdlg.h"
diff --git a/src/mac/carbon/radiobox.cpp b/src/mac/carbon/radiobox.cpp
index e3d5abd2a6..1ec40d88cf 100644
--- a/src/mac/carbon/radiobox.cpp
+++ b/src/mac/carbon/radiobox.cpp
@@ -117,7 +117,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
 	
 	MacPreControlCreate( parent , id ,  label , pos , size ,style, val , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlGroupBoxTextTitleProc , (long) this ) ;
 	
     for (i = 0; i < n; i++)
diff --git a/src/mac/carbon/radiobut.cpp b/src/mac/carbon/radiobut.cpp
index 6421f60596..0d060bdb95 100644
--- a/src/mac/carbon/radiobut.cpp
+++ b/src/mac/carbon/radiobut.cpp
@@ -35,7 +35,7 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
 	
 	MacPreControlCreate( parent , id ,  label , pos , size ,style, validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlRadioButtonProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
@@ -70,10 +70,10 @@ void wxRadioButton::SetValue(bool val)
 {
 	int i;
 	wxRadioButton *cycle;
-	  if ( GetControlValue( m_macControl ) == val )
+	  if ( GetControlValue( (ControlHandle) m_macControl ) == val )
 	    return ;
 	    
-   ::SetControlValue( m_macControl , val ) ;
+   ::SetControlValue( (ControlHandle) m_macControl , val ) ;
    if (val) 
    {
    		cycle=this->NextInCycle();
@@ -89,7 +89,7 @@ void wxRadioButton::SetValue(bool val)
 
 bool wxRadioButton::GetValue() const
 {
-    return ::GetControlValue( m_macControl ) ;
+    return ::GetControlValue( (ControlHandle) m_macControl ) ;
 }
 
 void wxRadioButton::Command (wxCommandEvent & event)
@@ -98,7 +98,7 @@ void wxRadioButton::Command (wxCommandEvent & event)
   ProcessCommand (event);
 }
 
-void wxRadioButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxRadioButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
     if ( GetValue() )
       return ;
diff --git a/src/mac/carbon/region.cpp b/src/mac/carbon/region.cpp
index 315b966927..a0204caad5 100644
--- a/src/mac/carbon/region.cpp
+++ b/src/mac/carbon/region.cpp
@@ -63,25 +63,25 @@ wxRegion::wxRegion()
 wxRegion::wxRegion(WXHRGN hRegion )
 {
     m_refData = new wxRegionRefData;
-    CopyRgn( hRegion , M_REGION ) ;
+    CopyRgn( (RgnHandle) hRegion , (RgnHandle) M_REGION ) ;
 }
 
 wxRegion::wxRegion(long x, long y, long w, long h)
 {
     m_refData = new wxRegionRefData;
-    SetRectRgn( M_REGION , x , y , x+w , y+h ) ;
+    SetRectRgn( (RgnHandle) M_REGION , x , y , x+w , y+h ) ;
 }
 
 wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight)
 {
     m_refData = new wxRegionRefData;
-    SetRectRgn( M_REGION , topLeft.x , topLeft.y , bottomRight.x , bottomRight.y ) ;
+    SetRectRgn( (RgnHandle) M_REGION , topLeft.x , topLeft.y , bottomRight.x , bottomRight.y ) ;
 }
 
 wxRegion::wxRegion(const wxRect& rect)
 {
     m_refData = new wxRegionRefData;
-    SetRectRgn( M_REGION , rect.x , rect.y , rect.x+rect.width , rect.y+rect.height ) ;
+    SetRectRgn( (RgnHandle) M_REGION , rect.x , rect.y , rect.x+rect.width , rect.y+rect.height ) ;
 }
 
 /*!
diff --git a/src/mac/carbon/scrolbar.cpp b/src/mac/carbon/scrolbar.cpp
index 51c01e4cef..07fb9476df 100644
--- a/src/mac/carbon/scrolbar.cpp
+++ b/src/mac/carbon/scrolbar.cpp
@@ -43,12 +43,12 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style, validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , true , 0 , 0 , 100, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , true , 0 , 0 , 100, 
 		kControlScrollBarLiveProc , (long) this ) ;
 	
-	wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+	wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
 
-	::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ;
+	::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ;
 
 	MacPostControlCreate() ;
 
@@ -61,12 +61,12 @@ wxScrollBar::~wxScrollBar()
 
 void wxScrollBar::SetThumbPosition(int viewStart)
 {
-    ::SetControlValue( m_macControl , viewStart ) ;
+    ::SetControlValue( (ControlHandle) m_macControl , viewStart ) ;
 }
 
 int wxScrollBar::GetThumbPosition() const
 {
-    return ::GetControlValue( m_macControl ) ;
+    return ::GetControlValue( (ControlHandle) m_macControl ) ;
 }
 
 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
@@ -78,15 +78,15 @@ void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageS
 
   	int range1 = wxMax((m_objectSize - m_pageSize), 0) ;
 
-    SetControlMaximum( m_macControl , range1 ) ;
-    SetControlMinimum(  m_macControl , 0 ) ;
-    SetControlValue(  m_macControl , position ) ;
+    SetControlMaximum( (ControlHandle) m_macControl , range1 ) ;
+    SetControlMinimum( (ControlHandle) m_macControl , 0 ) ;
+    SetControlValue( (ControlHandle) m_macControl , position ) ;
 
     if ( UMAGetAppearanceVersion() >= 0x0110  )
     {
         if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
         {
-			SetControlViewSize( m_macControl , m_pageSize ) ;
+			SetControlViewSize( (ControlHandle) m_macControl , m_pageSize ) ;
         }
     }
     Refresh() ;
@@ -99,14 +99,14 @@ void wxScrollBar::Command(wxCommandEvent& event)
     ProcessCommand(event);
 }
 
-void wxScrollBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
-	if ( m_macControl == NULL )
+	if ( (ControlHandle) m_macControl == NULL )
 		return ;
 	
-  int position = GetControlValue( m_macControl) ;
-  int minPos = GetControlMinimum( m_macControl) ;
-  int maxPos = GetControlMaximum( m_macControl) ;
+  int position = GetControlValue( (ControlHandle) m_macControl) ;
+  int minPos = GetControlMinimum( (ControlHandle) m_macControl) ;
+  int maxPos = GetControlMaximum( (ControlHandle) m_macControl) ;
 
   wxEventType scrollEvent = wxEVT_NULL;
   int nScrollInc;
diff --git a/src/mac/carbon/settings.cpp b/src/mac/carbon/settings.cpp
index 92d586c90c..8c7591cfdb 100644
--- a/src/mac/carbon/settings.cpp
+++ b/src/mac/carbon/settings.cpp
@@ -17,6 +17,8 @@
 #include "wx/gdicmn.h"
 #include "wx/utils.h"
 
+#include "wx/mac/uma.h"
+
 // ----------------------------------------------------------------------------
 // wxSystemSettingsNative
 // ----------------------------------------------------------------------------
diff --git a/src/mac/carbon/slider.cpp b/src/mac/carbon/slider.cpp
index 2f8854acc2..f76b09fc68 100644
--- a/src/mac/carbon/slider.cpp
+++ b/src/mac/carbon/slider.cpp
@@ -84,12 +84,12 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
     }
   
 
-     m_macControl = ::NewControl( parent->MacGetRootWindow(), &bounds, title, false,
+     m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()), &bounds, title, false,
                                    value, minValue, maxValue, procID, (long) this);
  
-     wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+     wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
  
-     ::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ;
+     ::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ;
  
      if(style & wxSL_LABELS)
      {
@@ -127,7 +127,7 @@ wxSlider::~wxSlider()
 
 int wxSlider::GetValue() const
 {
- 	return GetControlValue( m_macControl) ;
+ 	return GetControlValue( (ControlHandle) m_macControl) ;
 }
 
 void wxSlider::SetValue(int value)
@@ -136,7 +136,7 @@ void wxSlider::SetValue(int value)
 	valuestring.Printf( "%d" , value ) ;	
 	if ( m_macValueStatic )
 		m_macValueStatic->SetLabel( valuestring ) ;
- 	SetControlValue( m_macControl , value ) ;
+ 	SetControlValue( (ControlHandle) m_macControl , value ) ;
 }
 
 void wxSlider::SetRange(int minValue, int maxValue)
@@ -146,8 +146,8 @@ void wxSlider::SetRange(int minValue, int maxValue)
   m_rangeMin = minValue;
   m_rangeMax = maxValue;
 
-  SetControlMinimum(m_macControl, m_rangeMin);
-  SetControlMaximum(m_macControl, m_rangeMax);
+  SetControlMinimum( (ControlHandle) m_macControl, m_rangeMin);
+  SetControlMaximum( (ControlHandle) m_macControl, m_rangeMax);
   
   if(m_macMinimumStatic) {
     value.Printf("%d", m_rangeMin);
@@ -239,9 +239,9 @@ void wxSlider::Command (wxCommandEvent & event)
   ProcessCommand (event);
 }
 
-void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxSlider::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
-	SInt16 value = ::GetControlValue( m_macControl ) ;
+	SInt16 value = ::GetControlValue( (ControlHandle) m_macControl ) ;
 	
 	SetValue( value ) ;		
 	
@@ -372,7 +372,7 @@ void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart
          GetParent()->MacClientToRootWindow(&mac_x, &mac_y);
      }
  
-     GetControlBounds(m_macControl, &oldbounds);
+     GetControlBounds( (ControlHandle) m_macControl, &oldbounds);
      oldbounds.right = oldbounds.left + m_width;
      oldbounds.bottom = oldbounds.top + m_height;
  
@@ -408,7 +408,7 @@ void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart
  
          // Update window at old and new positions
          SetRect(&newbounds, m_x, m_y, m_x + m_width, m_y + m_height);
-         WindowRef rootwindow = MacGetRootWindow();
+         WindowRef rootwindow = (WindowRef) MacGetRootWindow();
          InvalWindowRect( rootwindow , &oldbounds );
          InvalWindowRect( rootwindow , &newbounds );
  
@@ -485,6 +485,6 @@ void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart
      if(GetParent()) {
          GetParent()->MacClientToRootWindow(&x, &y);
      }
-     UMAMoveControl(m_macControl, x, y);
-     UMASizeControl(m_macControl, width - xborder, height - yborder);
+     UMAMoveControl( (ControlHandle) m_macControl, x, y);
+     UMASizeControl( (ControlHandle) m_macControl, width - xborder, height - yborder);
 }
\ No newline at end of file
diff --git a/src/mac/carbon/spinbutt.cpp b/src/mac/carbon/spinbutt.cpp
index 87db4b041a..e3beab7322 100644
--- a/src/mac/carbon/spinbutt.cpp
+++ b/src/mac/carbon/spinbutt.cpp
@@ -49,10 +49,10 @@ bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, c
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 100, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100, 
 		kControlLittleArrowsProc , (long) this ) ;
 	
-	wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+	wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
 
 	MacPostControlCreate() ;
 
@@ -90,13 +90,13 @@ void wxSpinButton::SetRange(int minVal, int maxVal)
 {
 	m_min = minVal;
 	m_max = maxVal;
-    SetControlMaximum( m_macControl , maxVal ) ;
-    SetControlMinimum(  m_macControl , minVal ) ;
+    SetControlMaximum( (ControlHandle) m_macControl , maxVal ) ;
+    SetControlMinimum((ControlHandle) m_macControl , minVal ) ;
 }
 
-void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
-	if ( m_macControl == NULL )
+	if ( (ControlHandle) m_macControl == NULL )
 		return ;
 	
 	int oldValue = m_value ;
@@ -142,7 +142,7 @@ void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 control
   {
   	m_value = oldValue ;
   }
-  SetControlValue(  m_macControl , m_value ) ;
+  SetControlValue( (ControlHandle) m_macControl , m_value ) ;
 
     /* always send a thumbtrack event */
     if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
diff --git a/src/mac/carbon/statbox.cpp b/src/mac/carbon/statbox.cpp
index 1a562c12e6..529c720da3 100644
--- a/src/mac/carbon/statbox.cpp
+++ b/src/mac/carbon/statbox.cpp
@@ -43,7 +43,7 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
 	
 	MacPreControlCreate( parent , id ,  label , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlGroupBoxTextTitleProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
diff --git a/src/mac/carbon/statbrma.cpp b/src/mac/carbon/statbrma.cpp
index f0d2b9bfa4..139b505f8e 100644
--- a/src/mac/carbon/statbrma.cpp
+++ b/src/mac/carbon/statbrma.cpp
@@ -25,6 +25,10 @@ BEGIN_EVENT_TABLE(wxStatusBarMac, wxStatusBarGeneric)
 	EVT_PAINT(wxStatusBarMac::OnPaint)
 END_EVENT_TABLE()
 
+#ifdef __WXMAC__
+#include "wx/mac/private.h"
+#endif
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -56,7 +60,7 @@ void wxStatusBarMac::DrawFieldText(wxDC& dc, int i)
   wxRect rect;
   GetFieldRect(i, rect);
   
-  if ( !IsWindowHilited( MacGetRootWindow() ) )
+  if ( !IsWindowHilited( MAC_WXHWND( MacGetRootWindow() ) ) )
   {
     dc.SetTextForeground( wxColour( 0x80 , 0x80 , 0x80 ) ) ;
   }
@@ -107,7 +111,7 @@ void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event) )
 {
   	wxPaintDC dc(this);
   	
-  if ( IsWindowHilited( MacGetRootWindow() ) )
+  if ( IsWindowHilited( MAC_WXHWND( MacGetRootWindow() ) ) )
   {
   	wxPen black( wxBLACK , 1 , wxSOLID ) ;
 	wxPen white( wxWHITE , 1 , wxSOLID ) ;
diff --git a/src/mac/carbon/statlmac.cpp b/src/mac/carbon/statlmac.cpp
index 0272ed706e..2c01893e84 100644
--- a/src/mac/carbon/statlmac.cpp
+++ b/src/mac/carbon/statlmac.cpp
@@ -54,7 +54,7 @@ bool wxStaticLine::Create( wxWindow *parent,
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlSeparatorLineProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
diff --git a/src/mac/carbon/stattext.cpp b/src/mac/carbon/stattext.cpp
index f4e52d8d04..3b2476af40 100644
--- a/src/mac/carbon/stattext.cpp
+++ b/src/mac/carbon/stattext.cpp
@@ -129,7 +129,7 @@ void wxStaticText::OnDraw( wxDC &dc )
     if (m_width <= 0 || m_height <= 0)
         return;
 
-  if ( !IsWindowHilited( MacGetRootWindow() ) && 
+  if ( !IsWindowHilited( (WindowRef) MacGetRootWindow() ) && 
     ( GetBackgroundColour() == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) 
       || GetBackgroundColour() == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) )
   {
diff --git a/src/mac/carbon/tabctrl.cpp b/src/mac/carbon/tabctrl.cpp
index 9231ea3d41..db1992be6e 100644
--- a/src/mac/carbon/tabctrl.cpp
+++ b/src/mac/carbon/tabctrl.cpp
@@ -41,7 +41,7 @@ bool wxTabCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlTabSmallProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp
index 64d585d233..ce7177ffec 100644
--- a/src/mac/carbon/textctrl.cpp
+++ b/src/mac/carbon/textctrl.cpp
@@ -124,7 +124,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
     }
 
 
-    m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, 
+    m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , true , 0 , 0 , 1, 
         ( style & wxTE_PASSWORD ) ? kControlEditTextPasswordProc : kControlEditTextProc , (long) this ) ;
     MacPostControlCreate() ;
 
@@ -134,7 +134,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         TEHandle teH ;
         long size ;
    
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
         (*teH)->lineHeight = -1 ;
     }
     
@@ -142,7 +142,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         value = wxMacMakeMacStringFromPC( st ) ;
     else
         value = st ;
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
 
   return TRUE;
 }
@@ -150,7 +150,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
 wxString wxTextCtrl::GetValue() const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     wxBuffer[actualsize] = 0 ;
     if( wxApp::s_macDefaultEncodingIsPC )
         return wxMacMakePCStringFromMac( wxBuffer ) ;
@@ -164,7 +164,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
 
     *from = (**teH).selStart;
     *to = (**teH).selEnd;
@@ -178,7 +178,7 @@ void wxTextCtrl::SetValue(const wxString& st)
         value = wxMacMakeMacStringFromPC( st ) ;
     else
         value = st ;
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
     MacRedrawControl() ;
 }
 
@@ -190,7 +190,7 @@ void wxTextCtrl::Copy()
         TEHandle teH ;
         long size ;
    
-  		  ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+  		  ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
 		    TECopy( teH ) ;
         ClearCurrentScrap();
 		    TEToScrap() ;
@@ -204,7 +204,7 @@ void wxTextCtrl::Cut()
         TEHandle teH ;
         long size ;
    
-   		  ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   		  ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
 		    TECut( teH ) ;
         ClearCurrentScrap();
 		    TEToScrap() ;
@@ -219,7 +219,7 @@ void wxTextCtrl::Paste()
         TEHandle teH ;
         long size ;
    
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
         TEFromScrap() ;
         TEPaste( teH ) ;
         MacRedrawControl() ;
@@ -280,9 +280,9 @@ bool wxTextCtrl::CanPaste() const
 void wxTextCtrl::SetEditable(bool editable)
 {
     if ( editable )
-        UMAActivateControl( m_macControl ) ;
+        UMAActivateControl( (ControlHandle) m_macControl ) ;
     else
-        UMADeactivateControl( m_macControl ) ;
+        UMADeactivateControl( (ControlHandle) m_macControl ) ;
 }
 
 void wxTextCtrl::SetInsertionPoint(long pos)
@@ -302,8 +302,8 @@ long wxTextCtrl::GetInsertionPoint() const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-//   ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+//   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
     return (**teH).selStart ;
 }
 
@@ -313,9 +313,9 @@ long wxTextCtrl::GetLastPosition() const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
-//   ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
+//   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
     return (**teH).teLength ;
 }
 
@@ -328,8 +328,8 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
    
     selection.selStart = from ;
     selection.selEnd = to ;
-    ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     TESetSelect( from , to  , teH ) ;
     TEDelete( teH ) ;
         TEInsert( value , value.Length() , teH ) ;
@@ -345,8 +345,8 @@ void wxTextCtrl::Remove(long from, long to)
    
     selection.selStart = from ;
     selection.selEnd = to ;
-    ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-    ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+    ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     TEDelete( teH ) ;
     Refresh() ;
 }
@@ -357,12 +357,12 @@ void wxTextCtrl::SetSelection(long from, long to)
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
    selection.selStart = from ;
    selection.selEnd = to ;
    
-   ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+   ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
    TESetSelect( selection.selStart , selection.selEnd , teH ) ;
 }
 
@@ -385,7 +385,7 @@ void wxTextCtrl::WriteText(const wxString& text)
     wxBuffer[text.Length() ] = 0 ;
 //    wxMacConvertNewlines( wxBuffer , wxBuffer ) ;
    
-    ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
         TEInsert( wxBuffer , strlen( wxBuffer) , teH ) ;
         Refresh() ;
@@ -399,7 +399,7 @@ void wxTextCtrl::AppendText(const wxString& text)
 
 void wxTextCtrl::Clear()
 {
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
     Refresh() ;
 }
 
@@ -484,7 +484,7 @@ void wxTextCtrl::DiscardEdits()
 int wxTextCtrl::GetNumberOfLines() const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     
     int count = 1;
     for (int i = 0; i < actualsize; i++)
@@ -514,7 +514,7 @@ void wxTextCtrl::ShowPosition(long pos)
 int wxTextCtrl::GetLineLength(long lineNo) const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     
     // Find line first
     int count = 0;
@@ -541,7 +541,7 @@ int wxTextCtrl::GetLineLength(long lineNo) const
 wxString wxTextCtrl::GetLineText(long lineNo) const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     
     // Find line first
     int count = 0;
@@ -649,12 +649,12 @@ void wxTextCtrl::OnChar(wxKeyEvent& key_event)
             break;
     }
     
-    EventRecord *ev = wxTheApp->MacGetCurrentEvent();
+    EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent();
     short keychar = short(ev->message & charCodeMask);
     if (!eat_key)
     {
         short keycode = short(ev->message & keyCodeMask) >> 8 ;
-        ::HandleControlKey( m_macControl , keycode , keychar , ev->modifiers );
+        ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers );
     }
     if ( keychar >= 0x20 ||
          key_event.KeyCode() == WXK_RETURN ||
@@ -1706,7 +1706,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
 
     if ( style & wxTE_PASSWORD )
     {
-      m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, 
+      m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , true , 0 , 0 , 1, 
         kControlEditTextPasswordProc , (long) this ) ;
     }
     else
@@ -1725,13 +1725,13 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         
     if ( style & wxTE_PASSWORD )
     {
-      ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+      ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
         /* set up locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* set the text in the record */
     TXNSetData( (**tpvars).fTXNRec, kTXNTextData,  (const char*)value, value.Length(),
       kTXNStartOffset, kTXNEndOffset);
@@ -1745,14 +1745,14 @@ wxString wxTextCtrl::GetValue() const
     Size actualsize;
   if ( m_windowStyle & wxTE_PASSWORD )
   {
-      ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+      ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
     OSStatus err;
         /* set up locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* extract the text from the record */
     Handle theText ;
     err = TXNGetDataEncoded( (**tpvars).fTXNRec, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
@@ -1783,7 +1783,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
 
     *from = (**teH).selStart;
     *to = (**teH).selEnd;
@@ -1793,7 +1793,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
         STPTextPaneVars **tpvars;
 
             /* set up locals */
-        tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+        tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
 
         TXNGetSelection(  (**tpvars).fTXNRec , (TXNOffset*) from , (TXNOffset*) to ) ;
 
@@ -1810,13 +1810,13 @@ void wxTextCtrl::SetValue(const wxString& st)
         value = st ;
   if ( m_windowStyle & wxTE_PASSWORD )
   {
-      ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+      ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
         /* set up locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* set the text in the record */
     TXNSetData( (**tpvars).fTXNRec, kTXNTextData,  (const char*)value, value.Length(),
       kTXNStartOffset, kTXNEndOffset);
@@ -1834,14 +1834,14 @@ void wxTextCtrl::Copy()
             TEHandle teH ;
             long size ;
        
-      		 ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+      		 ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     		TECopy( teH ) ;
     		ClearCurrentScrap();
     		TEToScrap() ;
     	}
     	else
     	{
-    	  mUPDoEditCommand( m_macControl , kmUPCopy ) ;
+    	  mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCopy ) ;
     	}
 	}
 }
@@ -1855,7 +1855,7 @@ void wxTextCtrl::Cut()
             TEHandle teH ;
             long size ;
        
-       		::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+       		::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     		TECut( teH ) ;
     		ClearCurrentScrap();
     		TEToScrap() ;
@@ -1863,7 +1863,7 @@ void wxTextCtrl::Cut()
     }
     	else
     	{
-    	  mUPDoEditCommand( m_macControl , kmUPCut ) ;
+    	  mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCut ) ;
     	}
 	}
 }
@@ -1877,14 +1877,14 @@ void wxTextCtrl::Paste()
             TEHandle teH ;
             long size ;
      
-     		::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+     		::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
   		TEFromScrap() ;
   		TEPaste( teH ) ;
       MacRedrawControl() ;
   	}
    	else
    	{
-   	  mUPDoEditCommand( m_macControl , kmUPPaste ) ;
+   	  mUPDoEditCommand( (ControlHandle) m_macControl , kmUPPaste ) ;
    	}
 	}
 }
@@ -1943,9 +1943,9 @@ bool wxTextCtrl::CanPaste() const
 void wxTextCtrl::SetEditable(bool editable)
 {
     if ( editable )
-        UMAActivateControl( m_macControl ) ;
+        UMAActivateControl( (ControlHandle) m_macControl ) ;
     else
-        UMADeactivateControl( m_macControl ) ;
+        UMADeactivateControl( (ControlHandle) m_macControl ) ;
 }
 
 void wxTextCtrl::SetInsertionPoint(long pos)
@@ -1975,14 +1975,14 @@ long wxTextCtrl::GetLastPosition() const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
-//   ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
+//   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
     return (**teH).teLength ;
   }
   else
   {
-     STPTextPaneVars**	tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+     STPTextPaneVars**	tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
 
     int actualsize = 0 ;
   	Handle theText ;
@@ -2012,8 +2012,8 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
    
    	selection.selStart = from ;
    	selection.selEnd = to ;
-   	::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-		::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   	::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+		::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    	TESetSelect( from , to  , teH ) ;
    	TEDelete( teH ) ;
 		TEInsert( value , value.Length() , teH ) ;
@@ -2036,8 +2036,8 @@ void wxTextCtrl::Remove(long from, long to)
    
    	selection.selStart = from ;
    	selection.selEnd = to ;
-   	::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-	::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   	::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+	::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    	TEDelete( teH ) ;
   }
   else
@@ -2055,19 +2055,19 @@ void wxTextCtrl::SetSelection(long from, long to)
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
    selection.selStart = from ;
    selection.selEnd = to ;
    
-   ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+   ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
    TESetSelect( selection.selStart , selection.selEnd , teH ) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
         /* set up our locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* and our drawing environment as the operation
         may force a redraw in the text area. */
     SetPort((**tpvars).fDrawingEnvironment);
@@ -2098,14 +2098,14 @@ void wxTextCtrl::WriteText(const wxString& text)
       TEHandle teH ;
       long size ;
           
-      ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+      ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
         TEInsert( value , value.Length() , teH ) ;
         }
         else
         {
         STPTextPaneVars **tpvars;
             /* set up locals */
-        tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+        tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
             /* set the text in the record */
         TXNSetData( (**tpvars).fTXNRec, kTXNTextData,  (const char*)value, value.Length(),
           kTXNUseCurrentSelection, kTXNUseCurrentSelection);
@@ -2124,11 +2124,11 @@ void wxTextCtrl::Clear()
   if ( m_windowStyle & wxTE_PASSWORD )
   {
 
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
   }
   else
   {
-    mUPDoEditCommand( m_macControl , kmUPClear) ;
+    mUPDoEditCommand( (ControlHandle) m_macControl , kmUPClear) ;
   }
 	Refresh() ;
 }
@@ -2374,7 +2374,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
     short keychar ;
     keychar = short(ev->message & charCodeMask);
     keycode = short(ev->message & keyCodeMask) >> 8 ;
-    UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ;
+    UMAHandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
     if ( keychar >= 0x20 || event.KeyCode() == WXK_RETURN || event.KeyCode() == WXK_DELETE || event.KeyCode() == WXK_BACK)
     {
         wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
diff --git a/src/mac/carbon/thread.cpp b/src/mac/carbon/thread.cpp
index a8243467ed..c68fd396de 100644
--- a/src/mac/carbon/thread.cpp
+++ b/src/mac/carbon/thread.cpp
@@ -34,6 +34,10 @@
 #include "wx/module.h"
 #include "wx/thread.h"
 
+#ifdef __WXMAC__
+#include "wx/mac/private.h"
+#endif
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
diff --git a/src/mac/carbon/timer.cpp b/src/mac/carbon/timer.cpp
index f2b5f2e896..e2693c3e8a 100644
--- a/src/mac/carbon/timer.cpp
+++ b/src/mac/carbon/timer.cpp
@@ -19,6 +19,17 @@
 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
 #endif
 
+#ifdef __WXMAC__
+#include "wx/mac/private.h"
+#endif
+
+typedef struct MacTimerInfo
+{
+    TMTask m_task;
+    wxMacNotifierTableRef m_table ;
+    wxTimer* m_timer ;
+} ;
+
 static void wxProcessTimer( unsigned long event , void *data ) ;
 
 static pascal void MacTimerProc( TMTask * t )
@@ -38,30 +49,33 @@ static void wxProcessTimer( unsigned long event , void *data )
 		
     timer->Notify();
 
-    if ( timer->m_info.m_task.tmAddr && !timer->IsOneShot() )
+    if ( timer->m_info->m_task.tmAddr && !timer->IsOneShot() )
     {
-	    PrimeTime( (QElemPtr)  &timer->m_info.m_task , timer->GetInterval() ) ;
+	    PrimeTime( (QElemPtr)  &timer->m_info->m_task , timer->GetInterval() ) ;
     }
 }
 
 void wxTimer::Init()
 {
-	m_info.m_task.tmAddr = NULL ;
-	m_info.m_task.tmWakeUp = 0 ;
-	m_info.m_task.tmReserved = 0 ;
-	m_info.m_task.qType = 0 ;
-	m_info.m_table = wxMacGetNotifierTable() ;
-	m_info.m_timer = this ;
+    m_info = new MacTimerInfo() ;
+	m_info->m_task.tmAddr = NULL ;
+	m_info->m_task.tmWakeUp = 0 ;
+	m_info->m_task.tmReserved = 0 ;
+	m_info->m_task.qType = 0 ;
+	m_info->m_table = wxMacGetNotifierTable() ;
+	m_info->m_timer = this ;
 }
 
 bool wxTimer::IsRunning() const 
 {
-	return ( m_info.m_task.qType & kTMTaskActive ) ;
+	return ( m_info->m_task.qType & kTMTaskActive ) ;
 }
 
 wxTimer::~wxTimer()
 {
     Stop();
+    delete m_info ;
+    m_info = NULL ;
 }
 
 bool wxTimer::Start(int milliseconds,bool mode)
@@ -69,31 +83,31 @@ bool wxTimer::Start(int milliseconds,bool mode)
     (void)wxTimerBase::Start(milliseconds, mode);
 
     wxCHECK_MSG( m_milli > 0, FALSE, wxT("invalid value for timer timeour") );
-    wxCHECK_MSG( m_info.m_task.tmAddr == NULL , FALSE, wxT("attempting to restart a timer") );
+    wxCHECK_MSG( m_info->m_task.tmAddr == NULL , FALSE, wxT("attempting to restart a timer") );
 
     m_milli = milliseconds;
 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
-    m_info.m_task.tmAddr = NewTimerUPP( MacTimerProc ) ;
+    m_info->m_task.tmAddr = NewTimerUPP( MacTimerProc ) ;
 #else
-    m_info.m_task.tmAddr = NewTimerProc( MacTimerProc ) ;
+    m_info->m_task.tmAddr = NewTimerProc( MacTimerProc ) ;
 #endif
-    m_info.m_task.tmWakeUp = 0 ;
-    m_info.m_task.tmReserved = 0 ;
-	m_info.m_task.qType = 0 ;
-	m_info.m_timer = this ;
-    InsXTime((QElemPtr) &m_info.m_task ) ;
-    PrimeTime( (QElemPtr) &m_info.m_task , m_milli ) ;
+    m_info->m_task.tmWakeUp = 0 ;
+    m_info->m_task.tmReserved = 0 ;
+	m_info->m_task.qType = 0 ;
+	m_info->m_timer = this ;
+    InsXTime((QElemPtr) &m_info->m_task ) ;
+    PrimeTime( (QElemPtr) &m_info->m_task , m_milli ) ;
     return FALSE;
 }
 
 void wxTimer::Stop()
 {
     m_milli = 0 ;
-    if ( m_info.m_task.tmAddr )
+    if ( m_info->m_task.tmAddr )
     {
-    	RmvTime(  (QElemPtr) &m_info.m_task ) ;
-    	DisposeTimerUPP(m_info.m_task.tmAddr) ;
-    	m_info.m_task.tmAddr = NULL ;
+    	RmvTime(  (QElemPtr) &m_info->m_task ) ;
+    	DisposeTimerUPP(m_info->m_task.tmAddr) ;
+    	m_info->m_task.tmAddr = NULL ;
     }
     wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ;
 }
diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp
index 9604fbc2c1..66bed14b79 100644
--- a/src/mac/carbon/toolbar.cpp
+++ b/src/mac/carbon/toolbar.cpp
@@ -168,7 +168,7 @@ bool wxToolBar::Realize()
 
     Point localOrigin ;
     Rect clipRect ;
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
     wxWindow *win ;
     
     int lx , ly ;
@@ -215,20 +215,20 @@ bool wxToolBar::Realize()
                 if ( bmap->m_bitmapType == kMacBitmapTypePict )
                 {
                     info.contentType = kControlContentPictHandle ;
-                    info.u.picture = bmap->m_hPict ;
+                    info.u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
                 }
                 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
                 {
                     if ( tool->GetBitmap1().GetMask() )
                     {
                         info.contentType = kControlContentCIconHandle ;
-                        info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , tool->GetBitmap1().GetMask()->GetMaskBitmap() ,
+                        info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(tool->GetBitmap1().GetMask()->GetMaskBitmap()) ,
                                                                8 , 16 ) ;
                     }
                     else
                     {
                         info.contentType = kControlContentCIconHandle ;
-                        info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , NULL ,
+                        info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
                                                                8 , 16 ) ;
                     }
                 }
@@ -270,7 +270,7 @@ bool wxToolBar::Realize()
             /*
               ::SetControlFontStyle( m_macToolHandle , &controlstyle ) ;
             */
-            ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
+            ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
             wxASSERT_MSG( container != NULL , "No valid mac container control" ) ;
             ::EmbedControl( m_macToolHandle , container ) ;
             
@@ -346,7 +346,7 @@ wxSize wxToolBar::GetToolSize() const
     return wxSize(m_defaultWidth + 4, m_defaultHeight + 4);
 }
 
-void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
     int index = 0 ;
     for ( index = 0 ; index < m_macToolHandles.Count() ; ++index )
@@ -356,7 +356,7 @@ void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpar
             wxToolBarTool *tool = (wxToolBarTool *)m_tools.Nth( index )->Data();
             if ( tool->CanBeToggled() )
             {
-                tool->Toggle( GetControlValue( control ) ) ;
+                tool->Toggle( GetControlValue( (ControlHandle) control ) ) ;
             }
             OnLeftClick( tool->GetId() , tool -> IsToggled() ) ;
             break ;
@@ -410,7 +410,7 @@ void wxToolBar::MacSuperChangedPosition()
     int maxHeight = 0 ;
     int toolcount = 0 ;
     {
-      WindowRef rootwindow = MacGetRootWindow() ;
+      WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
     	while (node)
     	{
     		wxToolBarTool *tool = (wxToolBarTool *)node->Data();
@@ -611,7 +611,7 @@ void  wxToolBar::OnMouse( wxMouseEvent &event )
 		Point		localwhere ;
 		GrafPtr		port ;
 		SInt16		controlpart ;
-		WindowRef	window = MacGetRootWindow() ;
+		WindowRef	window = (WindowRef) MacGetRootWindow() ;
 		
 		localwhere.h = x ;
 		localwhere.v = y ;
diff --git a/src/mac/carbon/tooltip.cpp b/src/mac/carbon/tooltip.cpp
index 45877f9a1c..0655699087 100644
--- a/src/mac/carbon/tooltip.cpp
+++ b/src/mac/carbon/tooltip.cpp
@@ -21,13 +21,14 @@
 #include "wx/tooltip.h"
 #include "wx/timer.h"
 #include "wx/geometry.h"
-#include "wx/mac/aga.h"
 #include "wx/mac/uma.h"
 
 //-----------------------------------------------------------------------------
 // global data
 //-----------------------------------------------------------------------------
 
+class wxMacToolTipTimer ;
+
 class wxMacToolTip
 {
 	public :
@@ -48,6 +49,7 @@ class wxMacToolTip
 		PicHandle	m_backpict ;
 		bool		m_shown ;
 		long		m_mark ;
+		wxMacToolTipTimer* m_timer ;
 } ;
 
 class wxMacToolTipTimer : wxTimer
@@ -60,7 +62,6 @@ public:
 		if ( m_mark == m_tip->GetMark() )
 			m_tip->Draw() ;
 
-		delete this;
 	}
 	
 protected:
@@ -148,7 +149,7 @@ void wxToolTip::RelayEvent( wxWindow *win , wxMouseEvent &event )
 				s_ToolTipArea = wxRect2DInt( event.m_x - 2 , event.m_y - 2 , 4 , 4 ) ;
 				s_LastWindowEntered = win ;
 				
-				WindowRef window = win->MacGetRootWindow() ;
+				WindowRef window = MAC_WXHWND( win->MacGetRootWindow() ) ;
 				int x = event.m_x ;
 				int y = event.m_y ;
 				wxPoint local( x , y ) ;
@@ -179,6 +180,7 @@ wxMacToolTip::wxMacToolTip()
 	m_backpict = NULL ;
 	m_mark = 0 ;
 	m_shown = false ;
+    m_timer = NULL ;
 }
 
 void wxMacToolTip::Setup( WindowRef window  , wxString text , wxPoint localPosition ) 
@@ -190,11 +192,15 @@ void wxMacToolTip::Setup( WindowRef window  , wxString text , wxPoint localPosit
 	m_window = window ;
 	s_ToolTipWindowRef = window ;
 	m_backpict = NULL ;
-	new wxMacToolTipTimer( this , s_ToolTipDelay ) ;
+	if ( m_timer )
+	    delete m_timer ;
+	m_timer = new wxMacToolTipTimer( this , s_ToolTipDelay ) ;
 }
 
 wxMacToolTip::~wxMacToolTip() 
 {
+    if ( m_timer )
+        delete m_timer ;
 	if ( m_backpict ) 
 		Clear() ;
 }
@@ -219,11 +225,8 @@ void wxMacToolTip::Draw()
 */
 #endif
 	  {
-  		#if TARGET_CARBON
-  		AGAPortHelper help( GetWindowPort( m_window ) );
-  		#else
-  		AGAPortHelper help( ( m_window ) );
-  		#endif
+   		wxMacPortStateHelper help( GetWindowPort( m_window ) );
+ 
   		m_shown = true ;
 
   		TextFont( kFontIDGeneva ) ;
@@ -309,7 +312,7 @@ void wxMacToolTip::Draw()
 	}
 }
 
-void wxToolTip::NotifyWindowDelete( WindowRef win ) 
+void wxToolTip::NotifyWindowDelete( WXHWND win ) 
 {
 	if ( win == s_ToolTipWindowRef )
 	{
@@ -325,11 +328,8 @@ void wxMacToolTip::Clear()
 		 
 	if ( m_window == s_ToolTipWindowRef && m_backpict )
 	{
-		#if TARGET_CARBON
-		AGAPortHelper help( GetWindowPort(m_window) ) ;
-		#else
-		AGAPortHelper help( (m_window) ) ;
-		#endif
+		wxMacPortStateHelper help( GetWindowPort(m_window) ) ;
+
 		m_shown = false ;
 
 		BackColor( whiteColor ) ;
diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp
index 8c84e811e0..83b905c227 100644
--- a/src/mac/carbon/toplevel.cpp
+++ b/src/mac/carbon/toplevel.cpp
@@ -65,7 +65,7 @@ wxWindowList wxModelessWindows;
 // Find an item given the Macintosh Window Reference
 
 wxList *wxWinMacWindowList = NULL;
-wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
+wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef)
 {
     wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
     if (!node)
@@ -73,7 +73,7 @@ wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
     return (wxTopLevelWindowMac *)node->Data();
 }
 
-void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win)
+void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win)
 {
     // adding NULL WindowRef is (first) surely a result of an error and
     // (secondly) breaks menu command processing
@@ -93,7 +93,7 @@ void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
 // wxTopLevelWindowMac creation
 // ----------------------------------------------------------------------------
 
-WindowRef wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
+WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
 
 void wxTopLevelWindowMac::Init()
 {
@@ -131,7 +131,7 @@ bool wxTopLevelWindowMac::Create(wxWindow *parent,
 wxTopLevelWindowMac::~wxTopLevelWindowMac()
 {
     wxToolTip::NotifyWindowDelete(m_macWindow) ;
-    UMADisposeWindow( m_macWindow ) ;
+    UMADisposeWindow( (WindowRef) m_macWindow ) ;
 
     wxRemoveMacWindowAssociation( this ) ;
 
@@ -150,7 +150,7 @@ wxTopLevelWindowMac::~wxTopLevelWindowMac()
           wxTheApp->ExitMainLoop() ;        
         }
     }
-    DisposeRgn( m_macNoEraseUpdateRgn ) ;
+    DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
 }
 
 
@@ -267,27 +267,27 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
         attr |= kWindowCloseBoxAttribute ;
     }
     
-    ::CreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindow ) ;
+    ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
     wxAssociateWinWithMacWindow( m_macWindow , this ) ;
     wxString label ;
     if( wxApp::s_macDefaultEncodingIsPC )
         label = wxMacMakeMacStringFromPC( title ) ;
     else
         label = title ;
-    UMASetWTitleC( m_macWindow , label ) ;
-    ::CreateRootControl( m_macWindow , &m_macRootControl ) ;
+    UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
+    ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
 
     m_macFocus = NULL ;
 }
 
-void wxTopLevelWindowMac::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window  , wxWindowMac** rootwin) 
+void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window  , wxWindowMac** rootwin) 
 {
-    localOrigin->h = 0;
-    localOrigin->v = 0;
-    clipRect->left = 0;
-    clipRect->top = 0;
-    clipRect->right = m_width;
-    clipRect->bottom = m_height;
+    ((Point*)localOrigin)->h = 0;
+    ((Point*)localOrigin)->v = 0;
+    ((Rect*)clipRect)->left = 0;
+    ((Rect*)clipRect)->top = 0;
+    ((Rect*)clipRect)->right = m_width;
+    ((Rect*)clipRect)->bottom = m_height;
     *window = m_macWindow ;
     *rootwin = this ;
 }
@@ -297,7 +297,7 @@ void wxTopLevelWindowMac::Clear()
   wxWindow::Clear() ;
 }
 
-ControlHandle wxTopLevelWindowMac::MacGetContainerForEmbedding() 
+WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding() 
 {
     return m_macRootControl ;
 }
@@ -305,19 +305,17 @@ ControlHandle wxTopLevelWindowMac::MacGetContainerForEmbedding()
 
 void wxTopLevelWindowMac::MacUpdate( long timestamp)
 {
-    #if TARGET_CARBON
-    AGAPortHelper help( GetWindowPort(m_macWindow) ) ;
-    #else
-    AGAPortHelper help( (m_macWindow) ) ;
-    #endif
-    BeginUpdate( m_macWindow ) ;
+
+    wxMacPortStateHelper help( GetWindowPort( (WindowRef) m_macWindow) ) ;
+
+    BeginUpdate( (WindowRef)m_macWindow ) ;
 
     RgnHandle       updateRgn = NewRgn();    
     RgnHandle       diffRgn = NewRgn() ;
     if ( updateRgn && diffRgn )
     {
-        GetPortVisibleRegion( GetWindowPort( m_macWindow ), updateRgn );
-        DiffRgn( updateRgn , m_macNoEraseUpdateRgn , diffRgn ) ;
+        GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn );
+        DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
         if ( !EmptyRgn( updateRgn ) )
         {
             MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn )  ) ;
@@ -327,8 +325,8 @@ void wxTopLevelWindowMac::MacUpdate( long timestamp)
         DisposeRgn( updateRgn );
     if ( diffRgn )
         DisposeRgn( diffRgn );
-    EndUpdate( m_macWindow ) ;
-    SetEmptyRgn( m_macNoEraseUpdateRgn ) ;
+    EndUpdate( (WindowRef)m_macWindow ) ;
+    SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
     m_macNeedsErasing = false ;
 }
 
@@ -336,21 +334,22 @@ void wxTopLevelWindowMac::MacUpdate( long timestamp)
 // Raise the window to the top of the Z order
 void wxTopLevelWindowMac::Raise()
 {
-    ::BringToFront( m_macWindow ) ;
+    ::BringToFront( (WindowRef)m_macWindow ) ;
 }
 
 // Lower the window to the bottom of the Z order
 void wxTopLevelWindowMac::Lower()
 {
-    ::SendBehind( m_macWindow , NULL ) ;
+    ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
 }
 
 Point lastWhere ;
 long lastWhen = 0 ;
 extern int wxBusyCursorCount ;
 
-void wxTopLevelWindowMac::MacFireMouseEvent( EventRecord *ev )
+void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr )
 {
+    EventRecord *ev = (EventRecord*) evr ;
     wxMouseEvent event(wxEVT_LEFT_DOWN);
     bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
     bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
@@ -388,7 +387,7 @@ void wxTopLevelWindowMac::MacFireMouseEvent( EventRecord *ev )
         
     GrafPtr     port ;  
     ::GetPort( &port ) ;
-    ::SetPort( UMAGetWindowPort( m_macWindow ) ) ;
+    ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ;
     ::GlobalToLocal( &localwhere ) ;
     ::SetPort( port ) ;
 
@@ -449,12 +448,12 @@ void wxTopLevelWindowMac::MacFireMouseEvent( EventRecord *ev )
     }
 }
 
-void wxTopLevelWindowMac::MacMouseDown( EventRecord *ev , short part)
+void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part)
 {
     MacFireMouseEvent( ev ) ;
 }
 
-void wxTopLevelWindowMac::MacMouseUp( EventRecord *ev , short part)
+void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part)
 {
     switch (part)
     {
@@ -466,7 +465,7 @@ void wxTopLevelWindowMac::MacMouseUp( EventRecord *ev , short part)
     }
 }
 
-void wxTopLevelWindowMac::MacMouseMoved( EventRecord *ev , short part)
+void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part)
 {
     switch (part)
     {
@@ -477,20 +476,20 @@ void wxTopLevelWindowMac::MacMouseMoved( EventRecord *ev , short part)
             break ;
     }
 }
-void wxTopLevelWindowMac::MacActivate( EventRecord *ev , bool inIsActivating )
+void wxTopLevelWindowMac::MacActivate( WXEVENTREF ev , bool inIsActivating )
 {
     wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
-    event.m_timeStamp = ev->when ;
+    event.m_timeStamp = ((EventRecord*)ev)->when ;
     event.SetEventObject(this);
     
     GetEventHandler()->ProcessEvent(event);
     
-    UMAHighlightAndActivateWindow( m_macWindow , inIsActivating ) ;
+    UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ;
     
     MacSuperEnabled( inIsActivating ) ;
 }
 
-void wxTopLevelWindowMac::MacKeyDown( EventRecord *ev ) 
+void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ) 
 {
 }
 
@@ -505,7 +504,7 @@ void wxTopLevelWindowMac::SetTitle(const wxString& title)
     else
         label = m_label ;
 
-    UMASetWTitleC( m_macWindow , label ) ;
+    UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
 }
 
 bool wxTopLevelWindowMac::Show(bool show)
@@ -515,8 +514,8 @@ bool wxTopLevelWindowMac::Show(bool show)
 
     if (show)
     {
-      ::ShowWindow( m_macWindow ) ;
-      ::SelectWindow( m_macWindow ) ;
+      ::ShowWindow( (WindowRef)m_macWindow ) ;
+      ::SelectWindow( (WindowRef)m_macWindow ) ;
       // no need to generate events here, they will get them triggered by macos
       // actually they should be , but apparently they are not
       wxSize size(m_width, m_height);
@@ -526,7 +525,7 @@ bool wxTopLevelWindowMac::Show(bool show)
     }
     else
     {
-      ::HideWindow( m_macWindow ) ;
+      ::HideWindow( (WindowRef)m_macWindow ) ;
     }
 
     if ( !show )
@@ -581,10 +580,10 @@ void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
         m_height = actualHeight ;
 
         if ( doMove )
-            ::MoveWindow(m_macWindow, m_x, m_y  , false); // don't make frontmost
+            ::MoveWindow((WindowRef)m_macWindow, m_x, m_y  , false); // don't make frontmost
         
         if ( doResize )
-            ::SizeWindow(m_macWindow, m_width, m_height  , true); 
+            ::SizeWindow((WindowRef)m_macWindow, m_width, m_height  , true); 
         
         // the OS takes care of invalidating and erasing the new area
         // we have erased the old one   
@@ -632,11 +631,11 @@ void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
  * will get the eraseBackground event first
  */
  
-void wxTopLevelWindowMac::MacInvalidate( const Rect * rect, bool eraseBackground ) 
+void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ) 
 {
   GrafPtr formerPort ;
   GetPort( &formerPort ) ;
-  SetPortWindowPort( m_macWindow ) ;
+  SetPortWindowPort( (WindowRef)m_macWindow ) ;
   
   m_macNeedsErasing |= eraseBackground ;
   
@@ -651,11 +650,11 @@ void wxTopLevelWindowMac::MacInvalidate( const Rect * rect, bool eraseBackground
     RgnHandle       diffRgn = NewRgn() ;
     if ( updateRgn && diffRgn )
     {
-        GetWindowUpdateRgn( m_macWindow , updateRgn );
+        GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn );
         Point pt = {0,0} ;
         LocalToGlobal( &pt ) ;
         OffsetRgn( updateRgn , -pt.h , -pt.v ) ;
-        DiffRgn( updateRgn , m_macNoEraseUpdateRgn , diffRgn ) ;
+        DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
         if ( !EmptyRgn( diffRgn ) )
         {
             m_macNeedsErasing = true ;
@@ -669,12 +668,12 @@ void wxTopLevelWindowMac::MacInvalidate( const Rect * rect, bool eraseBackground
     if ( !m_macNeedsErasing )
     {
       RgnHandle rectRgn = NewRgn() ;
-      SetRectRgn( rectRgn , rect->left , rect->top , rect->right , rect->bottom ) ;
-      UnionRgn( m_macNoEraseUpdateRgn , rectRgn , m_macNoEraseUpdateRgn ) ;
+      SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ;
+      UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ;
       DisposeRgn( rectRgn ) ;
     }
   }
-  InvalWindowRect( m_macWindow , rect ) ;
+  InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ;
   // turn this on to debug the refreshing cycle
 #if wxMAC_DEBUG_REDRAW
   PaintRect( rect ) ;
diff --git a/src/mac/carbon/uma.cpp b/src/mac/carbon/uma.cpp
index f76e815114..1c31f87d4c 100644
--- a/src/mac/carbon/uma.cpp
+++ b/src/mac/carbon/uma.cpp
@@ -142,6 +142,7 @@ bool UMAGetProcessModeDoesActivateOnFGSwitch()
 
 void UMASetMenuTitle( MenuRef menu , StringPtr title )
 {
+/*
 #if !TARGET_CARBON
 	long 			size = GetHandleSize( (Handle) menu ) ;
 	const long 		headersize = 14 ;
@@ -164,8 +165,9 @@ void UMASetMenuTitle( MenuRef menu , StringPtr title )
 		SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
 	}
 #else
+*/
 	SetMenuTitle( menu , title ) ;
-#endif
+//#endif
 }
 
 UInt32 UMAMenuEvent( EventRecord *inEvent )
@@ -602,3 +604,55 @@ OSStatus UMAGetHelpMenu(
   return helpMenuStatus ;
 #endif
 }
+
+wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport) 
+{
+  m_clip = NULL ;
+  Setup( newport ) ;
+}
+
+wxMacPortStateHelper::wxMacPortStateHelper()
+{
+	m_clip = NULL ;
+}
+
+void wxMacPortStateHelper::Setup( GrafPtr newport )
+{
+	GetPort( &m_oldPort ) ;
+	SetPort( newport ) ;
+	wxASSERT_MSG( m_clip == NULL , "Cannot call setup twice" ) ;
+	m_clip = NewRgn() ;
+	GetClip( m_clip );
+	m_textFont = GetPortTextFont( (CGrafPtr) newport);
+	m_textSize = GetPortTextSize( (CGrafPtr) newport);
+	m_textStyle = GetPortTextFace( (CGrafPtr) newport);
+	m_textMode = GetPortTextMode( (CGrafPtr) newport);	
+	GetThemeDrawingState( &m_drawingState ) ;
+	m_currentPort = newport ;
+}
+void wxMacPortStateHelper::Clear()
+{
+	if ( m_clip )
+	{
+		DisposeRgn( m_clip ) ;
+		DisposeThemeDrawingState( m_drawingState ) ;
+		m_clip = NULL ;
+	}
+}
+
+wxMacPortStateHelper::~wxMacPortStateHelper()
+{
+	if ( m_clip )
+	{
+		SetPort( m_currentPort ) ;
+		SetClip( m_clip ) ;
+		DisposeRgn( m_clip ) ;
+		TextFont( m_textFont );
+		TextSize( m_textSize );
+		TextFace( m_textStyle );
+		TextMode( m_textMode );
+		SetThemeDrawingState( m_drawingState , true ) ;
+		SetPort( m_oldPort ) ;
+	}
+}
+
diff --git a/src/mac/carbon/wave.cpp b/src/mac/carbon/wave.cpp
index f0891a6546..d06eee4838 100644
--- a/src/mac/carbon/wave.cpp
+++ b/src/mac/carbon/wave.cpp
@@ -17,6 +17,10 @@
 #include "wx/string.h"
 #include "wx/wave.h"
 
+#ifdef __WXMAC__
+#include "wx/mac/private.h"
+#endif
+
 wxWave::wxWave()
   : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true)
 {
@@ -136,7 +140,7 @@ bool wxWave::Play(bool async, bool looped) const
 	  
 	  hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd);
 
-	  if ((hSnd != NULL) && (SndPlay(m_sndChan, hSnd, async) == noErr))
+	  if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, async) == noErr))
 	    ret = true;
 	} 
 	
diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp
index 7bf95a6ca3..bd38b3ccd2 100644
--- a/src/mac/carbon/window.cpp
+++ b/src/mac/carbon/window.cpp
@@ -205,7 +205,7 @@ void wxWindowMac::SetFocus()
             wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
             if ( control && control->GetMacControl() )
             {
-                UMASetKeyboardFocus( gFocusWindow->MacGetRootWindow() , control->GetMacControl()  , kControlFocusNoPart ) ;
+                UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl()  , kControlFocusNoPart ) ;
                 control->MacRedrawControl() ;
             }
             #endif
@@ -230,7 +230,7 @@ void wxWindowMac::SetFocus()
             wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
             if ( control && control->GetMacControl() )
             {
-                UMASetKeyboardFocus( gFocusWindow->MacGetRootWindow() , control->GetMacControl()  , kControlEditTextPart ) ;
+                UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl()  , kControlEditTextPart ) ;
             }
       #endif
             wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
@@ -318,8 +318,8 @@ bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
     menu->UpdateUI();
     ClientToScreen( &x , &y ) ;
 
-    ::InsertMenu( menu->GetHMenu() , -1 ) ;
-    long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ;
+    ::InsertMenu( (MenuHandle) menu->GetHMenu() , -1 ) ;
+    long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
     menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ;
     ::DeleteMenu( menu->MacGetMenuId() ) ;
     menu->SetInvokingWindow(NULL);
@@ -330,7 +330,7 @@ bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
 
 void wxWindowMac::DoScreenToClient(int *x, int *y) const
 {
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
 
     Point       localwhere = {0,0} ;
 
@@ -351,7 +351,7 @@ void wxWindowMac::DoScreenToClient(int *x, int *y) const
 
 void wxWindowMac::DoClientToScreen(int *x, int *y) const
 {
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
     
     MacClientToRootWindow( x , y ) ;
     
@@ -681,7 +681,7 @@ bool wxWindowMac::Show(bool show)
     MacSuperShown( show ) ;
     if ( !show )
     {
-        WindowRef window = MacGetRootWindow() ;
+        WindowRef window = (WindowRef) MacGetRootWindow() ;
         wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
         if ( win && !win->m_isBeingDeleted )
             Refresh() ; 
@@ -869,7 +869,7 @@ const wxBrush& wxWindowMac::MacGetBackgroundBrush()
         // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
         // either a non gray background color or a non control window
         
-            WindowRef window = MacGetRootWindow() ;
+            WindowRef window = (WindowRef) MacGetRootWindow() ;
             
             wxWindowMac* parent = GetParent() ;
             while( parent )
@@ -902,7 +902,7 @@ const wxBrush& wxWindowMac::MacGetBackgroundBrush()
                         extent.top-- ;
                         extent.right = x + size.x ;
                         extent.bottom = y + size.y ;
-                        m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , extent ) ; // todo eventually change for inactive
+                        m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive
                         break ;
                     }
                 }
@@ -932,7 +932,7 @@ void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
     wxWindowDC dc(this) ;
     wxMacPortSetter helper(&dc) ;
     
-    MacPaintBorders( dc.m_macLocalOrigin.h , dc.m_macLocalOrigin.v) ;
+    MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
 }
 
 int wxWindowMac::GetScrollPos(int orient) const
@@ -1120,7 +1120,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
             SectRect( &scrollrect , &r , &scrollrect ) ;        
         }
         ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
-        InvalWindowRgn( MacGetRootWindow() ,  updateRgn ) ;
+        InvalWindowRgn( (WindowRef) MacGetRootWindow() ,  updateRgn ) ;
         DisposeRgn( updateRgn ) ;
     }
     
@@ -1309,7 +1309,7 @@ bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac**
           return FALSE;
     }
     
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
 
     wxPoint newPoint( point ) ;
 
@@ -1363,7 +1363,7 @@ bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
     if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) )
         return FALSE ; 
     
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
 
     event.m_x -= m_x;
     event.m_y -= m_y;
@@ -1425,7 +1425,7 @@ void wxWindowMac::Update()
 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const 
 {
     wxTopLevelWindowMac* win = NULL ;
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
     if ( window )
     {
         win = wxFindWinFromMacWindow( window ) ;
@@ -1510,19 +1510,20 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion()
   return m_macVisibleRegion ;
 }
 
-void wxWindowMac::MacRedraw( RgnHandle updatergn , long time, bool erase)
+void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
 {
+    RgnHandle updatergn = (RgnHandle) updatergnr ;
     // updatergn is always already clipped to our boundaries
     // it is in window coordinates, not in client coordinates
     
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
 
     {
         // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
         RgnHandle ownUpdateRgn = NewRgn() ;
         CopyRgn( updatergn , ownUpdateRgn ) ;
                 
-        SectRgn( ownUpdateRgn , MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ;
+        SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ;
         
         // newupdate is the update region in client coordinates
         RgnHandle newupdate = NewRgn() ;
@@ -1578,7 +1579,7 @@ void wxWindowMac::MacRedraw( RgnHandle updatergn , long time, bool erase)
  
 }
 
-WindowRef wxWindowMac::MacGetRootWindow() const
+WXHWND wxWindowMac::MacGetRootWindow() const
 {
     wxWindowMac *iter = (wxWindowMac*)this ;
     
@@ -1711,7 +1712,7 @@ bool wxWindowMac::AcceptsFocus() const
     return MacCanFocus() && wxWindowBase::AcceptsFocus();
 }
 
-ControlHandle wxWindowMac::MacGetContainerForEmbedding() 
+WXWidget wxWindowMac::MacGetContainerForEmbedding() 
 {
     return GetParent()->MacGetContainerForEmbedding() ;
 }
diff --git a/src/mac/checkbox.cpp b/src/mac/checkbox.cpp
index d6d532e538..85ebcf2391 100644
--- a/src/mac/checkbox.cpp
+++ b/src/mac/checkbox.cpp
@@ -36,7 +36,7 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
 	
 	MacPreControlCreate( parent , id ,  label , pos , size ,style, validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlCheckBoxProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
@@ -46,13 +46,13 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
 
 void wxCheckBox::SetValue(bool val)
 {
-   ::SetControlValue( m_macControl , val ) ;
+   ::SetControlValue( (ControlHandle) m_macControl , val ) ;
    MacRedrawControl() ;
 }
 
 bool wxCheckBox::GetValue() const
 {
-    return ::GetControlValue( m_macControl ) ;
+    return ::GetControlValue( (ControlHandle) m_macControl ) ;
 }
 
 void wxCheckBox::Command (wxCommandEvent & event)
@@ -61,7 +61,7 @@ void wxCheckBox::Command (wxCommandEvent & event)
     ProcessCommand (event);
 }
 
-void wxCheckBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxCheckBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
 	SetValue( !GetValue() ) ;
     wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
diff --git a/src/mac/checklst.cpp b/src/mac/checklst.cpp
index 7d8bec19e8..743fea9aac 100644
--- a/src/mac/checklst.cpp
+++ b/src/mac/checklst.cpp
@@ -109,10 +109,10 @@ static pascal void wxMacCheckListDefinition( short message, Boolean isSelected,
             //  appropriate QuickDraw transform mode.
             
             if( isSelected ) {
-                savedPenMode = GetPortPenMode( grafPtr );
-                SetPortPenMode( grafPtr, hilitetransfermode );
+                savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
+                SetPortPenMode( (CGrafPtr) grafPtr, hilitetransfermode );
                 PaintRect( drawRect );
-                SetPortPenMode( grafPtr, savedPenMode );
+                SetPortPenMode( (CGrafPtr) grafPtr, savedPenMode );
             }
             
             //  Restore the saved clip region.
@@ -127,10 +127,10 @@ static pascal void wxMacCheckListDefinition( short message, Boolean isSelected,
             //  appropriate QuickDraw transform mode.
             
             GetPort( &grafPtr );
-            savedPenMode = GetPortPenMode( grafPtr );
-            SetPortPenMode( grafPtr, hilitetransfermode );
+            savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
+            SetPortPenMode( (CGrafPtr) grafPtr, hilitetransfermode );
             PaintRect( drawRect );
-            SetPortPenMode( grafPtr, savedPenMode );
+            SetPortPenMode( (CGrafPtr) grafPtr, savedPenMode );
             break;
         default :
           break ;
@@ -183,36 +183,36 @@ bool wxCheckListBox::Create(wxWindow *parent,
     CreateListBoxControl( parent->MacGetRootWindow(), &bounds, false, 0, 1, false, true,
                           14, 14, false, &listDef, &m_macControl );
 
-    GetControlData(m_macControl, kControlNoPart, kControlListBoxListHandleTag,
+    GetControlData( (ControlHandle) m_macControl, kControlNoPart, kControlListBoxListHandleTag,
                    sizeof(ListHandle), (Ptr) &m_macList, &asize);
 
-    SetControlReference(m_macControl, (long) this);
-    SetControlVisibility(m_macControl, false, false);
+    SetControlReference( (ControlHandle) m_macControl, (long) this);
+    SetControlVisibility( (ControlHandle) m_macControl, false, false);
 
 #else
 
     long    result ;
 
-    m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false ,
+    m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
                   kwxMacListWithVerticalScrollbar , 0 , 0, 
                   kControlListBoxProc , (long) this ) ;
-    ::GetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
+    ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
                sizeof( ListHandle ) , (char*) &m_macList  , &result ) ;
 
     HLock( (Handle) m_macList ) ;
     ldefHandle ldef ;
     ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ;
-    if (  (**m_macList).listDefProc != NULL )
+    if (  (**(ListHandle)m_macList).listDefProc != NULL )
     {
       (**ldef).instruction = 0x4EF9;  /* JMP instruction */
       (**ldef).function = (void(*)()) listDef.u.userProc;
-      (**m_macList).listDefProc = (Handle) ldef ;
+      (**(ListHandle)m_macList).listDefProc = (Handle) ldef ;
     }
         
-    Point pt = (**m_macList).cellSize ;
+    Point pt = (**(ListHandle)m_macList).cellSize ;
     pt.v = 14 ;
-    LCellSize( pt , m_macList ) ;
-    LAddColumn( 1 , 0 , m_macList ) ;
+    LCellSize( pt , (ListHandle)m_macList ) ;
+    LAddColumn( 1 , 0 , (ListHandle)m_macList ) ;
 #endif
     OptionBits  options = 0;
     if ( style & wxLB_MULTIPLE )
@@ -227,7 +227,7 @@ bool wxCheckListBox::Create(wxWindow *parent,
     {
         options = lOnlyOne ;
     }
-    SetListSelectionFlags(m_macList, options);
+    SetListSelectionFlags((ListHandle)m_macList, options);
     
     MacPostControlCreate() ;
     
@@ -236,7 +236,7 @@ bool wxCheckListBox::Create(wxWindow *parent,
         Append( choices[i] ) ;
     }
     
-    LSetDrawingMode( true , m_macList ) ;
+    LSetDrawingMode( true , (ListHandle) m_macList ) ;
 
     return TRUE;
 }
@@ -358,8 +358,8 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event)
     GetListVisibleCells( m_macList , &visible ) ;
     topcell = visible.top ;
 #else
-    lineheight =  (**m_macList).cellSize.v ;
-    topcell = (**m_macList).visible.top ;
+    lineheight =  (**(ListHandle)m_macList).cellSize.v ;
+    topcell = (**(ListHandle)m_macList).visible.top ;
 #endif
     size_t nItem = ((size_t)event.GetY()) / lineheight + topcell ;
     
diff --git a/src/mac/choice.cpp b/src/mac/choice.cpp
index 2ec18bc546..f8068ff829 100644
--- a/src/mac/choice.cpp
+++ b/src/mac/choice.cpp
@@ -45,15 +45,15 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id,
 	
 		MacPreControlCreate( parent , id ,  "" , pos , size ,style, validator , name , &bounds , title ) ;
 
-		m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , -12345 , 0 , 
+		m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , -12345 , 0 , 
 	  	kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ; 
 	
 		m_macPopUpMenuHandle =  NewUniqueMenu() ;
-		SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
-	 	SetControlMinimum( m_macControl , 0 ) ;
-		SetControlMaximum( m_macControl , 0) ;
+		SetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
+	 	SetControlMinimum( (ControlHandle) m_macControl , 0 ) ;
+		SetControlMaximum( (ControlHandle) m_macControl , 0) ;
 		if ( n > 0 )
-			SetControlValue( m_macControl , 1 ) ;
+			SetControlValue( (ControlHandle) m_macControl , 1 ) ;
 
 		MacPostControlCreate() ;
 
@@ -72,12 +72,12 @@ int wxChoice::DoAppend(const wxString& item)
 {
 	Str255 label;
 	wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
-	AppendMenu( m_macPopUpMenuHandle , label ) ;
+	AppendMenu( MAC_WXHMENU( m_macPopUpMenuHandle ) , label ) ;
 	m_strings.Add( item ) ;
 	m_datas.Add( NULL ) ;
 	int index = m_strings.GetCount()  - 1  ;
 	DoSetItemClientData( index , NULL ) ;
-	SetControlMaximum( m_macControl , GetCount()) ;
+	SetControlMaximum( (ControlHandle) m_macControl , GetCount()) ;
 	return index ;
 }
 
@@ -90,10 +90,10 @@ void wxChoice::Delete(int n)
         delete GetClientObject(n);
     }
 
-    ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
+    ::DeleteMenuItem( MAC_WXHMENU(m_macPopUpMenuHandle) , n + 1) ;
     m_strings.Remove( n ) ;
     m_datas.RemoveAt( n ) ;
-	SetControlMaximum( m_macControl , GetCount()) ;
+	SetControlMaximum( (ControlHandle) m_macControl , GetCount()) ;
 }
 
 void wxChoice::Clear()
@@ -102,11 +102,11 @@ void wxChoice::Clear()
 
     for ( int i = 0 ; i < GetCount() ; i++ )
     {
-    	::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
+    	::DeleteMenuItem( MAC_WXHMENU(m_macPopUpMenuHandle) , 1 ) ;
 	  }
     m_strings.Empty() ;
     m_datas.Empty() ;
-	SetControlMaximum( m_macControl , 0 ) ;
+	SetControlMaximum( (ControlHandle) m_macControl , 0 ) ;
 }
 
 void wxChoice::Free()
@@ -127,12 +127,12 @@ void wxChoice::Free()
 
 int wxChoice::GetSelection() const
 {
-    return GetControlValue( m_macControl ) -1 ;
+    return GetControlValue( (ControlHandle) m_macControl ) -1 ;
 }
 
 void wxChoice::SetSelection(int n)
 {
-    SetControlValue( m_macControl , n + 1 ) ;
+    SetControlValue( (ControlHandle) m_macControl , n + 1 ) ;
 }
 
 // ----------------------------------------------------------------------------
@@ -208,7 +208,7 @@ wxClientData* wxChoice::DoGetItemClientObject( int n ) const
     return (wxClientData *)DoGetItemClientData(n);
 }
 
-void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxChoice::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
     wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
 	  event.SetInt(GetSelection());
diff --git a/src/mac/clipbrd.cpp b/src/mac/clipbrd.cpp
index 0d59db9a44..8e3cd77678 100644
--- a/src/mac/clipbrd.cpp
+++ b/src/mac/clipbrd.cpp
@@ -22,6 +22,8 @@
 #include "wx/clipbrd.h"
 #include "wx/intl.h"
 
+#include "wx/mac/private.h"
+
 #define wxUSE_DATAOBJ 1
 
 #include <string.h>
@@ -254,7 +256,7 @@ bool wxClipboard::AddData( wxDataObject *data )
               wxMetafileDataObject* metaFileDataObject =
                 (wxMetafileDataObject*) data;
               wxMetafile metaFile = metaFileDataObject->GetMetafile();
-      				PicHandle pict = metaFile.GetHMETAFILE() ;
+      				PicHandle pict = (PicHandle) metaFile.GetHMETAFILE() ;
       				HLock( (Handle) pict ) ;
       #if !TARGET_CARBON
       				err = PutScrap( GetHandleSize(  (Handle) pict ) , 'PICT' , *pict ) ;
diff --git a/src/mac/colordlg.cpp b/src/mac/colordlg.cpp
index c6037a9f96..90326e713d 100644
--- a/src/mac/colordlg.cpp
+++ b/src/mac/colordlg.cpp
@@ -20,6 +20,8 @@
 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
 #endif
 
+#include "wx/mac/private.h"
+
 /*
  * wxColourDialog
  */
@@ -46,13 +48,13 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
 int wxColourDialog::ShowModal()
 {
 	Point where ;
-	RGBColor currentColor = m_colourData.dataColour.GetPixel() , newColor ;
+	RGBColor currentColor = *((RGBColor*)m_colourData.dataColour.GetPixel()) , newColor ;
 	
 	where.h = where.v = -1;
 
 	if (GetColor( where, "\pSelect a new palette color.", &currentColor, &newColor ))
 	{
-		m_colourData.dataColour.Set( newColor ) ;
+		m_colourData.dataColour.Set( (WXCOLORREF*) &newColor ) ;
     	return wxID_OK;
 	}
 	else
diff --git a/src/mac/colour.cpp b/src/mac/colour.cpp
index cc549b5f11..82fb8a7928 100644
--- a/src/mac/colour.cpp
+++ b/src/mac/colour.cpp
@@ -22,9 +22,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
 
 // Colour
 
-static void wxComposeRGBColor( RGBColor * col , int red, int blue, int green ) ;
-static void wxComposeRGBColor( RGBColor * col , int red, int blue, int green ) 
+#include "wx/mac/private.h"
+
+static void wxComposeRGBColor( WXCOLORREF* color , int red, int blue, int green ) ;
+static void wxComposeRGBColor( WXCOLORREF* color , int red, int blue, int green ) 
 {
+    RGBColor* col = (RGBColor*) color ;
 	col->red = (red << 8) + red;
 	col->blue = (blue << 8) + blue;
 	col->green = (green << 8) + green;
@@ -55,7 +58,7 @@ wxColour::wxColour (const wxColour& col)
     m_blue = col.m_blue;
     m_isInit = col.m_isInit;
 
-    m_pixel = col.m_pixel;
+    memcpy( &m_pixel , &col.m_pixel , 6 ) ;
 }
 
 wxColour::wxColour (const wxColour* col)
@@ -65,7 +68,7 @@ wxColour::wxColour (const wxColour* col)
     m_blue = col->m_blue;
     m_isInit = col->m_isInit;
 
-    m_pixel = col->m_pixel;
+    memcpy( &m_pixel , &col->m_pixel , 6 ) ;
 }
 
 wxColour& wxColour::operator =(const wxColour& col)
@@ -75,7 +78,7 @@ wxColour& wxColour::operator =(const wxColour& col)
   m_blue = col.m_blue;
   m_isInit = col.m_isInit;
  
-  m_pixel = col.m_pixel;
+  memcpy( &m_pixel , &col.m_pixel , 6 ) ;
 
   return *this;
 }
@@ -114,3 +117,12 @@ void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
 
 	wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
 }
+
+void wxColour::Set( const WXCOLORREF* color )
+{ 
+    RGBColor* col = (RGBColor*) color ;
+    memcpy( &m_pixel , color , 6 ) ;
+    m_red = col->red>>8 ;
+    m_blue = col->blue>>8 ;
+    m_green = col->green>>8 ;
+}
\ No newline at end of file
diff --git a/src/mac/combobox.cpp b/src/mac/combobox.cpp
index 712a6dddbf..d55e591e52 100644
--- a/src/mac/combobox.cpp
+++ b/src/mac/combobox.cpp
@@ -47,20 +47,20 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
 	
 		MacPreControlCreate( parent , id ,  "" , pos , size ,style, validator , name , &bounds , title ) ;
 	
-		m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , -12345 , 0, 
+		m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , -12345 , 0, 
 	  	kControlPopupButtonProc , (long) this ) ; 
 	
 		m_macPopUpMenuHandle =  NewUniqueMenu() ;
-		SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
+		SetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
 		for ( int i = 0 ; i < n ; i++ )
 		{
 			Str255 label;
 			wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
-			AppendMenu( m_macPopUpMenuHandle , label ) ;
+			AppendMenu( (MenuHandle) m_macPopUpMenuHandle , label ) ;
 		}
-		SetControlMinimum( m_macControl , 0 ) ;
-		SetControlMaximum( m_macControl , m_noStrings) ;
-		SetControlValue( m_macControl , 1 ) ;
+		SetControlMinimum( (ControlHandle) m_macControl , 0 ) ;
+		SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ;
+		SetControlValue( (ControlHandle) m_macControl , 1 ) ;
 
 		MacPostControlCreate() ;
 
@@ -139,37 +139,37 @@ void wxComboBox::Append(const wxString& item)
 {
 	Str255 label;
 	wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
-	AppendMenu( m_macPopUpMenuHandle , label ) ;
+	AppendMenu( (MenuHandle) m_macPopUpMenuHandle , label ) ;
     m_noStrings ++;
-	SetControlMaximum( m_macControl , m_noStrings) ;
+	SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ;
 }
 
 void wxComboBox::Delete(int n)
 {
 	wxASSERT( n < m_noStrings ) ;
-    ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
+    ::DeleteMenuItem( (MenuHandle) m_macPopUpMenuHandle , n + 1) ;
     m_noStrings --;
-	SetControlMaximum( m_macControl , m_noStrings) ;
+	SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ;
 }
 
 void wxComboBox::Clear()
 {
     for ( int i = 0 ; i < m_noStrings ; i++ )
     {
-    	::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
+    	::DeleteMenuItem((MenuHandle) m_macPopUpMenuHandle , 1 ) ;
 	}
     m_noStrings = 0;
-	SetControlMaximum( m_macControl , m_noStrings) ;
+	SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ;
 }
 
 int wxComboBox::GetSelection() const
 {
-    return GetControlValue( m_macControl ) -1 ;
+    return GetControlValue( (ControlHandle) m_macControl ) -1 ;
 }
 
 void wxComboBox::SetSelection(int n)
 {
-    SetControlValue( m_macControl , n + 1 ) ;
+    SetControlValue( (ControlHandle) m_macControl , n + 1 ) ;
 }
 
 int wxComboBox::FindString(const wxString& s) const
@@ -186,7 +186,7 @@ wxString wxComboBox::GetString(int n) const
 {
     Str255 p_text ;
     char   c_text[255];
-    ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , p_text ) ;
+    ::GetMenuItemText( (MenuHandle) m_macPopUpMenuHandle , n+1 , p_text ) ;
 #if TARGET_CARBON
     p2cstrcpy( c_text, p_text ) ;
 #else
@@ -217,7 +217,7 @@ bool wxComboBox::SetStringSelection(const wxString& sel)
         return FALSE;
 }
 
-void wxComboBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxComboBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
     wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
 	event.SetInt(GetSelection());
diff --git a/src/mac/control.cpp b/src/mac/control.cpp
index 9ee03b8a4e..0dcfb505d0 100644
--- a/src/mac/control.cpp
+++ b/src/mac/control.cpp
@@ -110,9 +110,9 @@ wxControl::~wxControl()
         if (parent->GetDefaultItem() == (wxButton*) this)
             parent->SetDefaultItem(NULL);
     }
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
-        ::DisposeControl( m_macControl ) ;
+        ::DisposeControl( (ControlHandle) m_macControl ) ;
         m_macControl = NULL ;
     }
 }
@@ -121,7 +121,7 @@ void wxControl::SetLabel(const wxString& title)
 {
     m_label = title ;
 
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         Str255 maclabel ;
         wxString label ;
@@ -137,7 +137,7 @@ void wxControl::SetLabel(const wxString& title)
         strcpy( (char *) maclabel , label ) ;
         c2pstr( (char *) maclabel ) ;
 #endif
-        ::SetControlTitle( m_macControl , maclabel ) ;
+        ::SetControlTitle( (ControlHandle) m_macControl , maclabel ) ;
     }
     Refresh() ;
 }
@@ -147,7 +147,7 @@ wxSize wxControl::DoGetBestSize() const
     Rect    bestsize = { 0 , 0 , 0 , 0 } ;
     short   baselineoffset ;
     int bestWidth, bestHeight ;
-    ::GetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ;
+    ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
 
     if ( EmptyRect( &bestsize ) )
     {
@@ -239,7 +239,7 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
              const wxPoint& pos,
              const wxSize& size, long style,
              const wxValidator& validator,
-             const wxString& name , Rect *outBounds , StringPtr maclabel ) 
+             const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel ) 
 {
     m_label = label ;
   SetName(name);
@@ -264,10 +264,10 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
     m_x = pos.x ;
     m_y = pos.y ;
         
-    outBounds->top = -10;
-    outBounds->left = -10;
-    outBounds->bottom = 0;
-    outBounds->right = 0;
+    ((Rect*)outBounds)->top = -10;
+    ((Rect*)outBounds)->left = -10;
+    ((Rect*)outBounds)->bottom = 0;
+    ((Rect*)outBounds)->right = 0;
 
     char c_text[255];
     strcpy( c_text , label ) ;
@@ -286,7 +286,7 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
 
 void wxControl::MacPostControlCreate()
 {
-    wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+    wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
     
     if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
     {
@@ -298,7 +298,7 @@ void wxControl::MacPostControlCreate()
         controlstyle.flags = kControlUseFontMask ;
         controlstyle.font = kControlFontSmallBoldSystemFont ;
         
-        ::SetControlFontStyle( m_macControl , &controlstyle ) ;
+        ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
     }
     else
     {
@@ -306,14 +306,14 @@ void wxControl::MacPostControlCreate()
         controlstyle.flags = kControlUseFontMask ;
         controlstyle.font = kControlFontSmallSystemFont ;
         
-        ::SetControlFontStyle( m_macControl , &controlstyle ) ;
+        ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
     }
-    ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
+    ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
     wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
-    ::EmbedControl( m_macControl , container ) ;
+    ::EmbedControl( (ControlHandle) m_macControl , container ) ;
     m_macControlIsShown  = true ;
 
-    wxAssociateControlWithMacControl( m_macControl , this ) ;
+    wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ;
 
  
      // Adjust the controls size and position
@@ -332,19 +332,19 @@ void wxControl::MacPostControlCreate()
  
      SetSize(pos.x, pos.y, new_size.x, new_size.y);
  
-     UMAShowControl( m_macControl ) ;
+     UMAShowControl( (ControlHandle) m_macControl ) ;
      Refresh() ;
 }
 
 void wxControl::MacAdjustControlRect() 
 {
-    wxASSERT_MSG( m_macControl != NULL , wxT("No valid mac control") ) ;
+    wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
     if ( m_width == -1 || m_height == -1 )
     {
         Rect    bestsize = { 0 , 0 , 0 , 0 } ;
         short   baselineoffset ;
         
-        ::GetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ;
+        ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
 
         if ( EmptyRect( &bestsize ) )
         {
@@ -388,10 +388,11 @@ void wxControl::MacAdjustControlRect()
             m_height += 2 * m_macVerticalBorder;
         }
         
-        UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height -  2 * m_macVerticalBorder ) ;
+        UMASizeControl( (ControlHandle) m_macControl , m_width - 2 * m_macHorizontalBorder, m_height -  2 * m_macVerticalBorder ) ;
     }
 }
-ControlHandle wxControl::MacGetContainerForEmbedding() 
+
+WXWidget wxControl::MacGetContainerForEmbedding() 
 {
     if ( m_macControl )
         return m_macControl ;
@@ -401,17 +402,17 @@ ControlHandle wxControl::MacGetContainerForEmbedding()
 
 void wxControl::MacSuperChangedPosition() 
 {
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         Rect contrlRect ;       
-        GetControlBounds( m_macControl , &contrlRect ) ; 
+        GetControlBounds( (ControlHandle) m_macControl , &contrlRect ) ; 
         int former_mac_x = contrlRect.left ;
         int former_mac_y = contrlRect.top ;
         int mac_x = m_x ;
         int mac_y = m_y ;
         GetParent()->MacWindowToRootWindow( & mac_x , & mac_y ) ;
         
-        WindowRef rootwindow = MacGetRootWindow() ;
+        WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
 
         if ( mac_x + m_macHorizontalBorder != former_mac_x || 
             mac_y + m_macVerticalBorder != former_mac_y )
@@ -420,7 +421,7 @@ void wxControl::MacSuperChangedPosition()
                 Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ;
                 InvalWindowRect( rootwindow , &inval ) ;
             }
-            UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ;
+            UMAMoveControl( (ControlHandle) m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ;
             {
                 Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
                 InvalWindowRect( rootwindow , &inval ) ;
@@ -439,13 +440,13 @@ void wxControl::MacSuperEnabled( bool enabled )
 
 void  wxControl::MacSuperShown( bool show ) 
 {
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         if ( !show )
         {
             if ( m_macControlIsShown )
             {
-                ::UMAHideControl( m_macControl ) ;
+                ::UMAHideControl( (ControlHandle) m_macControl ) ;
                 m_macControlIsShown = false ;
             }
         }
@@ -453,7 +454,7 @@ void  wxControl::MacSuperShown( bool show )
         {
             if ( MacIsReallyShown() && !m_macControlIsShown )
             {
-                ::UMAShowControl( m_macControl ) ;
+                ::UMAShowControl( (ControlHandle) m_macControl ) ;
                 m_macControlIsShown = true ;
             }
         }
@@ -466,7 +467,7 @@ void  wxControl::DoSetSize(int x, int y,
             int width, int height,
             int sizeFlags )
 {
-    if ( m_macControl == NULL )
+    if ( (ControlHandle) m_macControl == NULL )
     {
         wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
         return ;
@@ -515,7 +516,7 @@ void  wxControl::DoSetSize(int x, int y,
      if(GetParent()) {
          GetParent()->MacWindowToRootWindow(&mac_x, &mac_y);
      }
-     GetControlBounds(m_macControl, &oldbounds);
+     GetControlBounds( (ControlHandle) m_macControl, &oldbounds);
      oldbounds.right = oldbounds.left + m_width;
      oldbounds.bottom = oldbounds.top + m_height;
  
@@ -556,7 +557,7 @@ void  wxControl::DoSetSize(int x, int y,
              m_x = new_x;
              m_y = new_y;
  
-             UMAMoveControl(m_macControl,
+             UMAMoveControl( (ControlHandle) m_macControl,
                             mac_x + m_macHorizontalBorder, mac_y + m_macVerticalBorder);
 
              wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
@@ -568,7 +569,7 @@ void  wxControl::DoSetSize(int x, int y,
              m_width = new_width;
              m_height = new_height;
  
-             UMASizeControl( m_macControl,
+             UMASizeControl( (ControlHandle) m_macControl,
                              m_width - 2 * m_macHorizontalBorder,
                              m_height -  2 * m_macVerticalBorder ) ;
  
@@ -587,13 +588,13 @@ bool  wxControl::Show(bool show)
     if ( !wxWindow::Show( show ) )
         return FALSE ;
         
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         if ( !show )
         {
             if ( m_macControlIsShown )
             {
-                ::UMAHideControl( m_macControl ) ;
+                ::UMAHideControl( (ControlHandle) m_macControl ) ;
                 m_macControlIsShown = false ;
             }
         }
@@ -601,7 +602,7 @@ bool  wxControl::Show(bool show)
         {
             if ( MacIsReallyShown() && !m_macControlIsShown )
             {
-                ::UMAShowControl( m_macControl ) ;
+                ::UMAShowControl( (ControlHandle) m_macControl ) ;
                 m_macControlIsShown = true ;
             }
         }
@@ -614,12 +615,12 @@ bool  wxControl::Enable(bool enable)
     if ( !wxWindow::Enable(enable) )
         return FALSE;
 
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         if ( enable )
-            UMAActivateControl( m_macControl ) ;
+            UMAActivateControl( (ControlHandle) m_macControl ) ;
         else
-            UMADeactivateControl( m_macControl ) ;
+            UMADeactivateControl( (ControlHandle) m_macControl ) ;
     }
     return TRUE ;
 }
@@ -631,7 +632,7 @@ void wxControl::Refresh(bool eraseBack, const wxRect *rect)
 
 void wxControl::MacRedrawControl()
 {
-    if ( m_macControl && MacGetRootWindow() )
+    if ( (ControlHandle) m_macControl && MacGetRootWindow() )
     {
         wxClientDC dc(this) ;
         wxMacPortSetter helper(&dc) ;
@@ -643,13 +644,13 @@ void wxControl::MacRedrawControl()
         Rect r = { 0 , 0 , 32000 , 32000 } ;
         ClipRect( &r ) ;
         wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
-        UMADrawControl( m_macControl ) ;
+        UMADrawControl( (ControlHandle) m_macControl ) ;
     }
 }
 
 void wxControl::OnPaint(wxPaintEvent& event)
 {
-    if ( m_macControl )
+    if ( (ControlHandle) m_macControl )
     {
         wxPaintDC dc(this) ;
         wxMacPortSetter helper(&dc) ;
@@ -661,7 +662,7 @@ void wxControl::OnPaint(wxPaintEvent& event)
         ClipRect( &r ) ;
 
         wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
-        UMADrawControl( m_macControl ) ;
+        UMADrawControl( (ControlHandle) m_macControl ) ;
     }
     else
     {
@@ -676,21 +677,21 @@ void wxControl::OnEraseBackground(wxEraseEvent& event)
 
 void  wxControl::OnKeyDown( wxKeyEvent &event ) 
 {
-    if ( m_macControl == NULL )
+    if ( (ControlHandle) m_macControl == NULL )
         return ;
     
-    EventRecord *ev = wxTheApp->MacGetCurrentEvent() ;
+    EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
     short keycode ;
     short keychar ;
     keychar = short(ev->message & charCodeMask);
     keycode = short(ev->message & keyCodeMask) >> 8 ;
 
-    ::HandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ;
+    ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
 }
 
 void  wxControl::OnMouseEvent( wxMouseEvent &event ) 
 {
-    if ( m_macControl == NULL )
+    if ( (ControlHandle) m_macControl == NULL )
     {
         event.Skip() ;
         return ;
@@ -707,7 +708,7 @@ void  wxControl::OnMouseEvent( wxMouseEvent &event )
         ControlHandle   control ;
         Point       localwhere ;
         SInt16      controlpart ;
-        WindowRef   window = MacGetRootWindow() ;
+        WindowRef   window = (WindowRef) MacGetRootWindow() ;
         
         localwhere.h = x ;
         localwhere.v = y ;
@@ -742,7 +743,7 @@ void  wxControl::OnMouseEvent( wxMouseEvent &event )
                 SetFocus() ;
             }
         */
-            control = m_macControl ;
+            control = (ControlHandle) m_macControl ;
             if ( control && ::IsControlActive( control ) )
             {
                 {
@@ -762,15 +763,15 @@ void  wxControl::OnMouseEvent( wxMouseEvent &event )
 
 bool wxControl::MacCanFocus() const
 {
-        { if ( m_macControl == NULL ) 
+        { if ( (ControlHandle) m_macControl == NULL ) 
                 return true ; 
             else
             return false ; 
         }
 }
 
-void wxControl::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
-    wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+    wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
 }
 
diff --git a/src/mac/cursor.cpp b/src/mac/cursor.cpp
index fa0bbf76b2..c65a32ecb1 100644
--- a/src/mac/cursor.cpp
+++ b/src/mac/cursor.cpp
@@ -15,6 +15,7 @@
 
 #include "wx/cursor.h"
 #include "wx/icon.h"
+#include "wx/mac/private.h"
 
 #if !USE_SHARED_LIBRARIES
 IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
@@ -195,8 +196,8 @@ void wxCursor::MacInstall() const
 {
 	if ( m_refData && M_CURSORDATA->m_hCursor )
 	{
-		::SetCursor( *M_CURSORDATA->m_hCursor ) ;
-		gMacCurrentCursor = M_CURSORDATA->m_hCursor ;
+		::SetCursor(  *((CursHandle)M_CURSORDATA->m_hCursor) ) ;
+		gMacCurrentCursor = (CursHandle)M_CURSORDATA->m_hCursor ;
 	}
 	else
 	{
diff --git a/src/mac/dataobj.cpp b/src/mac/dataobj.cpp
index ff91434d91..bffbbe55e9 100644
--- a/src/mac/dataobj.cpp
+++ b/src/mac/dataobj.cpp
@@ -33,6 +33,7 @@
 #include "wx/dataobj.h"
 #include "wx/mstream.h"
 #include "wx/image.h"
+#include "wx/mac/private.h"
 
 // ----------------------------------------------------------------------------
 // functions
diff --git a/src/mac/dc.cpp b/src/mac/dc.cpp
index 59472ddfa5..5e62998da3 100644
--- a/src/mac/dc.cpp
+++ b/src/mac/dc.cpp
@@ -20,6 +20,8 @@
 #include "wx/region.h"
 #include "wx/image.h"
 
+#include "wx/mac/private.h"
+
 #if __MSL__ >= 0x6000
 #include "math.h"
 #endif
@@ -42,6 +44,10 @@ IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
 const double M_PI = 3.14159265358979 ;
 #endif
 const double RAD2DEG  = 180.0 / M_PI;
+const short kEmulatedMode = -1 ;
+const short kUnsupportedMode = -2 ;
+
+#define wxMAC_EXPERIMENTAL_PATTERN 0
 
 //-----------------------------------------------------------------------------
 // Local functions
@@ -55,6 +61,95 @@ static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
 // wxDC
 //-----------------------------------------------------------------------------
 
+// this function emulates all wx colour manipulations, used to verify the implementation
+// by setting the mode in the blitting functions to kEmulatedMode
+
+void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColor &dstColor ) ;
+void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColor &dstColor )
+{
+    switch ( logical_func )
+    {
+    	case wxAND:        // src AND dst
+    	    dstColor.red = dstColor.red & srcColor.red ;
+    	    dstColor.green = dstColor.green & srcColor.green ;
+    	    dstColor.blue = dstColor.blue & srcColor.blue ;
+    	    break ;
+    	case wxAND_INVERT: // (NOT src) AND dst
+    	    dstColor.red = dstColor.red & ~srcColor.red ;
+    	    dstColor.green = dstColor.green & ~srcColor.green ;
+    	    dstColor.blue = dstColor.blue & ~srcColor.blue ;
+    	    break ;
+    	case wxAND_REVERSE:// src AND (NOT dst)
+    	    dstColor.red = ~dstColor.red & srcColor.red ;
+    	    dstColor.green = ~dstColor.green & srcColor.green ;
+    	    dstColor.blue = ~dstColor.blue & srcColor.blue ;
+    	    break ;
+    	case wxCLEAR:      // 0
+    	    dstColor.red = 0 ;
+    	    dstColor.green = 0 ;
+    	    dstColor.blue = 0 ;
+    	    break ;
+        case wxCOPY:       // src
+    	    dstColor.red = srcColor.red ;
+    	    dstColor.green = srcColor.green ;
+    	    dstColor.blue = srcColor.blue ;
+    		break ;
+    	case wxEQUIV:      // (NOT src) XOR dst
+    	    dstColor.red = dstColor.red ^ ~srcColor.red ;
+    	    dstColor.green = dstColor.green ^ ~srcColor.green ;
+    	    dstColor.blue = dstColor.blue ^ ~srcColor.blue ;
+    	    break ;
+    	case wxINVERT:     // NOT dst
+    	    dstColor.red = ~dstColor.red ;
+    	    dstColor.green = ~dstColor.green ;
+    	    dstColor.blue = ~dstColor.blue ;
+    		break ;
+    	case wxNAND:       // (NOT src) OR (NOT dst)
+    	    dstColor.red = ~dstColor.red | ~srcColor.red ;
+    	    dstColor.green = ~dstColor.green | ~srcColor.green ;
+    	    dstColor.blue = ~dstColor.blue | ~srcColor.blue ;
+    	    break ;
+    	case wxNOR:        // (NOT src) AND (NOT dst)
+    	    dstColor.red = ~dstColor.red & ~srcColor.red ;
+    	    dstColor.green = ~dstColor.green & ~srcColor.green ;
+    	    dstColor.blue = ~dstColor.blue & ~srcColor.blue ;
+    	    break ;
+    	case wxNO_OP:      // dst
+    	    break ;
+    	case wxOR:         // src OR dst
+    	    dstColor.red = dstColor.red | srcColor.red ;
+    	    dstColor.green = dstColor.green | srcColor.green ;
+    	    dstColor.blue = dstColor.blue | srcColor.blue ;
+    	    break ;
+    	case wxOR_INVERT:  // (NOT src) OR dst
+    	    dstColor.red = dstColor.red | ~srcColor.red ;
+    	    dstColor.green = dstColor.green | ~srcColor.green ;
+    	    dstColor.blue = dstColor.blue | ~srcColor.blue ;
+    	    break ;
+    	case wxOR_REVERSE: // src OR (NOT dst)
+    	    dstColor.red = ~dstColor.red | srcColor.red ;
+    	    dstColor.green = ~dstColor.green | srcColor.green ;
+    	    dstColor.blue = ~dstColor.blue | srcColor.blue ;
+    		break ;
+    	case wxSET:        // 1
+    	    dstColor.red = 0xFFFF ;
+    	    dstColor.green = 0xFFFF ;
+    	    dstColor.blue = 0xFFFF ;
+    	    break ;
+    	case wxSRC_INVERT: // (NOT src)
+    	    dstColor.red = ~srcColor.red ;
+    	    dstColor.green = ~srcColor.green ;
+    	    dstColor.blue = ~srcColor.blue ;
+    		break ;
+    	case wxXOR:        // src XOR dst
+    	    dstColor.red = dstColor.red ^ srcColor.red ;
+    	    dstColor.green = dstColor.green ^ srcColor.green ;
+    	    dstColor.blue = dstColor.blue ^ srcColor.blue ;
+    		break ;
+    }
+
+}
+
 wxDC::wxDC()
 {
   m_ok = FALSE;
@@ -78,9 +173,6 @@ wxDC::wxDC()
   m_needComputeScaleX = FALSE;
   m_needComputeScaleY = FALSE;
   
-  m_maxX = m_maxY = -100000;
-  m_minY = m_minY =  100000;
-
   m_macPort = NULL ;
   m_macMask = NULL ;
   m_ok = FALSE ;
@@ -89,19 +181,19 @@ wxDC::wxDC()
 	m_macBrushInstalled = false ;
 	m_macPenInstalled = false ;
 	
-	m_macLocalOrigin.h = m_macLocalOrigin.v = 0 ;
+	m_macLocalOrigin.x = m_macLocalOrigin.y = 0 ;
 	m_macBoundaryClipRgn = NewRgn() ;
 	m_macCurrentClipRgn = NewRgn() ;
 
-	SetRectRgn( m_macBoundaryClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
-	SetRectRgn( m_macCurrentClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
+	SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
+	SetRectRgn( (RgnHandle) m_macCurrentClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
 
     m_pen = *wxBLACK_PEN;
     m_font = *wxNORMAL_FONT;
     m_brush = *wxWHITE_BRUSH;
 }
 wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) :
-	m_ph( dc->m_macPort ) 
+	m_ph( (GrafPtr) dc->m_macPort ) 
 {
 	wxASSERT( dc->Ok() ) ;
 	
@@ -114,12 +206,12 @@ wxMacPortSetter::~wxMacPortSetter()
 
 wxDC::~wxDC(void)
 {
-  DisposeRgn( m_macBoundaryClipRgn ) ;
-  DisposeRgn( m_macCurrentClipRgn ) ;
+    DisposeRgn( (RgnHandle) m_macBoundaryClipRgn ) ;
+    DisposeRgn( (RgnHandle) m_macCurrentClipRgn ) ;
 }
-void wxDC::MacSetupPort(AGAPortHelper* help) const
+void wxDC::MacSetupPort(wxMacPortStateHelper* help) const
 {
-	SetClip( m_macCurrentClipRgn);
+	SetClip( (RgnHandle) m_macCurrentClipRgn);
 
 	m_macFontInstalled = false ;
 	m_macBrushInstalled = false ;
@@ -159,18 +251,18 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
      if ( bmp.GetBitmapType() == kMacBitmapTypePict ) {
          Rect bitmaprect = { 0 , 0 , hh, ww };
          ::OffsetRect( &bitmaprect, xx, yy ) ;
-         ::DrawPicture( bmp.GetPict(), &bitmaprect ) ;
+         ::DrawPicture( (PicHandle) bmp.GetPict(), &bitmaprect ) ;
     }
      else if ( bmp.GetBitmapType() == kMacBitmapTypeGrafWorld )
      {
-         GWorldPtr    bmapworld = bmp.GetHBITMAP();
+         GWorldPtr    bmapworld = MAC_WXHBITMAP( bmp.GetHBITMAP() );
          PixMapHandle bmappixels ;
  
          // Set foreground and background colours (for bitmaps depth = 1)
          if(bmp.GetDepth() == 1)
         {
-             RGBColor fore = m_textForegroundColour.GetPixel();
-             RGBColor back = m_textBackgroundColour.GetPixel();
+             RGBColor fore = MAC_WXCOLORREF(m_textForegroundColour.GetPixel());
+             RGBColor back = MAC_WXCOLORREF(m_textBackgroundColour.GetPixel());
              RGBForeColor(&fore);
              RGBBackColor(&back);
          }
@@ -192,21 +284,21 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
  
          if ( useMask && bmp.GetMask() )
          {
-             if( LockPixels(GetGWorldPixMap(bmp.GetMask()->GetMaskBitmap())))
+             if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap()))))
              {
                  CopyDeepMask
                      (
                       GetPortBitMapForCopyBits(bmapworld),
-                      GetPortBitMapForCopyBits(bmp.GetMask()->GetMaskBitmap()),
-                      GetPortBitMapForCopyBits( m_macPort ),
+                      GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())),
+                      GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
                       &source, &source, &dest, mode, NULL
                       );
-                 UnlockPixels(GetGWorldPixMap(bmp.GetMask()->GetMaskBitmap()));
+                 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())));
              }
          }
          else {
              CopyBits( GetPortBitMapForCopyBits( bmapworld ),
-                       GetPortBitMapForCopyBits( m_macPort ),
+                       GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
                        &source, &dest, mode, NULL ) ;
          }
          UnlockPixels( bmappixels ) ;
@@ -215,7 +307,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
      {
         Rect bitmaprect = { 0 , 0 , bmp.GetHeight(), bmp.GetWidth() } ;
         OffsetRect( &bitmaprect, xx, yy ) ;
-        PlotCIconHandle( &bitmaprect , atNone , ttNone , bmp.GetHICON() ) ;
+        PlotCIconHandle( &bitmaprect , atNone , ttNone , MAC_WXHICON(bmp.GetHICON()) ) ;
      }
      m_macPenInstalled = false ;
      m_macBrushInstalled = false ;
@@ -241,8 +333,8 @@ void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord hei
     ww = XLOG2DEVREL(width);
     hh = YLOG2DEVREL(height);
 
-    SetRectRgn( m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
-    SectRgn( m_macCurrentClipRgn , m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+    SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
+    SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
     
     if( m_clipping )
     {
@@ -290,12 +382,12 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region  )
     }
     else
     {
-        CopyRgn( region.GetWXHRGN() , m_macCurrentClipRgn ) ;
+        CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ;
         if ( xx != x || yy != y )
         {
-            OffsetRgn( m_macCurrentClipRgn , xx - x , yy - y ) ;
+            OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ;
         }
-        SectRgn( m_macCurrentClipRgn , m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+        SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
         if( m_clipping )
         {
             m_clipX1 = wxMax( m_clipX1 , xx );
@@ -318,7 +410,7 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region  )
 void wxDC::DestroyClippingRegion()
 {
   wxMacPortSetter helper(this) ;
-  CopyRgn( m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+  CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
   m_clipping = FALSE;
 }    
 void wxDC::DoGetSize( int* width, int* height ) const
@@ -418,15 +510,8 @@ void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
   m_signX = (xLeftRight ?  1 : -1);
   m_signY = (yBottomUp  ? -1 :  1);
   ComputeScaleAndOrigin();
-}/*
-    
-void wxDC::CalcBoundingBox( long x, long y )
-{
-  if (x < m_minX) m_minX = x;
-  if (y < m_minY) m_minY = y;
-  if (x > m_maxX) m_maxX = x;
-  if (y > m_maxY) m_maxY = y;
-}*/
+}
+
 wxSize wxDC::GetPPI() const
 {
     return wxSize(72, 72);
@@ -787,13 +872,19 @@ void  wxDC::DoDrawPolygon(int n, wxPoint points[],
 	y1 = YLOG2DEVMAC(points[0].y + yoffset);   
 	::MoveTo(x1,y1);
 
-	for (int i = 0; i < n-1; i++)
+	for (int i = 1; i < n; i++)
 	{
-		x2 = XLOG2DEVMAC(points[i+1].x + xoffset);
-		y2 = YLOG2DEVMAC(points[i+1].y + yoffset);
+		x2 = XLOG2DEVMAC(points[i].x + xoffset);
+		y2 = YLOG2DEVMAC(points[i].y + yoffset);
 		::LineTo(x2, y2);
 	}
 
+    // close the polyline if necessary
+    if ( x1 != x2 || y1 != y2 )
+    {
+        ::LineTo(x1,y1 ) ;
+    }
+    
 	ClosePoly();
 
   	if (m_brush.GetStyle() != wxTRANSPARENT)
@@ -959,82 +1050,222 @@ bool  wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
 {
     wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
     wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit  Illegal source DC"));
-    wxMacPortSetter helper(this) ;
+    
+    if ( logical_func == wxNO_OP )
+        return TRUE ;
 
-    /* TODO: use the mask origin when drawing transparently */
     if (xsrcMask == -1 && ysrcMask == -1)
     {
         xsrcMask = xsrc; ysrcMask = ysrc;
     }
 
+    // correct the parameter in case this dc does not have a mask at all
+    
+    if ( useMask && !source->m_macMask )
+        useMask = false ;
+        
+	Rect srcrect , dstrect ;
+	srcrect.top = source->YLOG2DEVMAC(ysrc) ;
+	srcrect.left = source->XLOG2DEVMAC(xsrc)  ;
+	srcrect.right = source->XLOG2DEVMAC(xsrc + width ) ;
+	srcrect.bottom = source->YLOG2DEVMAC(ysrc + height) ;
+	dstrect.top = YLOG2DEVMAC(ydest) ;
+	dstrect.left = XLOG2DEVMAC(xdest) ;
+	dstrect.bottom = YLOG2DEVMAC(ydest + height )  ;
+	dstrect.right = XLOG2DEVMAC(xdest + width ) ;
+
+    short mode = kUnsupportedMode ;
+    bool invertDestinationFirst = false ;
+    switch ( logical_func )
+    {
+		case wxAND:        // src AND dst
+		    mode = srcOr ; // ok
+		    break ;
+		case wxAND_INVERT: // (NOT src) AND dst
+		    mode = notSrcOr  ; // ok
+		    break ;
+		case wxAND_REVERSE:// src AND (NOT dst)
+		    invertDestinationFirst = true ;
+		    mode = srcOr ; 
+		    break ;
+		case wxCLEAR:      // 0
+		    mode = kEmulatedMode ; 
+		    break ;
+        case wxCOPY:       // src
+			mode = srcCopy ; // ok
+			break ;
+		case wxEQUIV:      // (NOT src) XOR dst
+		    mode = srcXor ; // ok
+		    break ;
+		case wxINVERT:     // NOT dst
+			mode = kEmulatedMode ; //or hilite ;
+			break ;
+		case wxNAND:       // (NOT src) OR (NOT dst)
+		    invertDestinationFirst = true ;
+		    mode = srcBic ; 
+		    break ;
+		case wxNOR:        // (NOT src) AND (NOT dst)
+		    invertDestinationFirst = true ;
+		    mode = notSrcOr ; 
+		    break ;
+		case wxNO_OP:      // dst
+		    mode = kEmulatedMode ; // this has already been handled upon entry
+		    break ;
+		case wxOR:         // src OR dst
+		    mode = notSrcBic ;
+		    break ;
+		case wxOR_INVERT:  // (NOT src) OR dst
+		    mode = srcBic ; 
+		    break ;
+		case wxOR_REVERSE: // src OR (NOT dst)
+		    invertDestinationFirst = true ;
+			mode = notSrcBic ;
+			break ;
+		case wxSET:        // 1
+		    mode = kEmulatedMode ; 
+		    break ;
+		case wxSRC_INVERT: // (NOT src)
+			mode = notSrcCopy ; // ok
+			break ;
+		case wxXOR:        // src XOR dst
+			mode = notSrcXor ; // ok
+			break ;
+
+        default :
+			break ;
+
+    }
+
+    if ( mode == kUnsupportedMode )
+    {
+        wxFAIL_MSG("unsupported blitting mode" )
+        return FALSE ;
+    }
+    
 	CGrafPtr			sourcePort = (CGrafPtr) source->m_macPort ;
 	PixMapHandle	bmappixels =  GetGWorldPixMap( sourcePort ) ; 
-	RGBColor	white = { 0xFFFF, 0xFFFF,0xFFFF} ;
-	RGBColor	black = { 0,0,0} ;
-	RGBColor        forecolor = m_textForegroundColour.GetPixel();
-	RGBColor        backcolor = m_textBackgroundColour.GetPixel();
-	RGBForeColor( &forecolor ) ;
-	RGBBackColor( &backcolor ) ;
-
 	if ( LockPixels(bmappixels) )
 	{
-		Rect srcrect , dstrect ;
-		srcrect.top = source->YLOG2DEVMAC(ysrc) ;
-		srcrect.left = source->XLOG2DEVMAC(xsrc)  ;
-		srcrect.right = source->XLOG2DEVMAC(xsrc + width ) ;
-		srcrect.bottom = source->YLOG2DEVMAC(ysrc + height) ;
-		dstrect.top = YLOG2DEVMAC(ydest) ;
-		dstrect.left = XLOG2DEVMAC(xdest) ;
-		dstrect.bottom = YLOG2DEVMAC(ydest + height )  ;
-		dstrect.right = XLOG2DEVMAC(xdest + width ) ;
-
-    	short  mode = (logical_func == wxCOPY ? srcCopy :
- //   	logical_func == wxCLEAR ? WHITENESS :
- //   	logical_func == wxSET ? BLACKNESS :
-   		logical_func == wxINVERT ? hilite :
-  //  	logical_func == wxAND ? MERGECOPY :
-    	logical_func == wxOR ? srcOr :
-    	logical_func == wxSRC_INVERT ? notSrcCopy :
-    	logical_func == wxXOR ? srcXor :
-  //  	logical_func == wxOR_REVERSE ? MERGEPAINT :
-  //  	logical_func == wxAND_REVERSE ? SRCERASE :
-  //  	logical_func == wxSRC_OR ? srcOr :
-  //  	logical_func == wxSRC_AND ? SRCAND :
-    		srcCopy );
+        wxMacPortSetter helper(this) ;
+        RGBColor tempColor ;
+    
+    	if ( source->GetDepth() == 1 )
+    	{
+    	    RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour.GetPixel()) ) ;
+    	    RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour.GetPixel()) ) ;
+        }
+        else
+        {
+            // the modes need this, otherwise we'll end up having really nice colors...
+    	    RGBColor	white = { 0xFFFF, 0xFFFF,0xFFFF} ;
+    	    RGBColor	black = { 0,0,0} ;
+    	    RGBForeColor( &black ) ;
+    	    RGBBackColor( &white ) ;
+        }
 
 		if ( useMask && source->m_macMask )
 		{
 		    if ( mode == srcCopy )
 		    {
-    			if ( LockPixels( GetGWorldPixMap( source->m_macMask ) ) )
+    			if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) )
     			{
     				CopyMask( GetPortBitMapForCopyBits( sourcePort ) , 
-    				            GetPortBitMapForCopyBits( source->m_macMask ) , 
-    				            GetPortBitMapForCopyBits( m_macPort ) ,
+    				            GetPortBitMapForCopyBits( MAC_WXHBITMAP(source->m_macMask) ) , 
+    				            GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
     					        &srcrect, &srcrect , &dstrect ) ;
-    				UnlockPixels( GetGWorldPixMap( source->m_macMask )  ) ;
+    				UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) )  ) ;
     			}
 		    }
 		    else
 		    {
                 RgnHandle clipRgn = NewRgn() ;
-                
-                LockPixels( GetGWorldPixMap( source->m_macMask ) ) ;
-                BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( source->m_macMask ) ) ;
-                UnlockPixels( GetGWorldPixMap( source->m_macMask ) ) ;
-                //OffsetRgn( clipRgn , -source->m_macMask->portRect.left , -source->m_macMask->portRect.top ) ;
+                LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
+                BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
+                UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
                 OffsetRgn( clipRgn , -srcrect.left + dstrect.left, -srcrect.top +  dstrect.top ) ;
-    			CopyBits( GetPortBitMapForCopyBits( sourcePort ) , 
-    			    GetPortBitMapForCopyBits( m_macPort ) ,
-    				&srcrect, &dstrect, mode, clipRgn ) ;
+                if ( mode == kEmulatedMode )
+                {
+                    Pattern pat ;
+		            ::PenPat(GetQDGlobalsBlack(&pat));
+                    if ( logical_func == wxSET )
+                    {
+                        RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
+		                ::RGBForeColor( &col  ) ;
+                        ::PaintRgn( clipRgn ) ;
+                    }
+                    else if ( logical_func == wxCLEAR )
+                    {
+                        RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
+		                ::RGBForeColor( &col  ) ;
+                        ::PaintRgn( clipRgn ) ;
+                    }
+                    else if ( logical_func == wxINVERT )
+                    {
+                        MacInvertRgn( clipRgn ) ;
+                    }
+                    else
+                    {
+                        for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )
+                        {
+                            for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )
+                            {
+                                Point dstPoint = { dstrect.top + y , dstrect.left + x } ;
+                                Point srcPoint = { srcrect.top + y , srcrect.left + x } ;
+                                if ( PtInRgn( dstPoint , clipRgn ) )
+                                {
+                                    RGBColor srcColor ;
+                                    RGBColor dstColor ;
+                                    
+                                    SetPort( (GrafPtr) sourcePort ) ;
+                                    GetCPixel(  srcPoint.h , srcPoint.v , &srcColor) ;
+                                    SetPort( (GrafPtr) m_macPort ) ;
+                                    GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
+                                    
+                                    wxMacCalculateColour( logical_func , srcColor ,  dstColor ) ;
+                                    SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
+                                }
+                            }
+                        }
+                        // wxFAIL_MSG("unimplemented emulated mode") ;
+                    }
+                }
+                else
+                {
+                    if ( invertDestinationFirst )
+                    {
+                        MacInvertRgn( clipRgn ) ;
+                    }
+        			CopyBits( GetPortBitMapForCopyBits( sourcePort ) , 
+        			    GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
+        				&srcrect, &dstrect, mode, clipRgn ) ;
+        	    }
     		    DisposeRgn( clipRgn ) ;
     		}
 		}
 		else
 		{
-			CopyBits( GetPortBitMapForCopyBits( sourcePort ) , 
-			    GetPortBitMapForCopyBits( m_macPort ) ,
-				&srcrect, &dstrect, mode, NULL ) ;
+		    if ( mode == kEmulatedMode )
+		    {
+    			CopyBits( GetPortBitMapForCopyBits( sourcePort ) , 
+    			    GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
+    				&srcrect, &dstrect, mode, NULL ) ;
+    		}
+    		else
+    		{
+                    Pattern pat ;
+		            ::PenPat(GetQDGlobalsBlack(&pat));
+                    if ( logical_func == wxSET )
+                    {
+                        RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
+		                ::RGBForeColor( &col  ) ;
+                    }
+                    else
+                    {
+                        RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
+		                ::RGBForeColor( &col  ) ;
+                    }
+                    ::PaintRect( &dstrect ) ;
+    		}
 		}
 		UnlockPixels( bmappixels ) ;
 	} 
@@ -1100,8 +1331,8 @@ void  wxDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
     // prepare to blit-with-rotate the bitmap to the DC
     wxImage image(src);
 
-    RGBColor colText = m_textForegroundColour.GetPixel();
-    RGBColor colBack = m_textBackgroundColour.GetPixel();
+    RGBColor colText = MAC_WXCOLORREF( m_textForegroundColour.GetPixel() );
+    RGBColor colBack = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel() );
 
     unsigned char *data = image.GetData();
 
@@ -1336,7 +1567,8 @@ void  wxDC::Clear(void)
 	
 	if (m_backgroundBrush.GetStyle() != wxTRANSPARENT) 
 	{
-		MacInstallBrush() ;
+        MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ;
+	
 		::EraseRect( &rect ) ;
 	}
 }
@@ -1360,8 +1592,8 @@ void wxDC::MacInstallFont() const
 		m_macBrushInstalled = false ;
 		m_macPenInstalled = false ;
 
-		RGBColor forecolor = m_textForegroundColour.GetPixel();
-		RGBColor backcolor = m_textBackgroundColour.GetPixel();
+		RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
+		RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
 		::RGBForeColor( &forecolor );
 		::RGBBackColor( &backcolor );
 	}
@@ -1380,8 +1612,8 @@ void wxDC::MacInstallFont() const
 		m_macBrushInstalled = false ;
 		m_macPenInstalled = false ;
 
-		RGBColor forecolor = m_textForegroundColour.GetPixel();
-		RGBColor backcolor = m_textBackgroundColour.GetPixel();
+		RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
+		RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
 		::RGBForeColor( &forecolor );
 		::RGBBackColor( &backcolor );
 	}
@@ -1470,8 +1702,8 @@ void wxDC::MacInstallPen() const
 //	if ( m_macPenInstalled )
 //		return ;
 
-	RGBColor forecolor = m_pen.GetColour().GetPixel();
-	RGBColor backcolor = m_backgroundBrush.GetColour().GetPixel();
+	RGBColor forecolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel());
+	RGBColor backcolor = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel());
 	::RGBForeColor( &forecolor );
 	::RGBBackColor( &backcolor );
 	
@@ -1604,7 +1836,7 @@ void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background )
         }
       case kwxMacBrushColour :
         {
-       	  ::RGBBackColor( &background.GetColour().GetPixel() );
+       	  ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) );
         	int brushStyle = background.GetStyle();
         	if (brushStyle == wxSOLID)
         		::BackPat(GetQDGlobalsWhite(&whiteColor));
@@ -1632,8 +1864,10 @@ void wxDC::MacInstallBrush() const
 //		return ;
 
 	// foreground
+	
+	bool backgroundTransparent = (GetBackgroundMode() == wxTRANSPARENT) ;
 
-	::RGBForeColor( &m_brush.GetColour().GetPixel() );
+	::RGBForeColor( &MAC_WXCOLORREF( m_brush.GetColour().GetPixel()) );
 
 	int brushStyle = m_brush.GetStyle();
 	if (brushStyle == wxSOLID)
@@ -1646,62 +1880,109 @@ void wxDC::MacInstallBrush() const
 	}
 	else if ( m_brush.GetStyle() == wxSTIPPLE || m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
 	{
+	    // we force this in order to be compliant with wxMSW
+	    backgroundTransparent = false ;
 	    // for these the text fore (and back for MASK_OPAQUE) colors are used
 	    wxBitmap* bitmap = m_brush.GetStipple() ;
 	    int width = bitmap->GetWidth() ;
 	    int height = bitmap->GetHeight() ;
-	    int depth = bitmap->GetDepth() ;
+        GWorldPtr gw = NULL ;
+
 	    if ( m_brush.GetStyle() == wxSTIPPLE )
+	        gw = MAC_WXHBITMAP(bitmap->GetHBITMAP())  ;
+	    else 
+	        gw = MAC_WXHBITMAP(bitmap->GetMask()->GetMaskBitmap()) ;
+	        
+        PixMapHandle gwpixmaphandle = GetGWorldPixMap( gw ) ;
+        LockPixels( gwpixmaphandle ) ;
+
+	    bool isMonochrome = !IsPortColor( gw ) ;
+
+        if ( !isMonochrome )
+        {
+            if ( (**gwpixmaphandle).pixelSize == 1 )
+                isMonochrome = true ;
+        }
+
+
+	    if ( isMonochrome )
 	    {
-	        GWorldPtr gw = bitmap->GetHBITMAP() ;
-	        if ( width == 8 && height == 8 && depth == 1)
-	        {
-	            Pattern pat ;
-                LockPixels( GetGWorldPixMap( gw ) ) ;
-                BitMap* gwbitmap = (BitMap*) *GetGWorldPixMap( gw ) ; // since the color depth is 1 it is a BitMap
-	            int alignment = gwbitmap->rowBytes & 0x7FFF ;
-                UInt8 *gwbits = (UInt8*) gwbitmap->baseAddr ;
+	        ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) );
+
+            BitMap* gwbitmap = (BitMap*) *gwpixmaphandle ; // since the color depth is 1 it is a BitMap
+            UInt8 *gwbits = (UInt8*) gwbitmap->baseAddr ;
+            int alignment = gwbitmap->rowBytes & 0x7FFF ;
+
+    	    if( width == 8 && height == 8 )
+    	    {
+                Pattern pat ;
                 for ( int i = 0 ; i < 8 ; ++i )
                 {
                     pat.pat[i] = gwbits[i*alignment+0] ;
                 }
                 UnlockPixels( GetGWorldPixMap( gw ) ) ;
-	            
-	            ::PenPat( &pat ) ;
-	        }
-	        else
-	        {
-		        ::PenPat(GetQDGlobalsBlack(&blackColor));
-		    }
+                ::PenPat( &pat ) ;
+    	    }
+    	    else
+    	    {
+ #if wxMAC_EXPERIMENTAL_PATTERN
+ // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
+ // caching scheme before putting this into production
+            	Handle      image;
+            	long		imageSize;
+    	        PixPatHandle pixpat = NewPixPat() ;
+
+		        CopyPixMap(gwpixmaphandle, (**pixpat).patMap);
+	            imageSize = GetPixRowBytes((**pixpat).patMap) *
+				    ((**(**pixpat).patMap).bounds.bottom -
+				    (**(**pixpat).patMap).bounds.top);
+				
+	            PtrToHand( (**gwpixmaphandle).baseAddr, &image, imageSize );
+	            (**pixpat).patData = image;
+	            CTabHandle ctable = ((**((**pixpat).patMap)).pmTable) ;
+	            ColorSpecPtr ctspec = (ColorSpecPtr) &(**ctable).ctTable ;
+	            if ( ctspec[0].rgb.red == 0x0000 )
+	            {
+	                ctspec[1].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ;
+	                ctspec[0].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ;
+	            }
+	            else
+	            {
+	                ctspec[0].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ;
+	                ctspec[1].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ;
+	            }
+	            ::CTabChanged( ctable ) ;
+	            ::PenPixPat(pixpat);
+#endif
+    	    }
 	    }
-	    else if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
+	    else
 	    {
-	        ::RGBForeColor( &m_textForegroundColour.GetPixel() );
-	        ::RGBForeColor( &m_textBackgroundColour.GetPixel() );
-		    ::PenPat(GetQDGlobalsBlack(&blackColor));
 	    }
+	    UnlockPixels( gwpixmaphandle ) ;
 	}
     else
     {
 	    ::PenPat(GetQDGlobalsBlack(&blackColor));
 	}
-
-	
-	// background
 	
-    MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ;
-	
-
-	// todo :
+    if ( !backgroundTransparent )
+        ::RGBBackColor( &MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ) ;
 	
 	short mode = patCopy ;
 	switch( m_logicalFunction )
 	{
 		case wxCOPY:       // src
-			mode = patCopy ;
+		    if ( backgroundTransparent )
+		        mode = patOr ;
+		    else
+			    mode = patCopy ;
 			break ;
 		case wxINVERT:     // NOT dst
-			::PenPat(GetQDGlobalsBlack(&blackColor));
+		    if ( !backgroundTransparent )
+		    {
+			    ::PenPat(GetQDGlobalsBlack(&blackColor));
+			}
 			mode = patXor ;
 			break ;
 		case wxXOR:        // src XOR dst
diff --git a/src/mac/dcclient.cpp b/src/mac/dcclient.cpp
index 467bc66238..eb9d6e467b 100644
--- a/src/mac/dcclient.cpp
+++ b/src/mac/dcclient.cpp
@@ -19,6 +19,7 @@
 #include "wx/window.h"
 #include "wx/toplevel.h"
 #include <math.h>
+#include "wx/mac/private.h"
 
 //-----------------------------------------------------------------------------
 // constants
@@ -49,16 +50,16 @@ wxWindowDC::wxWindowDC()
 wxWindowDC::wxWindowDC(wxWindow *the_canvas) 
 {
 	wxTopLevelWindowMac* rootwindow = the_canvas->MacGetTopLevelWindow() ;
-	WindowRef windowref = rootwindow->MacGetWindowRef() ;
+	WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
 	
 	int x , y ;
 	x = y = 0 ;
 	the_canvas->MacWindowToRootWindow( &x , &y ) ;
-	m_macLocalOrigin.h = x ;
-	m_macLocalOrigin.v = y ;
-	CopyRgn( the_canvas->MacGetVisibleRegion().GetWXHRGN() , m_macBoundaryClipRgn ) ;
-	OffsetRgn( m_macBoundaryClipRgn , m_macLocalOrigin.h , m_macLocalOrigin.v ) ;
-	CopyRgn( m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+	m_macLocalOrigin.x = x ;
+	m_macLocalOrigin.y = y ;
+	CopyRgn( (RgnHandle) the_canvas->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
+	OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
+	CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
 	m_macPort = UMAGetWindowPort( windowref ) ;
 	m_minY = m_minX =  0;
 	wxSize size = the_canvas->GetSize() ;
@@ -84,20 +85,20 @@ wxClientDC::wxClientDC()
 wxClientDC::wxClientDC(wxWindow *window)
 {
 	wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
-	WindowRef windowref = rootwindow->MacGetWindowRef() ;
+	WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
 	wxPoint origin = window->GetClientAreaOrigin() ;
 	wxSize size = window->GetClientSize() ;
 	int x , y ;
 	x = origin.x ;
 	y = origin.y ;
 	window->MacWindowToRootWindow( &x , &y ) ;
-	m_macLocalOrigin.h = x ;
-	m_macLocalOrigin.v = y ;
-	SetRectRgn( m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
-	SectRgn( m_macBoundaryClipRgn , window->MacGetVisibleRegion().GetWXHRGN() , m_macBoundaryClipRgn ) ;
-	OffsetRgn( m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
-	OffsetRgn( m_macBoundaryClipRgn , m_macLocalOrigin.h , m_macLocalOrigin.v ) ;
-	CopyRgn( m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+	m_macLocalOrigin.x = x ;
+	m_macLocalOrigin.y = y ;
+	SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
+	SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
+	OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
+	OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
+	CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle)  m_macCurrentClipRgn ) ;
 	m_macPort = UMAGetWindowPort( windowref ) ;
 	m_minY = m_minX =  0;
 	m_maxX = size.x  ;
@@ -122,21 +123,21 @@ wxPaintDC::wxPaintDC()
 wxPaintDC::wxPaintDC(wxWindow *window)
 {
 	wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
-	WindowRef windowref = rootwindow->MacGetWindowRef() ;
+	WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
 	wxPoint origin = window->GetClientAreaOrigin() ;
 	wxSize size = window->GetClientSize() ;
 	int x , y ;
 	x = origin.x ;
 	y = origin.y ;
 	window->MacWindowToRootWindow( &x , &y ) ;
-	m_macLocalOrigin.h = x ;
-	m_macLocalOrigin.v = y ;
-	SetRectRgn( m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
-	SectRgn( m_macBoundaryClipRgn , window->MacGetVisibleRegion().GetWXHRGN() , m_macBoundaryClipRgn ) ;
-	OffsetRgn( m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
-  SectRgn( m_macBoundaryClipRgn  , window->GetUpdateRegion().GetWXHRGN() , m_macBoundaryClipRgn ) ;
-	OffsetRgn( m_macBoundaryClipRgn , m_macLocalOrigin.h , m_macLocalOrigin.v ) ;
-	CopyRgn( m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+	m_macLocalOrigin.x = x ;
+	m_macLocalOrigin.y = y ;
+	SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
+	SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
+	OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
+  SectRgn( (RgnHandle) m_macBoundaryClipRgn  , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
+	OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
+	CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
 	m_macPort = UMAGetWindowPort( windowref ) ;
 	m_minY = m_minX =  0;
 	m_maxX = size.x  ;
diff --git a/src/mac/dcmemory.cpp b/src/mac/dcmemory.cpp
index 85f1af33c5..ad67ca77c0 100644
--- a/src/mac/dcmemory.cpp
+++ b/src/mac/dcmemory.cpp
@@ -14,6 +14,7 @@
 #endif
 
 #include "wx/dcmemory.h"
+#include "wx/mac/private.h"
 
 //-----------------------------------------------------------------------------
 // wxMemoryDC
@@ -43,7 +44,7 @@ wxMemoryDC::~wxMemoryDC()
 {
 	if ( m_selected.Ok() )
 	{
- 		UnlockPixels( GetGWorldPixMap(m_selected.GetHBITMAP()) );
+ 		UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
 	}
 };
 
@@ -51,7 +52,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
 {
 	if ( m_selected.Ok() )
 	{
- 		UnlockPixels( GetGWorldPixMap(m_selected.GetHBITMAP()) );
+ 		UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
 	}
     m_selected = bitmap;
     if (m_selected.Ok())
diff --git a/src/mac/dcprint.cpp b/src/mac/dcprint.cpp
index 36d8757f67..e81573f6bc 100644
--- a/src/mac/dcprint.cpp
+++ b/src/mac/dcprint.cpp
@@ -63,9 +63,9 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
 	}
 	
 #if !TARGET_CARBON
-	if ( ::PrValidate( m_printData.m_macPrintInfo ) )
+	if ( ::PrValidate( (THPrint) m_printData.m_macPrintInfo ) )
 	{
-		::PrStlDialog( m_printData.m_macPrintInfo ) ;
+		::PrStlDialog( (THPrint) m_printData.m_macPrintInfo ) ;
 		// the driver has changed in the mean time, should we pop up a page setup dialog ?
 	}
 	err = PrError() ;
@@ -79,7 +79,7 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
 		return;
 	}
 	::GetPort( &macPrintFormerPort ) ;
-	m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ;
+	m_macPrintPort = ::PrOpenDoc( (THPrint) m_printData.m_macPrintInfo , NULL , NULL ) ;
 	err = PrError() ;
 	if ( err )
 	{
@@ -143,8 +143,8 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
 	m_maxX = rPaper.right - rPaper.left ;
 	m_maxY = rPaper.bottom - rPaper.top ;
 #else
-	m_maxX = (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ;
-	m_maxY = (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ;
+	m_maxX = (**(THPrint)m_printData.m_macPrintInfo).rPaper.right - (**(THPrint)m_printData.m_macPrintInfo).rPaper.left ;
+	m_maxY = (**(THPrint)m_printData.m_macPrintInfo).rPaper.bottom - (**(THPrint)m_printData.m_macPrintInfo).rPaper.top ;
 #endif
 }
 
@@ -155,15 +155,15 @@ wxPrinterDC::~wxPrinterDC(void)
 #if !TARGET_CARBON
 	if ( m_ok )
 	{
-		::PrCloseDoc( m_macPrintPort  ) ;
+		::PrCloseDoc( (TPPrPort) m_macPrintPort  ) ;
 		err = PrError() ;
 		
 		if ( err == noErr )
 		{
-			if ( (**m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop )
+			if ( (**(THPrint)m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop )
 			{
 				TPrStatus status ;
-				::PrPicFile( m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ;
+				::PrPicFile( (THPrint) m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ;
 			}
 		}
 		else
@@ -233,9 +233,9 @@ void wxPrinterDC::StartPage(void)
 	wxString message ;
 
 #if !TARGET_CARBON
-  	PrOpenPage( m_macPrintPort , NULL ) ;
-  	m_macLocalOrigin.h =  (**m_printData.m_macPrintInfo).rPaper.left ;
-  	m_macLocalOrigin.v =  (**m_printData.m_macPrintInfo).rPaper.top ;
+  	PrOpenPage( (TPPrPort) m_macPrintPort , NULL ) ;
+  	m_macLocalOrigin.x =  (**(THPrint)m_printData.m_macPrintInfo).rPaper.left ;
+  	m_macLocalOrigin.y =  (**(THPrint)m_printData.m_macPrintInfo).rPaper.top ;
   	
 	Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
 	::ClipRect( &clip ) ;
@@ -245,8 +245,8 @@ void wxPrinterDC::StartPage(void)
 		message.Printf( "Print Error %d", err ) ;
 		wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
 		dialog.ShowModal();
-   		::PrClosePage( m_macPrintPort ) ;
-		::PrCloseDoc( m_macPrintPort ) ;
+   		::PrClosePage( (TPPrPort) m_macPrintPort ) ;
+		::PrCloseDoc( (TPPrPort) m_macPrintPort ) ;
 		::UMAPrClose() ;
 	   	::SetPort( macPrintFormerPort ) ;
 	   	m_ok = FALSE ;
@@ -288,14 +288,14 @@ void wxPrinterDC::EndPage(void)
 	wxString message ;
 
 #if !TARGET_CARBON
-   	PrClosePage(  (TPrPort*) m_macPort ) ;
+   	PrClosePage(  (TPPrPort) m_macPort ) ;
 	err = PrError() ;
 	if ( err != noErr )
 	{
 		message.Printf( "Print Error %d", err ) ;
 		wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
 		dialog.ShowModal();
-		::PrCloseDoc( m_macPrintPort  ) ;
+		::PrCloseDoc( (TPPrPort) m_macPrintPort  ) ;
 		::UMAPrClose() ;
 	   	::SetPort( macPrintFormerPort ) ;
 	   	m_ok = FALSE ;
diff --git a/src/mac/dirdlg.cpp b/src/mac/dirdlg.cpp
index 83533f1236..079663908a 100644
--- a/src/mac/dirdlg.cpp
+++ b/src/mac/dirdlg.cpp
@@ -20,6 +20,8 @@
 
 #include "wx/cmndata.h"
 
+#include "wx/mac/private.h"
+
 #ifdef __DARWIN__
   #include <Carbon/Carbon.h>
 #else
@@ -30,423 +32,11 @@
 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
 #endif
 
-bool gUseNavServices = NavServicesAvailable() ;
-
-// the data we need to pass to our standard file hook routine
-// includes a pointer to the dialog, a pointer to the standard
-// file reply record (so we can inspect the current selection)
-// and a copy of the "previous" file spec of the reply record
-// so we can see if the selection has changed
-
-#if !TARGET_CARBON
-
-struct UserDataRec {
-	StandardFileReply	*sfrPtr;
-	FSSpec				oldSelectionFSSpec;
-	DialogPtr			theDlgPtr;
-};
-typedef struct UserDataRec
-	UserDataRec, *UserDataRecPtr;
-
-enum {
-	kSelectItem = 10, 			// select button item number
-	kSFGetFolderDlgID = 250,	// dialog resource number
-	kStrListID = 250,			// our strings
-	kSelectStrNum = 1,			// word 'Select: ' for button
-	kDesktopStrNum = 2,			// word 'Desktop' for button
-	kSelectNoQuoteStrNum = 3,	// word 'Select: ' for button
-	
-	kUseQuotes = true,			// parameter for SetButtonName
-	kDontUseQuotes = false
-};
-
-
-static void GetLabelString(StringPtr theStr, short stringNum)
-{
-	GetIndString(theStr, kStrListID, stringNum);
-}
-
-static void CopyPStr(StringPtr src, StringPtr dest)
-{
-	BlockMoveData(src, dest, 1 + src[0]);
-}
-
-static char GetSelectKey(void)
-{
-	// this is the key used to trigger the select button
-	
-	// NOT INTERNATIONAL SAVVY; should at least grab it from resources
-	
-	return 's';
-}
-
-
-// SetButtonName sets the name of the Select button in the dialog
-//
-// To do this, we need to call the Script Manager to truncate the
-// label in the middle to fit the button and to merge the button
-// name with the word Select (possibly followed by quotes).  Using
-// the Script Manager avoids all sorts of problems internationally.
-//
-// buttonName is the name to appear following the word Select
-// quoteFlag should be true if the name is to appear in quotes
-
-static void SetButtonName(DialogPtr theDlgPtr, short buttonID, StringPtr buttonName,
-					Boolean quoteFlag)
-{
-	short 	buttonType;
-	Handle	buttonHandle;
-	Rect	buttonRect;
-	short	textWidth;
-	Handle	labelHandle;
-	Handle	nameHandle;
-	Str15	keyStr;
-	Str255	labelStr;
-	OSErr	err;
-	
-	nameHandle = nil;
-	labelHandle = nil;
-	
-	// get the details of the button from the dialog
-	
-	GetDialogItem(theDlgPtr, buttonID, &buttonType, &buttonHandle, &buttonRect);
-	
-	// get the string for the select button label, "Select ^0" or "Select Ò^0Ó"
-	
-	GetLabelString(labelStr, (quoteFlag == kUseQuotes) ? kSelectStrNum : kSelectNoQuoteStrNum);
-	
-	// make string handles containing the select button label and the
-	// file name to be stuffed into the button
-	
-	err = PtrToHand(&labelStr[1], &labelHandle, labelStr[0]);
-	if (err != noErr) goto Bail;
-	
-	// cut out the middle of the file name to fit the button
-	//
-	// we'll temporarily use labelStr here to hold the modified button name
-	// since we don't own the buttonName string storage space
-	
-	textWidth = (buttonRect.right - buttonRect.left) - StringWidth(labelStr);
-
-	CopyPStr(buttonName, labelStr);
-	(void) TruncString(textWidth, labelStr, smTruncMiddle);
-	
-	err = PtrToHand(&labelStr[1], &nameHandle, labelStr[0]);
-	if (err != noErr) goto Bail;
-	
-	// replace the ^0 in the Select string with the file name
-	
-	CopyPStr("\p^0", keyStr);
-	
-	(void) ReplaceText(labelHandle, nameHandle, keyStr);
-	
-	labelStr[0] = (unsigned char) GetHandleSize(labelHandle);
-	BlockMoveData(*labelHandle, &labelStr[1], labelStr[0]);
-	
-	// now set the control title, and re-validate the area
-	// above the control to avoid a needless redraw
-	
-	SetControlTitle((ControlHandle) buttonHandle, labelStr);
-	
-	ValidRect(&buttonRect);
-
-Bail:
-	if (nameHandle)		DisposeHandle(nameHandle);
-	if (labelHandle)	DisposeHandle(labelHandle);
-	
-}
-
-// FlashButton briefly highlights the dialog button 
-// as feedback for key equivalents
-
-static void FlashButton(DialogPtr theDlgPtr, short buttonID)
-{
-	short	buttonType;
-	Handle	buttonHandle;
-	Rect	buttonRect;
-	unsigned long	finalTicks;
-	
-	GetDialogItem(theDlgPtr, buttonID, &buttonType, &buttonHandle, &buttonRect);
-	HiliteControl((ControlHandle) buttonHandle, kControlButtonPart);
-	Delay(10, &finalTicks);
-	HiliteControl((ControlHandle) buttonHandle, 0);
-}
-
-static Boolean SameFSSpec(FSSpecPtr spec1, FSSpecPtr spec2)
-{
-	return (spec1->vRefNum == spec2->vRefNum
-			&& spec1->parID == spec2->parID
-			&& EqualString(spec1->name, spec2->name, false, false));
-}
-// MyModalDialogFilter maps a key to the Select button, and handles
-// flashing of the button when the key is hit
-
-static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRecord *eventRec,
-											short *item, void *dataPtr)
-{
-#pragma unused (dataPtr)
-
-	// make certain the proper dialog is showing, 'cause standard file
-	// can nest dialogs but calls the same filter for each
-	
-	if (((WindowPeek) theDlgPtr)->refCon == sfMainDialogRefCon)
-	{
-		// check if the select button was hit
-		
-		if ((eventRec->what == keyDown)
-			&& (eventRec->modifiers & cmdKey) 
-			&& ((eventRec->message & charCodeMask) == GetSelectKey()))
-		{
-			*item = kSelectItem;
-			FlashButton(theDlgPtr, kSelectItem);
-			return true;
-		}
-	}
-		
-	return false;
-}
-
-
-// MyDlgHook is a hook routine that maps the select button to Open
-// and sets the Select button name
-
-static pascal short SFGetFolderDialogHook(short item, DialogPtr theDlgPtr, void *dataPtr)
-{
-	UserDataRecPtr	theUserDataRecPtr;
-	long			desktopDirID;
-	short			desktopVRefNum;
-	FSSpec			tempSpec;
-	Str63			desktopName;
-	OSErr			err;
-	
-	// be sure Std File is really showing us the intended dialog,
-	// not a nested modal dialog
-	
-	if (((WindowPeek) theDlgPtr)->refCon != sfMainDialogRefCon)
-	{
-		return item;
-	}
-	
-	theUserDataRecPtr = (UserDataRecPtr) dataPtr;
-	
-	// map the Select button to Open
-	
-	if (item == kSelectItem)
-	{
-		item = sfItemOpenButton;
-	}
-	
-	// find the desktop folder
-	
-	err = FindFolder(theUserDataRecPtr->sfrPtr->sfFile.vRefNum,
-					kDesktopFolderType, kDontCreateFolder,
-					&desktopVRefNum, &desktopDirID);
-	
-	if (err != noErr)
-	{
-		// for errors, get value that won't match any real vRefNum/dirID
-		desktopVRefNum = 0;
-		desktopDirID = 0;
-	}
-	
-	// change the Select button label if the selection has changed or
-	// if this is the first call to the hook
-	
-	if (item == sfHookFirstCall
-		|| item == sfHookChangeSelection
-		|| item == sfHookRebuildList
-		|| ! SameFSSpec(&theUserDataRecPtr->sfrPtr->sfFile,
-					&theUserDataRecPtr->oldSelectionFSSpec))
-	{
-		// be sure there is a file name selected
-		
-		if (theUserDataRecPtr->sfrPtr->sfFile.name[0] != '\0')
-		{
-			SetButtonName(theDlgPtr, kSelectItem, 
-							theUserDataRecPtr->sfrPtr->sfFile.name, 
-							kUseQuotes);	// true -> use quotes
-		}
-		else
-		{
-			// is the desktop selected?
-			
-			if (theUserDataRecPtr->sfrPtr->sfFile.vRefNum == desktopVRefNum
-				&& theUserDataRecPtr->sfrPtr->sfFile.parID == desktopDirID)
-			{
-				// set button to "Select Desktop"
-				
-				GetLabelString(desktopName, kDesktopStrNum);
-				SetButtonName(theDlgPtr, kSelectItem, 
-								desktopName, kDontUseQuotes);	// false -> no quotes
-			}
-			else
-			{
-				// get parent directory's name for the Select button
-				//
-				// passing an empty name string to FSMakeFSSpec gets the
-				// name of the folder specified by the parID parameter
-				
-				(void) FSMakeFSSpec(theUserDataRecPtr->sfrPtr->sfFile.vRefNum,
-					theUserDataRecPtr->sfrPtr->sfFile.parID, "\p",
-					&tempSpec);
-				SetButtonName(theDlgPtr, kSelectItem, 
-							tempSpec.name, kUseQuotes); // true -> use quotes
-			}
-		}
-	}
-	
-	// save the current selection as the old selection for comparison next time
-	//
-	// it's not valid on the first call, though, or if we don't have a 
-	// name available from standard file
-	
-	if (item != sfHookFirstCall || theUserDataRecPtr->sfrPtr->sfFile.name[0] != '\0')
-	{
-		theUserDataRecPtr->oldSelectionFSSpec = theUserDataRecPtr->sfrPtr->sfFile;
-	}
-	else
-	{
-		// on first call, empty string won't set the button correctly, 
-		// so invalidate oldSelection
-		
-		theUserDataRecPtr->oldSelectionFSSpec.vRefNum = 999;
-		theUserDataRecPtr->oldSelectionFSSpec.parID = 0;
-	}
-	
-	return item;
-}
-
-void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileFilterYDUPP fileFilter, StandardFileReply *theSFR)
-{
-	Point 				thePt;
-	SFTypeList			mySFTypeList;
-	UserDataRec			myData;
-	FSSpec				tempSpec;
-	Boolean				folderFlag;
-	Boolean				wasAliasedFlag;
-	DlgHookYDUPP		dlgHookUPP;
-	ModalFilterYDUPP	myModalFilterUPP;
-	OSErr				err;
-	
-	
-	// presumably we're running System 7 or later so CustomGetFile is
-	// available
-	
-	// set initial contents of Select button to a space
-	
-	memcpy(theSFR->sfFile.name, "\p ", 2);
-	
-	// point the user data parameter at the reply record so we can get to it later
-	
-	myData.sfrPtr = theSFR;
-	
-	// display the dialog
-	
-	#if !TARGET_CARBON
-	
-	dlgHookUPP = NewDlgHookYDProc(SFGetFolderDialogHook);
-	myModalFilterUPP = NewModalFilterYDProc(SFGetFolderModalDialogFilter);
-	
-	thePt.h = thePt.v = -1;	// center dialog
-	
-	ParamText( message , NULL , NULL , NULL ) ;
-	
-	CustomGetFile(	fileFilter, 
-					-1,					// show all types
-					mySFTypeList,
-					theSFR,
-					kSFGetFolderDlgID,
-					thePt,				// top left point
-					dlgHookUPP,
-					myModalFilterUPP,
-					nil,				// activate list
-					nil,				// activate proc
-					&myData);
-					
-	DisposeRoutineDescriptor(dlgHookUPP);
-	DisposeRoutineDescriptor(myModalFilterUPP);
-	#else
-	#endif
-	
-	// if cancel wasn't pressed and no fatal error occurred...
-	
-	if (theSFR->sfGood)
-	{
-		// if no name is in the reply record file spec,
-		// use the file spec of the parent folder
-		
-		if (theSFR->sfFile.name[0] == '\0')
-		{
-			err = FSMakeFSSpec(theSFR->sfFile.vRefNum, theSFR->sfFile.parID,
-								"\p", &tempSpec);
-			if (err == noErr)
-			{
-				theSFR->sfFile = tempSpec;
-			}
-			else
-			{
-				// no name to return, forget it
-				
-				theSFR->sfGood = false;
-			}
-		}
-		
-		// if there is now a name in the file spec, check if it's
-		// for a folder or a volume
-		
-		if (theSFR->sfFile.name[0] != '\0')
-		{
-			// the parID of the root of a disk is always fsRtParID == 1
-			
-			if (theSFR->sfFile.parID == fsRtParID)
-			{
-				theSFR->sfIsVolume = true;
-				theSFR->sfIsFolder = false;	// it would be reasonable for this to be true, too
-			}
-			
-			// we have a valid FSSpec, now let's make sure it's not for an alias file
-			
-			err = ResolveAliasFile(&theSFR->sfFile, true, &folderFlag, &wasAliasedFlag);
-			if (err != noErr)
-			{
-				theSFR->sfGood = false;
-			}
-			
-			// did the alias resolve to a folder?
-			
-			if (folderFlag  && ! theSFR->sfIsVolume)
-			{
-				theSFR->sfIsFolder = true;
-			}
-		}
-	}
-}
-
-static pascal Boolean OnlyVisibleFoldersCustomFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr)
-{
-#pragma unused (dataPtr)
-
-	// return true if this item is invisible or a file
-
-	Boolean visibleFlag;
-	Boolean folderFlag;
-	
-	visibleFlag = ! (myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible);
-	folderFlag = (myCInfoPBPtr->hFileInfo.ioFlAttrib & 0x10);
-	
-	// because the semantics of the filter proc are "true means don't show
-	// it" we need to invert the result that we return
-	
-	return !(visibleFlag && folderFlag);
-}
-
-#endif
-
-
 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
         const wxString& defaultPath,
         long style, const wxPoint& pos)
 {
+	wxASSERT_MSG( NavServicesAvailable() , "Navigation Services are not running" ) ;
     m_message = message;
     m_dialogStyle = style;
     m_parent = parent;
@@ -455,145 +45,98 @@ wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
 
 int wxDirDialog::ShowModal()
 {
-	#if !TARGET_CARBON
-	if ( !gUseNavServices )
-	{
-		Str255				prompt ;
-		Str255				path ;
-
-#if TARGET_CARBON
-		c2pstrcpy((StringPtr)prompt, m_message) ;
-#else
-		strcpy((char *)prompt, m_message) ;
-		c2pstr((char *)prompt ) ;
-#endif
-#if TARGET_CARBON
-		c2pstrcpy((StringPtr)path, m_path ) ;
-#else
-		strcpy((char *)path, m_path ) ;
-		c2pstr((char *)path ) ;
-#endif
-
-		StandardFileReply	reply ;
-		FileFilterYDUPP 	invisiblesExcludedCustomFilterUPP = 0 ;
-		invisiblesExcludedCustomFilterUPP = 
-			NewFileFilterYDProc(OnlyVisibleFoldersCustomFileFilter);
-
-
-		StandardGetFolder( prompt , path , invisiblesExcludedCustomFilterUPP, &reply);
+	NavDialogOptions		mNavOptions;
+	NavObjectFilterUPP		mNavFilterUPP = NULL;
+	NavPreviewUPP			mNavPreviewUPP = NULL ;
+	NavReplyRecord			mNavReply;
+	AEDesc*					mDefaultLocation = NULL ;
+	bool					mSelectDefault = false ;
+	
+	::NavGetDefaultDialogOptions(&mNavOptions);
+
+	mNavFilterUPP	= nil;
+	mNavPreviewUPP	= nil;
+	mSelectDefault	= false;
+	mNavReply.validRecord				= false;
+	mNavReply.replacing					= false;
+	mNavReply.isStationery				= false;
+	mNavReply.translationNeeded			= false;
+	mNavReply.selection.descriptorType = typeNull;
+	mNavReply.selection.dataHandle		= nil;
+	mNavReply.keyScript					= smSystemScript;
+	mNavReply.fileTranslation			= nil;
+	
+	// Set default location, the location
+	//   that's displayed when the dialog
+	//   first appears
+	
+	if ( mDefaultLocation ) {
+		
+		if (mSelectDefault) {
+			mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
+		} else {
+			mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
+		}
+	}
 	
+	OSErr err = ::NavChooseFolder(
+						mDefaultLocation,
+						&mNavReply,
+						&mNavOptions,
+						NULL,
+						mNavFilterUPP,
+						0L);							// User Data
+	
+	if ( (err != noErr) && (err != userCanceledErr) ) {
+		m_path = "" ;
+		return wxID_CANCEL ;
+	}
 
-		DisposeRoutineDescriptor(invisiblesExcludedCustomFilterUPP);
-
-		if ( reply.sfGood == false )
-		{
+	if (mNavReply.validRecord) {		// User chose a folder
+	
+		FSSpec	folderInfo;
+		FSSpec  outFileSpec ;
+		AEDesc specDesc ;
+		
+		OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
+		if ( err != noErr ) {
 			m_path = "" ;
 			return wxID_CANCEL ;
+		}			
+		folderInfo = **(FSSpec**) specDesc.dataHandle;
+		if (specDesc.dataHandle != nil) {
+			::AEDisposeDesc(&specDesc);
 		}
-		else
-		{
-			m_path = wxMacFSSpec2MacFilename( &reply.sfFile ) ;
-			return wxID_OK ;
-		}
-		return wxID_CANCEL;
-	}
-	else
-	#endif
-	{
-		NavDialogOptions		mNavOptions;
-		NavObjectFilterUPP		mNavFilterUPP = NULL;
-		NavPreviewUPP			mNavPreviewUPP = NULL ;
-		NavReplyRecord			mNavReply;
-		AEDesc*					mDefaultLocation = NULL ;
-		bool					mSelectDefault = false ;
-		
-		::NavGetDefaultDialogOptions(&mNavOptions);
-	
-		mNavFilterUPP	= nil;
-		mNavPreviewUPP	= nil;
-		mSelectDefault	= false;
-		mNavReply.validRecord				= false;
-		mNavReply.replacing					= false;
-		mNavReply.isStationery				= false;
-		mNavReply.translationNeeded			= false;
-		mNavReply.selection.descriptorType = typeNull;
-		mNavReply.selection.dataHandle		= nil;
-		mNavReply.keyScript					= smSystemScript;
-		mNavReply.fileTranslation			= nil;
-		
-		// Set default location, the location
-		//   that's displayed when the dialog
-		//   first appears
+
+//			mNavReply.GetFileSpec(folderInfo);
 		
-		if ( mDefaultLocation ) {
-			
-			if (mSelectDefault) {
-				mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
-			} else {
-				mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
-			}
-		}
+			// The FSSpec from NavChooseFolder is NOT the file spec
+			// for the folder. The parID field is actually the DirID
+			// of the folder itself, not the folder's parent, and
+			// the name field is empty. We must call PBGetCatInfo
+			// to get the parent DirID and folder name
 		
-		OSErr err = ::NavChooseFolder(
-							mDefaultLocation,
-							&mNavReply,
-							&mNavOptions,
-							NULL,
-							mNavFilterUPP,
-							0L);							// User Data
+		Str255		name;
+		CInfoPBRec	thePB;			// Directory Info Parameter Block
+		thePB.dirInfo.ioCompletion	= nil;
+		thePB.dirInfo.ioVRefNum		= folderInfo.vRefNum;	// Volume is right
+		thePB.dirInfo.ioDrDirID		= folderInfo.parID;		// Folder's DirID
+		thePB.dirInfo.ioNamePtr		= name;
+		thePB.dirInfo.ioFDirIndex	= -1;	// Lookup using Volume and DirID
 		
-		if ( (err != noErr) && (err != userCanceledErr) ) {
+		err = ::PBGetCatInfoSync(&thePB);
+		if ( err != noErr ) {
 			m_path = "" ;
 			return wxID_CANCEL ;
-		}
-
-		if (mNavReply.validRecord) {		// User chose a folder
-		
-			FSSpec	folderInfo;
-			FSSpec  outFileSpec ;
-			AEDesc specDesc ;
-			
-			OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
-			if ( err != noErr ) {
-				m_path = "" ;
-				return wxID_CANCEL ;
-			}			
-			folderInfo = **(FSSpec**) specDesc.dataHandle;
-			if (specDesc.dataHandle != nil) {
-				::AEDisposeDesc(&specDesc);
-			}
-
-//			mNavReply.GetFileSpec(folderInfo);
-			
-				// The FSSpec from NavChooseFolder is NOT the file spec
-				// for the folder. The parID field is actually the DirID
-				// of the folder itself, not the folder's parent, and
-				// the name field is empty. We must call PBGetCatInfo
-				// to get the parent DirID and folder name
-			
-			Str255		name;
-			CInfoPBRec	thePB;			// Directory Info Parameter Block
-			thePB.dirInfo.ioCompletion	= nil;
-			thePB.dirInfo.ioVRefNum		= folderInfo.vRefNum;	// Volume is right
-			thePB.dirInfo.ioDrDirID		= folderInfo.parID;		// Folder's DirID
-			thePB.dirInfo.ioNamePtr		= name;
-			thePB.dirInfo.ioFDirIndex	= -1;	// Lookup using Volume and DirID
-			
-			err = ::PBGetCatInfoSync(&thePB);
-			if ( err != noErr ) {
-				m_path = "" ;
-				return wxID_CANCEL ;
-			}			
-												// Create cannonical FSSpec
-			::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
-						   name, &outFileSpec);
-							
-			// outFolderDirID = thePB.dirInfo.ioDrDirID;
-			m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
-			return wxID_OK ;
-		}
-		return wxID_CANCEL;
-
+		}			
+											// Create cannonical FSSpec
+		::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
+					   name, &outFileSpec);
+						
+		// outFolderDirID = thePB.dirInfo.ioDrDirID;
+		m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
+		return wxID_OK ;
 	}
+	return wxID_CANCEL;
 }
 
diff --git a/src/mac/dirmac.cpp b/src/mac/dirmac.cpp
index c1b010f5f7..1acff5b7ca 100644
--- a/src/mac/dirmac.cpp
+++ b/src/mac/dirmac.cpp
@@ -40,6 +40,8 @@
   #include <windows.h>
 #endif
 
+#include "wx/mac/private.h"
+
 #include "MoreFiles.h"
 #include "MoreFilesExtras.h"
 
diff --git a/src/mac/dnd.cpp b/src/mac/dnd.cpp
index 2965b50d5c..e81ad045d2 100644
--- a/src/mac/dnd.cpp
+++ b/src/mac/dnd.cpp
@@ -22,6 +22,7 @@
 #include "wx/toplevel.h"
 #include "wx/app.h"
 #include "wx/gdicmn.h"
+#include "wx/mac/private.h"
 
 // ----------------------------------------------------------------------------
 // global
@@ -104,17 +105,17 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
     {
       UInt16 items ;
       OSErr result;
-      CountDragItems(m_currentDrag, &items);
+      CountDragItems((DragReference)m_currentDrag, &items);
       for (UInt16 index = 1; index <= items && supported == false ; ++index) 
       {
           ItemReference theItem;
           FlavorType theType ;
           UInt16 flavors = 0 ;
-          GetDragItemReferenceNumber(m_currentDrag, index, &theItem);
-          CountDragItemFlavors( m_currentDrag, theItem , &flavors ) ;
+          GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
+          CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
           for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
           {
-            result = GetFlavorType(m_currentDrag, theItem, flavor , &theType);
+            result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
             if ( m_dataObject->IsSupportedFormat( wxDataFormat( theType ) ) )
             {
               supported = true ;
@@ -172,31 +173,31 @@ bool wxDropTarget::GetData()
     {
       UInt16 items ;
       OSErr result;
-      CountDragItems(m_currentDrag, &items);
+      CountDragItems((DragReference)m_currentDrag, &items);
       for (UInt16 index = 1; index <= items; ++index) 
       {
           ItemReference theItem;
           FlavorType theType ;
           UInt16 flavors = 0 ;
-          GetDragItemReferenceNumber(m_currentDrag, index, &theItem);
-          CountDragItemFlavors( m_currentDrag, theItem , &flavors ) ;
+          GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
+          CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
           for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
           {
-            result = GetFlavorType(m_currentDrag, theItem, flavor , &theType);
+            result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
             wxDataFormat format(theType) ;
             if ( m_dataObject->IsSupportedFormat( format ) )
             {
               FlavorFlags theFlags;
-              result = GetFlavorFlags(m_currentDrag, theItem, theType, &theFlags);
+              result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
               if (result == noErr) 
               {
                   Size dataSize ;
                   Ptr theData ;
-                  GetFlavorDataSize(m_currentDrag, theItem, theType, &dataSize);
+                  GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
           			  if ( theType == 'TEXT' )
           			    dataSize++ ;
                   theData = new char[dataSize];
-                  GetFlavorData(m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L); 
+                  GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L); 
                   if( theType == 'TEXT' )
                   {
                     theData[dataSize]=0 ;       
@@ -335,7 +336,7 @@ wxDragResult wxDropSource::DoDragDrop( bool allowMove )
     dragRegion = NewRgn();
     RgnHandle tempRgn = NewRgn() ;
     
-    EventRecord* ev = wxTheApp->MacGetCurrentEvent() ;
+    EventRecord* ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
     const short dragRegionOuterBoundary = 10 ;
     const short dragRegionInnerBoundary = 9 ;
     
diff --git a/src/mac/filedlg.cpp b/src/mac/filedlg.cpp
index 6ca66d390f..87e7846177 100644
--- a/src/mac/filedlg.cpp
+++ b/src/mac/filedlg.cpp
@@ -31,6 +31,8 @@ IMPLEMENT_CLASS(wxFileDialog, wxDialog)
 
 // begin wxmac
 
+#include "wx/mac/private.h"
+
 #include <Navigation.h>
 
 #include "MoreFiles.h"
@@ -112,132 +114,6 @@ OSType gfiltersmac[] =
 } ;
 
 
-#if !TARGET_CARBON
-
-static void wxMacSetupStandardFile(short newVRefNum, long newDirID) 
-{ 
-	enum 
-	{ SFSaveDisk = 0x214, CurDirStore = 0x398 };
-	*(short *) SFSaveDisk = -1 * newVRefNum; 
-	*(long *) CurDirStore = newDirID; 
-}
-
-static void wxMacSetupStandardFileFromPath( const char* s )
-{
-	Str255	volume ;
-	Str255	path ;
-	short	vRefNum ;
-	long dirRef ;
-	short	i,j ;
-	Boolean isDirectory ;
-	
-	for (i=0 ; (s[i]!=0) && (s[i]!=':') ;i++)
-		{
-		volume[i]=s[i] ;
-		}
-	volume[i]=':' ;
-	volume[i+1]=0 ;
-	
-	// then copy the rest of the filename
-	
-	for (j=0;(s[i]!=0);i++,j++)
-		{
-		path[j]=s[i] ;		
-		}
-	path[j]=0 ;
-	
-	c2pstr((Ptr) volume) ;
-	c2pstr((Ptr) path) ;
-	
-	SetVol(volume, 0) ;
-	GetVol( NULL, &vRefNum ) ;
-		
-	GetDirectoryID( vRefNum , fsRtDirID , path , &dirRef , &isDirectory ) ;
-	wxMacSetupStandardFile(vRefNum, dirRef) 	;
-}
-
-enum {
-	kSelectItem = 10, 			// select button item number
-	kSFGetFileDlgID = 251,	// dialog resource number
-	kStrListID = 251,			// our strings
-	kSelectStrNum = 1,			// word 'Select: ' for button
-	kDesktopStrNum = 2,			// word 'Desktop' for button
-	kSelectNoQuoteStrNum = 3,	// word 'Select: ' for button
-	
-	kUseQuotes = true,			// parameter for SetButtonName
-	kDontUseQuotes = false
-};
-
-static void GetLabelString(StringPtr theStr, short stringNum)
-{
-	GetIndString(theStr, kStrListID, stringNum);
-}
-
-static void CopyPStr(StringPtr src, StringPtr dest)
-{
-	BlockMoveData(src, dest, 1 + src[0]);
-}
-
-static char GetSelectKey(void)
-{
-	// this is the key used to trigger the select button
-	
-	// NOT INTERNATIONAL SAVVY; should at least grab it from resources
-	
-	return 's';
-}
-
-// FlashButton briefly highlights the dialog button 
-// as feedback for key equivalents
-
-static void FlashButton(DialogPtr theDlgPtr, short buttonID)
-{
-	short	buttonType;
-	Handle	buttonHandle;
-	Rect	buttonRect;
-	unsigned long	finalTicks;
-	
-	GetDialogItem(theDlgPtr, buttonID, &buttonType, &buttonHandle, &buttonRect);
-	HiliteControl((ControlHandle) buttonHandle, kControlButtonPart);
-	Delay(10, &finalTicks);
-	HiliteControl((ControlHandle) buttonHandle, 0);
-}
-
-static Boolean SameFSSpec(FSSpecPtr spec1, FSSpecPtr spec2)
-{
-	return (spec1->vRefNum == spec2->vRefNum
-			&& spec1->parID == spec2->parID
-			&& EqualString(spec1->name, spec2->name, false, false));
-}
-// MyModalDialogFilter maps a key to the Select button, and handles
-// flashing of the button when the key is hit
-
-static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRecord *eventRec,
-											short *item, void *dataPtr)
-{
-#pragma unused (dataPtr)
-
-	// make certain the proper dialog is showing, 'cause standard file
-	// can nest dialogs but calls the same filter for each
-	
-	if (((WindowPeek) theDlgPtr)->refCon == sfMainDialogRefCon)
-	{
-		// check if the select button was hit
-		/*
-		if ((eventRec->what == keyDown)
-			&& (eventRec->modifiers & cmdKey) 
-			&& ((eventRec->message & charCodeMask) == GetSelectKey()))
-		{
-			*item = kSelectItem;
-			FlashButton(theDlgPtr, kSelectItem);
-			return true;
-		}
-		*/
-	}
-		
-	return false;
-}
-#endif !TARGET_CARBON
 
 void MakeUserDataRec(OpenUserDataRec	*myData , const wxString& filter )
 {
@@ -300,113 +176,6 @@ void MakeUserDataRec(OpenUserDataRec	*myData , const wxString& filter )
 
 }
 
-#ifndef __DARWIN__
-void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const char *filter , FileFilterYDUPP fileFilter, StandardFileReply *theSFR )
-{
-	Point 				thePt;
-	OpenUserDataRec			myData;
-	FSSpec				tempSpec;
-	Boolean				folderFlag;
-	Boolean				wasAliasedFlag;
-	DlgHookYDUPP		dlgHookUPP;
-	ModalFilterYDUPP	myModalFilterUPP;
-	OSErr				err;
-	SFTypeList			types ;
-	
-	
-	// presumably we're running System 7 or later so CustomGetFile is
-	// available
-	
-	// set initial contents of Select button to a space
-	
-	memcpy( theSFR->sfFile.name , "\p " , 2 ) ;
-	
-	// point the user data parameter at the reply record so we can get to it later
-	
-	MakeUserDataRec( &myData , filter ) ;
-	// display the dialog
-
-#if !TARGET_CARBON
-	
-	dlgHookUPP = NULL ;
-//	dlgHookUPP = NewDlgHookYDProc(SFGetFolderDialogHook);
-	myModalFilterUPP = NewModalFilterYDProc(SFGetFolderModalDialogFilter);
-	
-	thePt.h = thePt.v = -1;	// center dialog
-	
-	ParamText( message , NULL , NULL , NULL ) ;
-	
-	CustomGetFile(	fileFilter, 
-			-1,		       		// show all types
-			NULL,
-			theSFR,
-			kSFGetFileDlgID,
-			thePt,				// top left point
-			dlgHookUPP,
-			myModalFilterUPP,
-			nil,				// activate list
-			nil,				// activate proc
-			&myData);
-					
-	DisposeRoutineDescriptor(dlgHookUPP);
-	DisposeRoutineDescriptor(myModalFilterUPP);
-#else
-#endif	
-	// if cancel wasn't pressed and no fatal error occurred...
-	
-	if (theSFR->sfGood)
-	{
-		// if no name is in the reply record file spec,
-		// use the file spec of the parent folder
-		
-		if (theSFR->sfFile.name[0] == '\0')
-		{
-			err = FSMakeFSSpec(theSFR->sfFile.vRefNum, theSFR->sfFile.parID,
-					   "\p", &tempSpec);
-			if (err == noErr)
-			{
-				theSFR->sfFile = tempSpec;
-			}
-			else
-			{
-				// no name to return, forget it
-				
-				theSFR->sfGood = false;
-			}
-		}
-		
-		// if there is now a name in the file spec, check if it's
-		// for a folder or a volume
-		
-		if (theSFR->sfFile.name[0] != '\0')
-		{
-			// the parID of the root of a disk is always fsRtParID == 1
-			
-			if (theSFR->sfFile.parID == fsRtParID)
-			{
-				theSFR->sfIsVolume = true;
-				theSFR->sfIsFolder = false;	// it would be reasonable for this to be true, too
-			}
-			
-			// we have a valid FSSpec, now let's make sure it's not for an alias file
-			
-			err = ResolveAliasFile(&theSFR->sfFile, true, &folderFlag, &wasAliasedFlag);
-			if (err != noErr)
-			{
-				theSFR->sfGood = false;
-			}
-			
-			// did the alias resolve to a folder?
-			
-			if (folderFlag  && ! theSFR->sfIsVolume)
-			{
-				theSFR->sfIsFolder = true;
-			}
-		}
-	}
-}
-#endif
-
 static Boolean CheckFile( ConstStr255Param name , OSType type , OpenUserDataRecPtr data)
 {
     Str255 			filename ;
@@ -541,6 +310,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
         const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
         long style, const wxPoint& pos)
 {
+	  wxASSERT_MSG( NavServicesAvailable() , "Navigation Services are not running" ) ;
     m_message = message;
     m_dialogStyle = style;
     m_parent = parent;
@@ -578,70 +348,6 @@ pascal Boolean CrossPlatformFilterCallback (
 
 int wxFileDialog::ShowModal()
 {
-#if !TARGET_CARBON
-	if ( !gUseNavServices )
-	{
-	if ( m_dialogStyle & wxSAVE )
-	{
-		StandardFileReply	reply ;
-		Str255				prompt ;
-		Str255				filename ;
-
-		strcpy((char *)prompt, m_message) ;
-		c2pstr((char *)prompt ) ;
-		strcpy((char *)filename, m_fileName) ;
-		c2pstr((char *)filename ) ;
-
-		StandardPutFile( prompt , filename , &reply ) ;
-		if ( reply.sfGood == false )
-		{
-			m_path = "" ;
-			return wxID_CANCEL ;
-		}
-		else
-		{
-			m_path = wxMacFSSpec2MacFilename( &reply.sfFile ) ;
-			return wxID_OK ;
-		}
-	}
-	else
-	{
-		OSType types = '????' ;
-		Str255				prompt ;
-		Str255				path ;
-
-		strcpy((char *)prompt, m_message) ;
-		c2pstr((char *)prompt ) ;
-		strcpy((char *)path, m_dir ) ;
-		c2pstr((char *)path ) ;
-
-		StandardFileReply	reply ;
-		FileFilterYDUPP crossPlatformFileFilterUPP = 0 ;
-		#if !TARGET_CARBON
-		crossPlatformFileFilterUPP = 
-			NewFileFilterYDProc(CrossPlatformFileFilter);
-		#endif
-
-		ExtendedOpenFile( prompt , path , m_wildCard , crossPlatformFileFilterUPP, &reply);
-		#if !TARGET_CARBON
-		DisposeFileFilterYDUPP(crossPlatformFileFilterUPP);
-		#endif
-		if ( reply.sfGood == false )
-		{
-			m_path = "" ;
-			return wxID_CANCEL ;
-		}
-		else
-		{
-			m_path = wxMacFSSpec2UnixFilename( &reply.sfFile ) ;
-			return wxID_OK ;
-		}
-	}
-    return wxID_CANCEL;
-}
-	else
-#endif
-	{
 		NavDialogOptions		mNavOptions;
 		NavObjectFilterUPP		mNavFilterUPP = NULL;
 		NavPreviewUPP			mNavPreviewUPP = NULL ;
@@ -800,7 +506,6 @@ int wxFileDialog::ShowModal()
 			return wxID_OK ;
 		}
 		return wxID_CANCEL;
-	}
 }
 
 // Generic file load/save dialog
diff --git a/src/mac/font.cpp b/src/mac/font.cpp
index 2d3e5f9033..2335e5d262 100644
--- a/src/mac/font.cpp
+++ b/src/mac/font.cpp
@@ -22,6 +22,9 @@
 
 #include "wx/fontutil.h"
 
+#include "wx/mac/private.h"
+
+
 #if !USE_SHARED_LIBRARIES
 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
 #endif
diff --git a/src/mac/fontenum.cpp b/src/mac/fontenum.cpp
index 14491d79e9..e1b1347c6d 100644
--- a/src/mac/fontenum.cpp
+++ b/src/mac/fontenum.cpp
@@ -37,6 +37,8 @@
 #include "wx/fontmap.h"
 #include "wx/fontutil.h"
 
+#include "wx/mac/private.h"
+
 // ----------------------------------------------------------------------------
 // private classes
 // ----------------------------------------------------------------------------
diff --git a/src/mac/gauge.cpp b/src/mac/gauge.cpp
index 38367d88c6..cdaaf58a71 100644
--- a/src/mac/gauge.cpp
+++ b/src/mac/gauge.cpp
@@ -41,7 +41,7 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id,
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style & 0xE0FFFFFF /* no borders on mac */ , validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , range, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , range, 
 	  	kControlProgressBarProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
@@ -60,13 +60,13 @@ void wxGauge::SetBezelFace(int w)
 void wxGauge::SetRange(int r)
 {
     m_rangeMax = r;
-    ::SetControlMaximum( m_macControl , m_rangeMax ) ;
+    ::SetControlMaximum( (ControlHandle) m_macControl , m_rangeMax ) ;
 }
 
 void wxGauge::SetValue(int pos)
 {
     m_gaugePos = pos;
-   	::SetControlValue( m_macControl , m_gaugePos ) ;
+   	::SetControlValue( (ControlHandle) m_macControl , m_gaugePos ) ;
 }
 
 int wxGauge::GetShadowWidth() const
diff --git a/src/mac/glcanvas.cpp b/src/mac/glcanvas.cpp
index ae60210ef3..62d9c307c4 100644
--- a/src/mac/glcanvas.cpp
+++ b/src/mac/glcanvas.cpp
@@ -45,7 +45,7 @@ wxGLContext::wxGLContext(
 {
     m_window = win;
 
-    m_drawable = (AGLDrawable) UMAGetWindowPort(win->MacGetRootWindow());
+    m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetRootWindow()));
 
     m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL);
     wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") );
@@ -251,7 +251,7 @@ void wxGLCanvas::SetViewport()
     int width, height;
     GetClientSize(& width, & height);
     Rect bounds ;
-    GetWindowPortBounds( MacGetRootWindow() , &bounds ) ;
+    GetWindowPortBounds( MAC_WXHWND(MacGetRootWindow()) , &bounds ) ;
     GLint parms[4] ;
     parms[0] = x ;
     parms[1] = bounds.bottom - bounds.top - ( y + height ) ;
diff --git a/src/mac/gsocket.c b/src/mac/gsocket.c
index ef89f1a511..7fed13e8c4 100644
--- a/src/mac/gsocket.c
+++ b/src/mac/gsocket.c
@@ -29,6 +29,7 @@
     #define TRUE 1
   #endif
 #else
+  #include <MacHeaders.c>
   #define OTUNIXERRORS 1
   #include <OpenTransport.h>
   #include <OpenTransportProviders.h>
diff --git a/src/mac/icon.cpp b/src/mac/icon.cpp
index 0133e45534..2ae29d1859 100644
--- a/src/mac/icon.cpp
+++ b/src/mac/icon.cpp
@@ -19,6 +19,9 @@
 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
 #endif
 
+#include "wx/mac/private.h"
+
+
 /*
  * Icons
  */
@@ -43,18 +46,18 @@ wxIcon::wxIcon( char **bits ) :
 {
 }
 
-wxIcon::wxIcon(const wxString& icon_file, long flags,
+wxIcon::wxIcon(const wxString& icon_file, int flags,
     int desiredWidth, int desiredHeight)
 
 {
-    LoadFile(icon_file, flags, desiredWidth, desiredHeight);
+    LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight);
 }
 
 wxIcon::~wxIcon()
 {
 }
 
-bool wxIcon::LoadFile(const wxString& filename, long type,
+bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
     int desiredWidth, int desiredHeight)
 {
   UnRef();
diff --git a/src/mac/listbox.cpp b/src/mac/listbox.cpp
index 8aa4fda2a3..9533882e9e 100644
--- a/src/mac/listbox.cpp
+++ b/src/mac/listbox.cpp
@@ -93,10 +93,10 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect
             //  appropriate QuickDraw transform mode.
             
             if( isSelected ) {
-                savedPenMode = GetPortPenMode( grafPtr );
-                SetPortPenMode( grafPtr, hilitetransfermode );
+                savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
+                SetPortPenMode( (CGrafPtr)grafPtr, hilitetransfermode );
                 PaintRect( drawRect );
-                SetPortPenMode( grafPtr, savedPenMode );
+                SetPortPenMode( (CGrafPtr)grafPtr, savedPenMode );
             }
             
             //  Restore the saved clip region.
@@ -111,10 +111,10 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect
             //  appropriate QuickDraw transform mode.
             
             GetPort( &grafPtr );
-            savedPenMode = GetPortPenMode( grafPtr );
-            SetPortPenMode( grafPtr, hilitetransfermode );
+            savedPenMode = GetPortPenMode( (CGrafPtr)grafPtr );
+            SetPortPenMode( (CGrafPtr)grafPtr, hilitetransfermode );
             PaintRect( drawRect );
-            SetPortPenMode( grafPtr, savedPenMode );
+            SetPortPenMode( (CGrafPtr)grafPtr, savedPenMode );
             break;
         default :
           break ;
@@ -171,36 +171,36 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
     CreateListBoxControl( parent->MacGetRootWindow(), &bounds, false, 0, 1, false, true,
                           kwxMacListItemHeight, kwxMacListItemHeight, false, &listDef, &m_macControl );
 
-    GetControlData(m_macControl, kControlNoPart, kControlListBoxListHandleTag,
+    GetControlData( (ControlHandle) m_macControl, kControlNoPart, kControlListBoxListHandleTag,
                    sizeof(ListHandle), (Ptr) &m_macList, &asize);
 
-    SetControlReference(m_macControl, (long) this);
-    SetControlVisibility(m_macControl, false, false);
+    SetControlReference( (ControlHandle) m_macControl, (long) this);
+    SetControlVisibility( (ControlHandle) m_macControl, false, false);
 
 #else
 
     long    result ;
 
-    m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false ,
+    m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
                   kwxMacListWithVerticalScrollbar , 0 , 0, 
                   kControlListBoxProc , (long) this ) ;
-    ::GetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
+    ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
                sizeof( ListHandle ) , (char*) &m_macList  , &result ) ;
 
     HLock( (Handle) m_macList ) ;
     ldefHandle ldef ;
     ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ;
-    if (  (**m_macList).listDefProc != NULL )
+    if (  (**(ListHandle)m_macList).listDefProc != NULL )
     {
       (**ldef).instruction = 0x4EF9;  /* JMP instruction */
       (**ldef).function = (void(*)()) listDef.u.userProc;
-      (**m_macList).listDefProc = (Handle) ldef ;
+      (**(ListHandle)m_macList).listDefProc = (Handle) ldef ;
     }
         
-    Point pt = (**m_macList).cellSize ;
+    Point pt = (**(ListHandle)m_macList).cellSize ;
     pt.v = kwxMacListItemHeight ;
-    LCellSize( pt , m_macList ) ;
-    LAddColumn( 1 , 0 , m_macList ) ;
+    LCellSize( pt , (ListHandle)m_macList ) ;
+    LAddColumn( 1 , 0 , (ListHandle)m_macList ) ;
 #endif
     OptionBits  options = 0;
     if ( style & wxLB_MULTIPLE )
@@ -215,7 +215,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
     {
         options = lOnlyOne ;
     }
-    SetListSelectionFlags(m_macList, options);
+    SetListSelectionFlags((ListHandle)m_macList, options);
     
     MacPostControlCreate() ;
     
@@ -224,7 +224,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
         Append( choices[i] ) ;
     }
     
-    LSetDrawingMode( true , m_macList ) ;
+    LSetDrawingMode( true , (ListHandle)m_macList ) ;
 
     return TRUE;
 }
@@ -235,8 +235,8 @@ wxListBox::~wxListBox()
     if ( m_macList )
     {
 #if !TARGET_CARBON
-      DisposeHandle( (**m_macList).listDefProc ) ;
-      (**m_macList).listDefProc = NULL ;
+      DisposeHandle( (**(ListHandle)m_macList).listDefProc ) ;
+      (**(ListHandle)m_macList).listDefProc = NULL ;
 #endif
         m_macList = NULL ;
     }
@@ -272,7 +272,7 @@ void  wxListBox::DoSetSize(int x, int y,
     wxControl::DoSetSize( x , y , width , height , sizeFlags ) ;
 #if TARGET_CARBON
     Rect bounds ;
-    GetControlBounds( m_macControl , &bounds ) ;
+    GetControlBounds( (ControlHandle) m_macControl , &bounds ) ;
     ControlRef control = GetListVerticalScrollBar( m_macList ) ;
     if ( control )
     {
@@ -633,7 +633,7 @@ void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refC
 
 void wxListBox::MacDelete( int N )
 {
-    LDelRow( 1 , N , m_macList) ;
+    LDelRow( 1 , N , (ListHandle)m_macList) ;
     Refresh();
 }
 
@@ -641,7 +641,7 @@ void wxListBox::MacInsert( int n , const char * text)
 {
     Cell cell = { 0 , 0 } ;
     cell.v = n ;
-    LAddRow( 1 , cell.v , m_macList ) ;
+    LAddRow( 1 , cell.v , (ListHandle)m_macList ) ;
 //    LSetCell(text, strlen(text), cell, m_macList);
     Refresh();
 }
@@ -649,15 +649,15 @@ void wxListBox::MacInsert( int n , const char * text)
 void wxListBox::MacAppend( const char * text) 
 {
     Cell cell = { 0 , 0 } ;
-    cell.v = (**m_macList).dataBounds.bottom ;
-    LAddRow( 1 , cell.v , m_macList ) ;
+    cell.v = (**(ListHandle)m_macList).dataBounds.bottom ;
+    LAddRow( 1 , cell.v , (ListHandle)m_macList ) ;
  //   LSetCell(text, strlen(text), cell, m_macList);
     Refresh();
 }
 
 void wxListBox::MacClear() 
 {
-    LDelRow( (**m_macList).dataBounds.bottom , 0 , m_macList ) ;
+    LDelRow( (**(ListHandle)m_macList).dataBounds.bottom , 0 ,(ListHandle) m_macList ) ;
     Refresh();
 }
 
@@ -666,15 +666,15 @@ void wxListBox::MacSetSelection( int n , bool select )
     Cell cell = { 0 , 0 } ;
     if ( ! (m_windowStyle & wxLB_MULTIPLE) )
     {
-    if ( LGetSelect( true , &cell , m_macList ) )
+    if ( LGetSelect( true , &cell , (ListHandle)m_macList ) )
     {
-        LSetSelect( false , cell , m_macList ) ;
+        LSetSelect( false , cell , (ListHandle)m_macList ) ;
     }
     }
     
     cell.v = n ;
-    LSetSelect( select , cell , m_macList ) ;
-    LAutoScroll( m_macList ) ;
+    LSetSelect( select , cell , (ListHandle)m_macList ) ;
+    LAutoScroll( (ListHandle)m_macList ) ;
     Refresh();
 }
 
@@ -682,7 +682,7 @@ bool wxListBox::MacIsSelected( int n ) const
 {
     Cell cell = { 0 , 0 } ;
     cell.v = n ;
-    return LGetSelect( false , &cell , m_macList ) ;
+    return LGetSelect( false , &cell , (ListHandle)m_macList ) ;
 }
 
 void wxListBox::MacDestroy()
@@ -693,7 +693,7 @@ void wxListBox::MacDestroy()
 int wxListBox::MacGetSelection() const
 {
     Cell cell = { 0 , 0 } ;
-    if ( LGetSelect( true , &cell , m_macList ) )
+    if ( LGetSelect( true , &cell , (ListHandle)m_macList ) )
         return cell.v ;
     else
         return -1 ;
@@ -708,7 +708,7 @@ int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
     Cell cell = { 0 , 0 } ;
     cell.v = 0 ;
     
-    while ( LGetSelect( true , &cell , m_macList ) )
+    while ( LGetSelect( true , &cell ,(ListHandle) m_macList ) )
     {
         aSelections.Add( cell.v ) ;
         no_sel++ ;
@@ -739,18 +739,18 @@ void wxListBox::OnSize( const wxSizeEvent &event)
 #if TARGET_CARBON
     GetListCellSize(m_macList, &pt);
 #else
-    pt = (**m_macList).cellSize ;
+    pt = (**(ListHandle)m_macList).cellSize ;
 #endif
     pt.h =  m_width - 15  ;
-    LCellSize( pt , m_macList ) ;
+    LCellSize( pt , (ListHandle)m_macList ) ;
 }
 
-void wxListBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
     Boolean wasDoubleClick = false ;
     long    result ;
 
-    ::GetControlData( m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick  , &result ) ;
+    ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick  , &result ) ;
     if ( !wasDoubleClick )
     {
         MacDoClick() ;
@@ -763,7 +763,7 @@ void wxListBox::MacHandleControlClick( ControlHandle control , SInt16 controlpar
 
 void wxListBox::MacSetRedraw( bool doDraw ) 
 {
-    LSetDrawingMode( doDraw , m_macList ) ;
+    LSetDrawingMode( doDraw , (ListHandle)m_macList ) ;
     
 }
 
diff --git a/src/mac/macnotfy.cpp b/src/mac/macnotfy.cpp
index a47fce31e5..9d0a2a8346 100644
--- a/src/mac/macnotfy.cpp
+++ b/src/mac/macnotfy.cpp
@@ -8,6 +8,9 @@
  */
 
 #include "wx/wx.h"
+
+#include "wx/mac/private.h"
+
 #include "wx/mac/macnotfy.h"
 
 const short kMaxEvents = 1000 ;
@@ -74,6 +77,7 @@ void wxMacAddEvent(
 	short wakeUp ) 
 {
 	wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
+	wxASSERT_MSG( handler != NULL , "illegal notification proc ptr" ) ;
 	/* this should be protected eventually */
 	short index = e->top++ ;
 	
@@ -125,7 +129,8 @@ void wxMacProcessNotifierEvents()
 	gMacNotificationEvents.events[index] = NULL ;
 	gMacNotificationEvents.proc[index]  = NULL ;
     
-	handler( event , data  ) ;
+    if ( handler )
+	    handler( event , data  ) ;
   }
   gInProcessing = false ;
 }
diff --git a/src/mac/mdi.cpp b/src/mac/mdi.cpp
index b41f8735e8..6f7ff1e805 100644
--- a/src/mac/mdi.cpp
+++ b/src/mac/mdi.cpp
@@ -17,6 +17,8 @@
 #include "wx/menu.h"
 #include "wx/settings.h"
 
+#include "wx/mac/private.h"
+
 extern wxWindowList wxModelessWindows;
 
 #if !USE_SHARED_LIBRARY
diff --git a/src/mac/menu.cpp b/src/mac/menu.cpp
index df302f9e69..17e8679a5b 100644
--- a/src/mac/menu.cpp
+++ b/src/mac/menu.cpp
@@ -88,8 +88,8 @@ void wxMenu::Init()
 
 wxMenu::~wxMenu()
 {
-	if (m_hMenu)
-		::DisposeMenu(m_hMenu);
+	if (MAC_WXHMENU(m_hMenu))
+		::DisposeMenu(MAC_WXHMENU(m_hMenu));
 
 #if wxUSE_ACCEL
     // delete accels
@@ -164,11 +164,11 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
 	{
 		if ( pos == (size_t)-1 )
 		{
-			MacAppendMenu(m_hMenu, "\p-");
+			MacAppendMenu(MAC_WXHMENU(m_hMenu), "\p-");
 		}
 		else
 		{
-			MacInsertMenuItem(m_hMenu, "\p-" , pos);
+			MacInsertMenuItem(MAC_WXHMENU(m_hMenu), "\p-" , pos);
 		}
 	}
 	else 
@@ -183,16 +183,16 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
 		
 			if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar) 
 			{
-				::InsertMenu( pSubMenu->m_hMenu , -1 ) ;
+				::InsertMenu( MAC_WXHMENU( pSubMenu->m_hMenu ) , -1 ) ;
 			}
 			
 			if ( pos == (size_t)-1 )
 			{
-				UMAAppendSubMenuItem(m_hMenu, label, pSubMenu->m_macMenuId);
+				UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu), label, pSubMenu->m_macMenuId);
 			}
 			else
 			{
-				UMAInsertSubMenuItem(m_hMenu, label , pos, pSubMenu->m_macMenuId);
+				UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), label , pos, pSubMenu->m_macMenuId);
 			}
 		}
 		else
@@ -209,21 +209,21 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
 			}
 			if ( pos == (size_t)-1 )
 			{
-				UMAAppendMenuItem(m_hMenu, label,key,modifiers);
+				UMAAppendMenuItem(MAC_WXHMENU(m_hMenu), label,key,modifiers);
 			}
 			else
 			{
-				UMAInsertMenuItem(m_hMenu, label , pos,key,modifiers);
+				UMAInsertMenuItem(MAC_WXHMENU(m_hMenu), label , pos,key,modifiers);
 			}
   			if ( pItem->GetId() == idMenuTitle ) 
   			{
   				if ( pos == (size_t)-1 )
 				{
-					UMADisableMenuItem( m_hMenu , CountMenuItems( m_hMenu ) ) ;
+					UMADisableMenuItem(MAC_WXHMENU(m_hMenu) , CountMenuItems(MAC_WXHMENU(m_hMenu) ) ) ;
 				}
 				else
 				{
-					UMADisableMenuItem( m_hMenu , pos + 1 ) ;
+					UMADisableMenuItem(MAC_WXHMENU(m_hMenu) , pos + 1 ) ;
 				}
   			}
 		}
@@ -274,7 +274,7 @@ wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
     //else: this item doesn't have an accel, nothing to do
 #endif // wxUSE_ACCEL
 
-	::DeleteMenuItem( m_hMenu , pos + 1);
+	::DeleteMenuItem(MAC_WXHMENU(m_hMenu) , pos + 1);
 
     if ( IsAttached() )
     {
@@ -312,7 +312,7 @@ void wxMenu::SetTitle(const wxString& label)
 	Str255 title ;
     m_title = label ;
 	wxMenuItem::MacBuildMenuString( title, NULL , NULL , label , false );
-	UMASetMenuTitle( m_hMenu , title ) ;
+	UMASetMenuTitle(MAC_WXHMENU(m_hMenu) , title ) ;
 }
 bool wxMenu::ProcessCommand(wxCommandEvent & event)
 {
@@ -399,9 +399,9 @@ int wxMenu::MacGetIndexFromItem( wxMenuItem *pItem )
 void wxMenu::MacEnableMenu( bool bDoEnable ) 
 {
 	if ( bDoEnable )
-		UMAEnableMenuItem( m_hMenu , 0 ) ;
+		UMAEnableMenuItem(MAC_WXHMENU(m_hMenu) , 0 ) ;
 	else
-		UMADisableMenuItem( m_hMenu , 0 ) ;
+		UMADisableMenuItem(MAC_WXHMENU(m_hMenu) , 0 ) ;
 		
 	::DrawMenuBar() ;
 }
@@ -691,7 +691,7 @@ void wxMenuBar::MacInstallMenuBar()
 			else
 			{
 				wxMenuItem::MacBuildMenuString( label, NULL , NULL , m_titles[i] , false );
-				UMASetMenuTitle( menu->GetHMenu() , label ) ;
+				UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , label ) ;
 					wxArrayPtrVoid submenus ;
 					
 		  		for (pos = 0, node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) 
@@ -703,7 +703,7 @@ void wxMenuBar::MacInstallMenuBar()
   					  submenus.Add(subMenu) ;
 					}
 				}
-				::InsertMenu(m_menus[i]->GetHMenu(), 0);
+				::InsertMenu(MAC_WXHMENU(m_menus[i]->GetHMenu()), 0);
 				for ( int i = 0 ; i < submenus.GetCount() ; ++i )
 				{
 				  wxMenu* submenu = (wxMenu*) submenus[i] ;
@@ -719,7 +719,7 @@ void wxMenuBar::MacInstallMenuBar()
   						submenus.Add(itsSubMenu) ;
   					}  				
   				}
-					::InsertMenu( submenu->GetHMenu() , -1 ) ;
+					::InsertMenu( MAC_WXHMENU(submenu->GetHMenu()) , -1 ) ;
   			}
 			}
 		}
@@ -802,14 +802,14 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
 			{
 				Str255 	label;
 				wxMenuItem::MacBuildMenuString( label, NULL , NULL , title , false );
-				UMASetMenuTitle( menu->GetHMenu() , label ) ;
+				UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , label ) ;
 				if ( pos == m_menus.GetCount() - 1)
 				{
-					::InsertMenu( menu->GetHMenu() , 0 ) ;
+					::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
 				}
 				else
 				{
-					::InsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ;
+					::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , m_menus[pos+1]->MacGetMenuId() ) ;
 				}
 			}
 		}
@@ -842,11 +842,11 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
     {
     	if ( pos == (size_t) -1 )
 		{
-			::InsertMenu( menu->GetHMenu() , 0 ) ;
+			::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
 		}
 		else
 		{
-			::InsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ;
+			::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , m_menus[pos+1]->MacGetMenuId() ) ;
 		}
 
 #if wxUSE_ACCEL
@@ -951,7 +951,7 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
     {
 		if (s_macInstalledMenuBar == this)
 		{
-			::InsertMenu( menu->GetHMenu() , 0 ) ;
+			::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
 		}
 
 #if wxUSE_ACCEL
diff --git a/src/mac/menuitem.cpp b/src/mac/menuitem.cpp
index 33b337518e..52e68bfdad 100644
--- a/src/mac/menuitem.cpp
+++ b/src/mac/menuitem.cpp
@@ -249,30 +249,30 @@ void wxMenuItem::Enable(bool bDoEnable)
     if ( m_subMenu == NULL ) 
     {     
     	// normal menu item
-	    if ( m_parentMenu->GetHMenu() )
+	    if ( MAC_WXHMENU(m_parentMenu->GetHMenu()) )
 	    {
 	   	 	int index = m_parentMenu->MacGetIndexFromItem( this ) ;
 	   	 	if ( index >= 1 )
 	   	 	{
 	   	 		if ( bDoEnable )
-	   	 			UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
+	   	 			UMAEnableMenuItem( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index ) ;
 	   	 		else
-	   	 			UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
+	   	 			UMADisableMenuItem( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index ) ;
 	   	 	}
 	    }
     }
     else                            
     {
   		// submenu
-	    if ( m_parentMenu->GetHMenu() )
+	    if ( MAC_WXHMENU(m_parentMenu->GetHMenu()) )
 	    {
 	   	 	int index = m_parentMenu->MacGetIndexFromItem( this ) ;
 	   	 	if ( index >= 1 )
 	   	 	{
 	   	 		if ( bDoEnable )
-	   	 			UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
+	   	 			UMAEnableMenuItem( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index ) ;
 	   	 		else
-	   	 			UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
+	   	 			UMADisableMenuItem( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index ) ;
 	   	 	}
 	    }
     }
@@ -288,15 +288,15 @@ void wxMenuItem::Check(bool bDoCheck)
   if ( m_isChecked != bDoCheck ) 
   {
     m_isChecked = bDoCheck;
-   	if ( m_parentMenu->GetHMenu() )
+   	if ( MAC_WXHMENU(m_parentMenu->GetHMenu()) )
     {
    	 	int index = m_parentMenu->MacGetIndexFromItem( this ) ;
    	 	if ( index >= 1 )
    	 	{
    	 		if ( bDoCheck )
-					::SetItemMark( m_parentMenu->GetHMenu() , index , 0x12 ) ; // checkmark
+					::SetItemMark( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index , 0x12 ) ; // checkmark
 				else
- 					::SetItemMark( m_parentMenu->GetHMenu() , index , 0 ) ; // no mark
+ 					::SetItemMark( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index , 0 ) ; // no mark
   	 	}
   	}
   }
@@ -312,14 +312,14 @@ void wxMenuItem::SetText(const wxString& text)
 //    OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
 
     wxCHECK_RET( m_parentMenu && m_parentMenu->GetHMenu(), wxT("menuitem without menu") );
-   	if ( m_parentMenu->GetHMenu() )
+   	if ( MAC_WXHMENU(m_parentMenu->GetHMenu()) )
     {
    	 	int index = m_parentMenu->MacGetIndexFromItem( this ) ;
    	 	if ( index >= 1 )
    	 	{
  			Str255 label;
 			MacBuildMenuString( label , NULL , NULL , text ,false);
-   	 		::SetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark
+   	 		::SetMenuItemText( MAC_WXHMENU(m_parentMenu->GetHMenu()) , index , label ) ; // checkmark
   	 	}
   	}
 
diff --git a/src/mac/metafile.cpp b/src/mac/metafile.cpp
index 9bdbb223fb..2380c96edc 100644
--- a/src/mac/metafile.cpp
+++ b/src/mac/metafile.cpp
@@ -34,6 +34,8 @@
 #include "wx/metafile.h"
 #include "wx/clipbrd.h"
 
+#include "wx/mac/private.h"
+
 #include <stdio.h>
 #include <string.h>
 
@@ -59,7 +61,7 @@ wxMetafileRefData::~wxMetafileRefData(void)
 {
     if (m_metafile)
     {
-		KillPicture( m_metafile ) ;
+		KillPicture( (PicHandle) m_metafile ) ;
         m_metafile = 0;
     }
 }
@@ -104,7 +106,7 @@ bool wxMetaFile::SetClipboard(int width, int height)
     return TRUE ;
 }
 
-void wxMetafile::SetHMETAFILE(PicHandle mf)
+void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
 {
     if (!m_refData)
         m_refData = new wxMetafileRefData;
@@ -122,7 +124,7 @@ bool wxMetaFile::Play(wxDC *dc)
 		
 	{
 		wxMacPortSetter helper( dc ) ;
-		PicHandle pict = GetHMETAFILE() ;
+		PicHandle pict = (PicHandle) GetHMETAFILE() ;
 		DrawPicture( pict , &(**pict).picFrame ) ;
 	}
     return TRUE;
@@ -149,7 +151,7 @@ wxMetaFileDC::wxMetaFileDC(const wxString& file)
   Rect r={0,0,1000,1000} ;
 	
   m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
-  ::GetPort( &m_macPort ) ;	
+  ::GetPort( (GrafPtr*) &m_macPort ) ;	
   m_ok = TRUE ;
 
   SetMapMode(wxMM_TEXT); 
@@ -171,7 +173,7 @@ wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, i
 	Rect r={yorg,xorg,yorg+yext,xorg+xext} ;
 	
 	m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
-	::GetPort( &m_macPort ) ;	
+	::GetPort( (GrafPtr*) &m_macPort ) ;	
   m_ok = TRUE ;
 
   SetMapMode(wxMM_TEXT); 
@@ -195,7 +197,7 @@ size_t wxMetafileDataObject::GetDataSize() const
 
 bool wxMetafileDataObject::GetDataHere(void *buf) const
 {
-  memcpy( buf , (*(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
+  memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
     GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
   return true ;
 }
diff --git a/src/mac/notebmac.cpp b/src/mac/notebmac.cpp
index 9edaae2764..aa5351acc5 100644
--- a/src/mac/notebmac.cpp
+++ b/src/mac/notebmac.cpp
@@ -130,7 +130,7 @@ bool wxNotebook::Create(wxWindow *parent,
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlTabSmallProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
@@ -168,7 +168,7 @@ int wxNotebook::SetSelection(int nPage)
     return m_nSelection ;
 
     ChangePage(m_nSelection, nPage);
-	SetControlValue( m_macControl , m_nSelection + 1 ) ;
+	SetControlValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ;
 
     return m_nSelection;
 }
@@ -291,7 +291,7 @@ bool wxNotebook::InsertPage(int nPage,
  */
 void wxNotebook::MacSetupTabs()
 {
-    SetControlMaximum( m_macControl , GetPageCount() ) ;
+    SetControlMaximum( (ControlHandle) m_macControl , GetPageCount() ) ;
 
     wxNotebookPage *page;
     ControlTabInfoRec info;
@@ -307,14 +307,14 @@ void wxNotebook::MacSetupTabs()
 		strcpy( (char *) info.name , page->GetLabel() ) ;
 		c2pstr( (char *) info.name ) ;
 #endif
-        SetControlData( m_macControl, ii+1, kControlTabInfoTag,
+        SetControlData( (ControlHandle) m_macControl, ii+1, kControlTabInfoTag,
                         sizeof( ControlTabInfoRec) , (char*) &info ) ;
-        SetControlData( m_macControl, ii+1, kControlTabEnabledFlagTag,
+        SetControlData( (ControlHandle) m_macControl, ii+1, kControlTabEnabledFlagTag,
                         sizeof( Boolean ), (Ptr)&enabled );
     }
     Rect bounds;
-    GetControlBounds(m_macControl, &bounds);
-    InvalWindowRect(MacGetRootWindow(), &bounds);
+    GetControlBounds((ControlHandle)m_macControl, &bounds);
+    InvalWindowRect((WindowRef)MacGetRootWindow(), &bounds);
 }
 
 // ----------------------------------------------------------------------------
@@ -436,9 +436,9 @@ void wxNotebook::ChangePage(int nOldSel, int nSel)
     m_nSelection = nSel;
 }
 
-void wxNotebook::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxNotebook::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
-  wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControlValue(m_macControl) - 1, m_nSelection);
+  wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControlValue((ControlHandle)m_macControl) - 1, m_nSelection);
   event.SetEventObject(this);
 
   ProcessEvent(event);
diff --git a/src/mac/printdlg.cpp b/src/mac/printdlg.cpp
index ffe0ba15ba..38c128ac21 100644
--- a/src/mac/printdlg.cpp
+++ b/src/mac/printdlg.cpp
@@ -76,7 +76,7 @@ int wxPrintDialog::ShowModal()
 	if ( err == noErr )
 	{
 		m_printDialogData.ConvertToNative() ;
-		if  ( ::PrJobDialog( m_printDialogData.GetPrintData().m_macPrintInfo ) )
+		if  ( ::PrJobDialog( (THPrint) m_printDialogData.GetPrintData().m_macPrintInfo ) )
 		{
 			m_printDialogData.ConvertFromNative() ;
 			result = wxID_OK ;
@@ -228,7 +228,7 @@ int wxPageSetupDialog::ShowModal()
 	if ( err == noErr )
 	{
 		m_pageSetupData.ConvertToNative() ;
-		if  ( ::PrStlDialog( m_pageSetupData.GetPrintData().m_macPrintInfo ) )
+		if  ( ::PrStlDialog(  (THPrint) m_pageSetupData.GetPrintData().m_macPrintInfo ) )
 		{
 			m_pageSetupData.ConvertFromNative() ;
 			result = wxID_OK ;
diff --git a/src/mac/printmac.cpp b/src/mac/printmac.cpp
index 426bd42de3..33506c4548 100644
--- a/src/mac/printmac.cpp
+++ b/src/mac/printmac.cpp
@@ -29,6 +29,8 @@
 #include "wx/msgdlg.h"
 #endif
 
+#include "wx/mac/private.h"
+
 #include "wx/mac/printmac.h"
 #include "wx/dcprint.h"
 #include "wx/printdlg.h"
diff --git a/src/mac/radiobox.cpp b/src/mac/radiobox.cpp
index e3d5abd2a6..1ec40d88cf 100644
--- a/src/mac/radiobox.cpp
+++ b/src/mac/radiobox.cpp
@@ -117,7 +117,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
 	
 	MacPreControlCreate( parent , id ,  label , pos , size ,style, val , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlGroupBoxTextTitleProc , (long) this ) ;
 	
     for (i = 0; i < n; i++)
diff --git a/src/mac/radiobut.cpp b/src/mac/radiobut.cpp
index 6421f60596..0d060bdb95 100644
--- a/src/mac/radiobut.cpp
+++ b/src/mac/radiobut.cpp
@@ -35,7 +35,7 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
 	
 	MacPreControlCreate( parent , id ,  label , pos , size ,style, validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlRadioButtonProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
@@ -70,10 +70,10 @@ void wxRadioButton::SetValue(bool val)
 {
 	int i;
 	wxRadioButton *cycle;
-	  if ( GetControlValue( m_macControl ) == val )
+	  if ( GetControlValue( (ControlHandle) m_macControl ) == val )
 	    return ;
 	    
-   ::SetControlValue( m_macControl , val ) ;
+   ::SetControlValue( (ControlHandle) m_macControl , val ) ;
    if (val) 
    {
    		cycle=this->NextInCycle();
@@ -89,7 +89,7 @@ void wxRadioButton::SetValue(bool val)
 
 bool wxRadioButton::GetValue() const
 {
-    return ::GetControlValue( m_macControl ) ;
+    return ::GetControlValue( (ControlHandle) m_macControl ) ;
 }
 
 void wxRadioButton::Command (wxCommandEvent & event)
@@ -98,7 +98,7 @@ void wxRadioButton::Command (wxCommandEvent & event)
   ProcessCommand (event);
 }
 
-void wxRadioButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxRadioButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
     if ( GetValue() )
       return ;
diff --git a/src/mac/region.cpp b/src/mac/region.cpp
index 315b966927..a0204caad5 100644
--- a/src/mac/region.cpp
+++ b/src/mac/region.cpp
@@ -63,25 +63,25 @@ wxRegion::wxRegion()
 wxRegion::wxRegion(WXHRGN hRegion )
 {
     m_refData = new wxRegionRefData;
-    CopyRgn( hRegion , M_REGION ) ;
+    CopyRgn( (RgnHandle) hRegion , (RgnHandle) M_REGION ) ;
 }
 
 wxRegion::wxRegion(long x, long y, long w, long h)
 {
     m_refData = new wxRegionRefData;
-    SetRectRgn( M_REGION , x , y , x+w , y+h ) ;
+    SetRectRgn( (RgnHandle) M_REGION , x , y , x+w , y+h ) ;
 }
 
 wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight)
 {
     m_refData = new wxRegionRefData;
-    SetRectRgn( M_REGION , topLeft.x , topLeft.y , bottomRight.x , bottomRight.y ) ;
+    SetRectRgn( (RgnHandle) M_REGION , topLeft.x , topLeft.y , bottomRight.x , bottomRight.y ) ;
 }
 
 wxRegion::wxRegion(const wxRect& rect)
 {
     m_refData = new wxRegionRefData;
-    SetRectRgn( M_REGION , rect.x , rect.y , rect.x+rect.width , rect.y+rect.height ) ;
+    SetRectRgn( (RgnHandle) M_REGION , rect.x , rect.y , rect.x+rect.width , rect.y+rect.height ) ;
 }
 
 /*!
diff --git a/src/mac/scrolbar.cpp b/src/mac/scrolbar.cpp
index 51c01e4cef..07fb9476df 100644
--- a/src/mac/scrolbar.cpp
+++ b/src/mac/scrolbar.cpp
@@ -43,12 +43,12 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style, validator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , true , 0 , 0 , 100, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , true , 0 , 0 , 100, 
 		kControlScrollBarLiveProc , (long) this ) ;
 	
-	wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+	wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
 
-	::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ;
+	::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ;
 
 	MacPostControlCreate() ;
 
@@ -61,12 +61,12 @@ wxScrollBar::~wxScrollBar()
 
 void wxScrollBar::SetThumbPosition(int viewStart)
 {
-    ::SetControlValue( m_macControl , viewStart ) ;
+    ::SetControlValue( (ControlHandle) m_macControl , viewStart ) ;
 }
 
 int wxScrollBar::GetThumbPosition() const
 {
-    return ::GetControlValue( m_macControl ) ;
+    return ::GetControlValue( (ControlHandle) m_macControl ) ;
 }
 
 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
@@ -78,15 +78,15 @@ void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageS
 
   	int range1 = wxMax((m_objectSize - m_pageSize), 0) ;
 
-    SetControlMaximum( m_macControl , range1 ) ;
-    SetControlMinimum(  m_macControl , 0 ) ;
-    SetControlValue(  m_macControl , position ) ;
+    SetControlMaximum( (ControlHandle) m_macControl , range1 ) ;
+    SetControlMinimum( (ControlHandle) m_macControl , 0 ) ;
+    SetControlValue( (ControlHandle) m_macControl , position ) ;
 
     if ( UMAGetAppearanceVersion() >= 0x0110  )
     {
         if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
         {
-			SetControlViewSize( m_macControl , m_pageSize ) ;
+			SetControlViewSize( (ControlHandle) m_macControl , m_pageSize ) ;
         }
     }
     Refresh() ;
@@ -99,14 +99,14 @@ void wxScrollBar::Command(wxCommandEvent& event)
     ProcessCommand(event);
 }
 
-void wxScrollBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
-	if ( m_macControl == NULL )
+	if ( (ControlHandle) m_macControl == NULL )
 		return ;
 	
-  int position = GetControlValue( m_macControl) ;
-  int minPos = GetControlMinimum( m_macControl) ;
-  int maxPos = GetControlMaximum( m_macControl) ;
+  int position = GetControlValue( (ControlHandle) m_macControl) ;
+  int minPos = GetControlMinimum( (ControlHandle) m_macControl) ;
+  int maxPos = GetControlMaximum( (ControlHandle) m_macControl) ;
 
   wxEventType scrollEvent = wxEVT_NULL;
   int nScrollInc;
diff --git a/src/mac/settings.cpp b/src/mac/settings.cpp
index 92d586c90c..8c7591cfdb 100644
--- a/src/mac/settings.cpp
+++ b/src/mac/settings.cpp
@@ -17,6 +17,8 @@
 #include "wx/gdicmn.h"
 #include "wx/utils.h"
 
+#include "wx/mac/uma.h"
+
 // ----------------------------------------------------------------------------
 // wxSystemSettingsNative
 // ----------------------------------------------------------------------------
diff --git a/src/mac/slider.cpp b/src/mac/slider.cpp
index 2f8854acc2..f76b09fc68 100644
--- a/src/mac/slider.cpp
+++ b/src/mac/slider.cpp
@@ -84,12 +84,12 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
     }
   
 
-     m_macControl = ::NewControl( parent->MacGetRootWindow(), &bounds, title, false,
+     m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()), &bounds, title, false,
                                    value, minValue, maxValue, procID, (long) this);
  
-     wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+     wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
  
-     ::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ;
+     ::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ;
  
      if(style & wxSL_LABELS)
      {
@@ -127,7 +127,7 @@ wxSlider::~wxSlider()
 
 int wxSlider::GetValue() const
 {
- 	return GetControlValue( m_macControl) ;
+ 	return GetControlValue( (ControlHandle) m_macControl) ;
 }
 
 void wxSlider::SetValue(int value)
@@ -136,7 +136,7 @@ void wxSlider::SetValue(int value)
 	valuestring.Printf( "%d" , value ) ;	
 	if ( m_macValueStatic )
 		m_macValueStatic->SetLabel( valuestring ) ;
- 	SetControlValue( m_macControl , value ) ;
+ 	SetControlValue( (ControlHandle) m_macControl , value ) ;
 }
 
 void wxSlider::SetRange(int minValue, int maxValue)
@@ -146,8 +146,8 @@ void wxSlider::SetRange(int minValue, int maxValue)
   m_rangeMin = minValue;
   m_rangeMax = maxValue;
 
-  SetControlMinimum(m_macControl, m_rangeMin);
-  SetControlMaximum(m_macControl, m_rangeMax);
+  SetControlMinimum( (ControlHandle) m_macControl, m_rangeMin);
+  SetControlMaximum( (ControlHandle) m_macControl, m_rangeMax);
   
   if(m_macMinimumStatic) {
     value.Printf("%d", m_rangeMin);
@@ -239,9 +239,9 @@ void wxSlider::Command (wxCommandEvent & event)
   ProcessCommand (event);
 }
 
-void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxSlider::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
-	SInt16 value = ::GetControlValue( m_macControl ) ;
+	SInt16 value = ::GetControlValue( (ControlHandle) m_macControl ) ;
 	
 	SetValue( value ) ;		
 	
@@ -372,7 +372,7 @@ void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart
          GetParent()->MacClientToRootWindow(&mac_x, &mac_y);
      }
  
-     GetControlBounds(m_macControl, &oldbounds);
+     GetControlBounds( (ControlHandle) m_macControl, &oldbounds);
      oldbounds.right = oldbounds.left + m_width;
      oldbounds.bottom = oldbounds.top + m_height;
  
@@ -408,7 +408,7 @@ void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart
  
          // Update window at old and new positions
          SetRect(&newbounds, m_x, m_y, m_x + m_width, m_y + m_height);
-         WindowRef rootwindow = MacGetRootWindow();
+         WindowRef rootwindow = (WindowRef) MacGetRootWindow();
          InvalWindowRect( rootwindow , &oldbounds );
          InvalWindowRect( rootwindow , &newbounds );
  
@@ -485,6 +485,6 @@ void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart
      if(GetParent()) {
          GetParent()->MacClientToRootWindow(&x, &y);
      }
-     UMAMoveControl(m_macControl, x, y);
-     UMASizeControl(m_macControl, width - xborder, height - yborder);
+     UMAMoveControl( (ControlHandle) m_macControl, x, y);
+     UMASizeControl( (ControlHandle) m_macControl, width - xborder, height - yborder);
 }
\ No newline at end of file
diff --git a/src/mac/spinbutt.cpp b/src/mac/spinbutt.cpp
index 87db4b041a..e3beab7322 100644
--- a/src/mac/spinbutt.cpp
+++ b/src/mac/spinbutt.cpp
@@ -49,10 +49,10 @@ bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, c
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 100, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100, 
 		kControlLittleArrowsProc , (long) this ) ;
 	
-	wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+	wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
 
 	MacPostControlCreate() ;
 
@@ -90,13 +90,13 @@ void wxSpinButton::SetRange(int minVal, int maxVal)
 {
 	m_min = minVal;
 	m_max = maxVal;
-    SetControlMaximum( m_macControl , maxVal ) ;
-    SetControlMinimum(  m_macControl , minVal ) ;
+    SetControlMaximum( (ControlHandle) m_macControl , maxVal ) ;
+    SetControlMinimum((ControlHandle) m_macControl , minVal ) ;
 }
 
-void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
-	if ( m_macControl == NULL )
+	if ( (ControlHandle) m_macControl == NULL )
 		return ;
 	
 	int oldValue = m_value ;
@@ -142,7 +142,7 @@ void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 control
   {
   	m_value = oldValue ;
   }
-  SetControlValue(  m_macControl , m_value ) ;
+  SetControlValue( (ControlHandle) m_macControl , m_value ) ;
 
     /* always send a thumbtrack event */
     if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
diff --git a/src/mac/statbox.cpp b/src/mac/statbox.cpp
index 1a562c12e6..529c720da3 100644
--- a/src/mac/statbox.cpp
+++ b/src/mac/statbox.cpp
@@ -43,7 +43,7 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
 	
 	MacPreControlCreate( parent , id ,  label , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlGroupBoxTextTitleProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
diff --git a/src/mac/statbrma.cpp b/src/mac/statbrma.cpp
index f0d2b9bfa4..139b505f8e 100644
--- a/src/mac/statbrma.cpp
+++ b/src/mac/statbrma.cpp
@@ -25,6 +25,10 @@ BEGIN_EVENT_TABLE(wxStatusBarMac, wxStatusBarGeneric)
 	EVT_PAINT(wxStatusBarMac::OnPaint)
 END_EVENT_TABLE()
 
+#ifdef __WXMAC__
+#include "wx/mac/private.h"
+#endif
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -56,7 +60,7 @@ void wxStatusBarMac::DrawFieldText(wxDC& dc, int i)
   wxRect rect;
   GetFieldRect(i, rect);
   
-  if ( !IsWindowHilited( MacGetRootWindow() ) )
+  if ( !IsWindowHilited( MAC_WXHWND( MacGetRootWindow() ) ) )
   {
     dc.SetTextForeground( wxColour( 0x80 , 0x80 , 0x80 ) ) ;
   }
@@ -107,7 +111,7 @@ void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event) )
 {
   	wxPaintDC dc(this);
   	
-  if ( IsWindowHilited( MacGetRootWindow() ) )
+  if ( IsWindowHilited( MAC_WXHWND( MacGetRootWindow() ) ) )
   {
   	wxPen black( wxBLACK , 1 , wxSOLID ) ;
 	wxPen white( wxWHITE , 1 , wxSOLID ) ;
diff --git a/src/mac/statlmac.cpp b/src/mac/statlmac.cpp
index 0272ed706e..2c01893e84 100644
--- a/src/mac/statlmac.cpp
+++ b/src/mac/statlmac.cpp
@@ -54,7 +54,7 @@ bool wxStaticLine::Create( wxWindow *parent,
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlSeparatorLineProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
diff --git a/src/mac/stattext.cpp b/src/mac/stattext.cpp
index f4e52d8d04..3b2476af40 100644
--- a/src/mac/stattext.cpp
+++ b/src/mac/stattext.cpp
@@ -129,7 +129,7 @@ void wxStaticText::OnDraw( wxDC &dc )
     if (m_width <= 0 || m_height <= 0)
         return;
 
-  if ( !IsWindowHilited( MacGetRootWindow() ) && 
+  if ( !IsWindowHilited( (WindowRef) MacGetRootWindow() ) && 
     ( GetBackgroundColour() == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) 
       || GetBackgroundColour() == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) )
   {
diff --git a/src/mac/tabctrl.cpp b/src/mac/tabctrl.cpp
index 9231ea3d41..db1992be6e 100644
--- a/src/mac/tabctrl.cpp
+++ b/src/mac/tabctrl.cpp
@@ -41,7 +41,7 @@ bool wxTabCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons
 	
 	MacPreControlCreate( parent , id ,  "" , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ;
 
-	m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1, 
+	m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, 
 	  	kControlTabSmallProc , (long) this ) ;
 	
 	MacPostControlCreate() ;
diff --git a/src/mac/textctrl.cpp b/src/mac/textctrl.cpp
index 64d585d233..ce7177ffec 100644
--- a/src/mac/textctrl.cpp
+++ b/src/mac/textctrl.cpp
@@ -124,7 +124,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
     }
 
 
-    m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, 
+    m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , true , 0 , 0 , 1, 
         ( style & wxTE_PASSWORD ) ? kControlEditTextPasswordProc : kControlEditTextProc , (long) this ) ;
     MacPostControlCreate() ;
 
@@ -134,7 +134,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         TEHandle teH ;
         long size ;
    
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
         (*teH)->lineHeight = -1 ;
     }
     
@@ -142,7 +142,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         value = wxMacMakeMacStringFromPC( st ) ;
     else
         value = st ;
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
 
   return TRUE;
 }
@@ -150,7 +150,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
 wxString wxTextCtrl::GetValue() const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     wxBuffer[actualsize] = 0 ;
     if( wxApp::s_macDefaultEncodingIsPC )
         return wxMacMakePCStringFromMac( wxBuffer ) ;
@@ -164,7 +164,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
 
     *from = (**teH).selStart;
     *to = (**teH).selEnd;
@@ -178,7 +178,7 @@ void wxTextCtrl::SetValue(const wxString& st)
         value = wxMacMakeMacStringFromPC( st ) ;
     else
         value = st ;
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
     MacRedrawControl() ;
 }
 
@@ -190,7 +190,7 @@ void wxTextCtrl::Copy()
         TEHandle teH ;
         long size ;
    
-  		  ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+  		  ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
 		    TECopy( teH ) ;
         ClearCurrentScrap();
 		    TEToScrap() ;
@@ -204,7 +204,7 @@ void wxTextCtrl::Cut()
         TEHandle teH ;
         long size ;
    
-   		  ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   		  ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
 		    TECut( teH ) ;
         ClearCurrentScrap();
 		    TEToScrap() ;
@@ -219,7 +219,7 @@ void wxTextCtrl::Paste()
         TEHandle teH ;
         long size ;
    
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
         TEFromScrap() ;
         TEPaste( teH ) ;
         MacRedrawControl() ;
@@ -280,9 +280,9 @@ bool wxTextCtrl::CanPaste() const
 void wxTextCtrl::SetEditable(bool editable)
 {
     if ( editable )
-        UMAActivateControl( m_macControl ) ;
+        UMAActivateControl( (ControlHandle) m_macControl ) ;
     else
-        UMADeactivateControl( m_macControl ) ;
+        UMADeactivateControl( (ControlHandle) m_macControl ) ;
 }
 
 void wxTextCtrl::SetInsertionPoint(long pos)
@@ -302,8 +302,8 @@ long wxTextCtrl::GetInsertionPoint() const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-//   ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+//   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
     return (**teH).selStart ;
 }
 
@@ -313,9 +313,9 @@ long wxTextCtrl::GetLastPosition() const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
-//   ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
+//   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
     return (**teH).teLength ;
 }
 
@@ -328,8 +328,8 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
    
     selection.selStart = from ;
     selection.selEnd = to ;
-    ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     TESetSelect( from , to  , teH ) ;
     TEDelete( teH ) ;
         TEInsert( value , value.Length() , teH ) ;
@@ -345,8 +345,8 @@ void wxTextCtrl::Remove(long from, long to)
    
     selection.selStart = from ;
     selection.selEnd = to ;
-    ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-    ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+    ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     TEDelete( teH ) ;
     Refresh() ;
 }
@@ -357,12 +357,12 @@ void wxTextCtrl::SetSelection(long from, long to)
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
    selection.selStart = from ;
    selection.selEnd = to ;
    
-   ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+   ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
    TESetSelect( selection.selStart , selection.selEnd , teH ) ;
 }
 
@@ -385,7 +385,7 @@ void wxTextCtrl::WriteText(const wxString& text)
     wxBuffer[text.Length() ] = 0 ;
 //    wxMacConvertNewlines( wxBuffer , wxBuffer ) ;
    
-    ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
         TEInsert( wxBuffer , strlen( wxBuffer) , teH ) ;
         Refresh() ;
@@ -399,7 +399,7 @@ void wxTextCtrl::AppendText(const wxString& text)
 
 void wxTextCtrl::Clear()
 {
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
     Refresh() ;
 }
 
@@ -484,7 +484,7 @@ void wxTextCtrl::DiscardEdits()
 int wxTextCtrl::GetNumberOfLines() const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     
     int count = 1;
     for (int i = 0; i < actualsize; i++)
@@ -514,7 +514,7 @@ void wxTextCtrl::ShowPosition(long pos)
 int wxTextCtrl::GetLineLength(long lineNo) const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     
     // Find line first
     int count = 0;
@@ -541,7 +541,7 @@ int wxTextCtrl::GetLineLength(long lineNo) const
 wxString wxTextCtrl::GetLineText(long lineNo) const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     
     // Find line first
     int count = 0;
@@ -649,12 +649,12 @@ void wxTextCtrl::OnChar(wxKeyEvent& key_event)
             break;
     }
     
-    EventRecord *ev = wxTheApp->MacGetCurrentEvent();
+    EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent();
     short keychar = short(ev->message & charCodeMask);
     if (!eat_key)
     {
         short keycode = short(ev->message & keyCodeMask) >> 8 ;
-        ::HandleControlKey( m_macControl , keycode , keychar , ev->modifiers );
+        ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers );
     }
     if ( keychar >= 0x20 ||
          key_event.KeyCode() == WXK_RETURN ||
@@ -1706,7 +1706,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
 
     if ( style & wxTE_PASSWORD )
     {
-      m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, 
+      m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , true , 0 , 0 , 1, 
         kControlEditTextPasswordProc , (long) this ) ;
     }
     else
@@ -1725,13 +1725,13 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         
     if ( style & wxTE_PASSWORD )
     {
-      ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+      ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
         /* set up locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* set the text in the record */
     TXNSetData( (**tpvars).fTXNRec, kTXNTextData,  (const char*)value, value.Length(),
       kTXNStartOffset, kTXNEndOffset);
@@ -1745,14 +1745,14 @@ wxString wxTextCtrl::GetValue() const
     Size actualsize;
   if ( m_windowStyle & wxTE_PASSWORD )
   {
-      ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+      ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
     OSStatus err;
         /* set up locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* extract the text from the record */
     Handle theText ;
     err = TXNGetDataEncoded( (**tpvars).fTXNRec, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
@@ -1783,7 +1783,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
 
     *from = (**teH).selStart;
     *to = (**teH).selEnd;
@@ -1793,7 +1793,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
         STPTextPaneVars **tpvars;
 
             /* set up locals */
-        tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+        tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
 
         TXNGetSelection(  (**tpvars).fTXNRec , (TXNOffset*) from , (TXNOffset*) to ) ;
 
@@ -1810,13 +1810,13 @@ void wxTextCtrl::SetValue(const wxString& st)
         value = st ;
   if ( m_windowStyle & wxTE_PASSWORD )
   {
-      ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+      ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
         /* set up locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* set the text in the record */
     TXNSetData( (**tpvars).fTXNRec, kTXNTextData,  (const char*)value, value.Length(),
       kTXNStartOffset, kTXNEndOffset);
@@ -1834,14 +1834,14 @@ void wxTextCtrl::Copy()
             TEHandle teH ;
             long size ;
        
-      		 ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+      		 ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     		TECopy( teH ) ;
     		ClearCurrentScrap();
     		TEToScrap() ;
     	}
     	else
     	{
-    	  mUPDoEditCommand( m_macControl , kmUPCopy ) ;
+    	  mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCopy ) ;
     	}
 	}
 }
@@ -1855,7 +1855,7 @@ void wxTextCtrl::Cut()
             TEHandle teH ;
             long size ;
        
-       		::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+       		::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     		TECut( teH ) ;
     		ClearCurrentScrap();
     		TEToScrap() ;
@@ -1863,7 +1863,7 @@ void wxTextCtrl::Cut()
     }
     	else
     	{
-    	  mUPDoEditCommand( m_macControl , kmUPCut ) ;
+    	  mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCut ) ;
     	}
 	}
 }
@@ -1877,14 +1877,14 @@ void wxTextCtrl::Paste()
             TEHandle teH ;
             long size ;
      
-     		::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+     		::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
   		TEFromScrap() ;
   		TEPaste( teH ) ;
       MacRedrawControl() ;
   	}
    	else
    	{
-   	  mUPDoEditCommand( m_macControl , kmUPPaste ) ;
+   	  mUPDoEditCommand( (ControlHandle) m_macControl , kmUPPaste ) ;
    	}
 	}
 }
@@ -1943,9 +1943,9 @@ bool wxTextCtrl::CanPaste() const
 void wxTextCtrl::SetEditable(bool editable)
 {
     if ( editable )
-        UMAActivateControl( m_macControl ) ;
+        UMAActivateControl( (ControlHandle) m_macControl ) ;
     else
-        UMADeactivateControl( m_macControl ) ;
+        UMADeactivateControl( (ControlHandle) m_macControl ) ;
 }
 
 void wxTextCtrl::SetInsertionPoint(long pos)
@@ -1975,14 +1975,14 @@ long wxTextCtrl::GetLastPosition() const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
-//   ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
+//   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
     return (**teH).teLength ;
   }
   else
   {
-     STPTextPaneVars**	tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+     STPTextPaneVars**	tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
 
     int actualsize = 0 ;
   	Handle theText ;
@@ -2012,8 +2012,8 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
    
    	selection.selStart = from ;
    	selection.selEnd = to ;
-   	::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-		::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   	::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+		::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    	TESetSelect( from , to  , teH ) ;
    	TEDelete( teH ) ;
 		TEInsert( value , value.Length() , teH ) ;
@@ -2036,8 +2036,8 @@ void wxTextCtrl::Remove(long from, long to)
    
    	selection.selStart = from ;
    	selection.selEnd = to ;
-   	::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-	::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   	::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+	::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    	TEDelete( teH ) ;
   }
   else
@@ -2055,19 +2055,19 @@ void wxTextCtrl::SetSelection(long from, long to)
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
    selection.selStart = from ;
    selection.selEnd = to ;
    
-   ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+   ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
    TESetSelect( selection.selStart , selection.selEnd , teH ) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
         /* set up our locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* and our drawing environment as the operation
         may force a redraw in the text area. */
     SetPort((**tpvars).fDrawingEnvironment);
@@ -2098,14 +2098,14 @@ void wxTextCtrl::WriteText(const wxString& text)
       TEHandle teH ;
       long size ;
           
-      ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+      ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
         TEInsert( value , value.Length() , teH ) ;
         }
         else
         {
         STPTextPaneVars **tpvars;
             /* set up locals */
-        tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+        tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
             /* set the text in the record */
         TXNSetData( (**tpvars).fTXNRec, kTXNTextData,  (const char*)value, value.Length(),
           kTXNUseCurrentSelection, kTXNUseCurrentSelection);
@@ -2124,11 +2124,11 @@ void wxTextCtrl::Clear()
   if ( m_windowStyle & wxTE_PASSWORD )
   {
 
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
   }
   else
   {
-    mUPDoEditCommand( m_macControl , kmUPClear) ;
+    mUPDoEditCommand( (ControlHandle) m_macControl , kmUPClear) ;
   }
 	Refresh() ;
 }
@@ -2374,7 +2374,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
     short keychar ;
     keychar = short(ev->message & charCodeMask);
     keycode = short(ev->message & keyCodeMask) >> 8 ;
-    UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ;
+    UMAHandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
     if ( keychar >= 0x20 || event.KeyCode() == WXK_RETURN || event.KeyCode() == WXK_DELETE || event.KeyCode() == WXK_BACK)
     {
         wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
diff --git a/src/mac/thread.cpp b/src/mac/thread.cpp
index a8243467ed..c68fd396de 100644
--- a/src/mac/thread.cpp
+++ b/src/mac/thread.cpp
@@ -34,6 +34,10 @@
 #include "wx/module.h"
 #include "wx/thread.h"
 
+#ifdef __WXMAC__
+#include "wx/mac/private.h"
+#endif
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
diff --git a/src/mac/timer.cpp b/src/mac/timer.cpp
index f2b5f2e896..e2693c3e8a 100644
--- a/src/mac/timer.cpp
+++ b/src/mac/timer.cpp
@@ -19,6 +19,17 @@
 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
 #endif
 
+#ifdef __WXMAC__
+#include "wx/mac/private.h"
+#endif
+
+typedef struct MacTimerInfo
+{
+    TMTask m_task;
+    wxMacNotifierTableRef m_table ;
+    wxTimer* m_timer ;
+} ;
+
 static void wxProcessTimer( unsigned long event , void *data ) ;
 
 static pascal void MacTimerProc( TMTask * t )
@@ -38,30 +49,33 @@ static void wxProcessTimer( unsigned long event , void *data )
 		
     timer->Notify();
 
-    if ( timer->m_info.m_task.tmAddr && !timer->IsOneShot() )
+    if ( timer->m_info->m_task.tmAddr && !timer->IsOneShot() )
     {
-	    PrimeTime( (QElemPtr)  &timer->m_info.m_task , timer->GetInterval() ) ;
+	    PrimeTime( (QElemPtr)  &timer->m_info->m_task , timer->GetInterval() ) ;
     }
 }
 
 void wxTimer::Init()
 {
-	m_info.m_task.tmAddr = NULL ;
-	m_info.m_task.tmWakeUp = 0 ;
-	m_info.m_task.tmReserved = 0 ;
-	m_info.m_task.qType = 0 ;
-	m_info.m_table = wxMacGetNotifierTable() ;
-	m_info.m_timer = this ;
+    m_info = new MacTimerInfo() ;
+	m_info->m_task.tmAddr = NULL ;
+	m_info->m_task.tmWakeUp = 0 ;
+	m_info->m_task.tmReserved = 0 ;
+	m_info->m_task.qType = 0 ;
+	m_info->m_table = wxMacGetNotifierTable() ;
+	m_info->m_timer = this ;
 }
 
 bool wxTimer::IsRunning() const 
 {
-	return ( m_info.m_task.qType & kTMTaskActive ) ;
+	return ( m_info->m_task.qType & kTMTaskActive ) ;
 }
 
 wxTimer::~wxTimer()
 {
     Stop();
+    delete m_info ;
+    m_info = NULL ;
 }
 
 bool wxTimer::Start(int milliseconds,bool mode)
@@ -69,31 +83,31 @@ bool wxTimer::Start(int milliseconds,bool mode)
     (void)wxTimerBase::Start(milliseconds, mode);
 
     wxCHECK_MSG( m_milli > 0, FALSE, wxT("invalid value for timer timeour") );
-    wxCHECK_MSG( m_info.m_task.tmAddr == NULL , FALSE, wxT("attempting to restart a timer") );
+    wxCHECK_MSG( m_info->m_task.tmAddr == NULL , FALSE, wxT("attempting to restart a timer") );
 
     m_milli = milliseconds;
 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
-    m_info.m_task.tmAddr = NewTimerUPP( MacTimerProc ) ;
+    m_info->m_task.tmAddr = NewTimerUPP( MacTimerProc ) ;
 #else
-    m_info.m_task.tmAddr = NewTimerProc( MacTimerProc ) ;
+    m_info->m_task.tmAddr = NewTimerProc( MacTimerProc ) ;
 #endif
-    m_info.m_task.tmWakeUp = 0 ;
-    m_info.m_task.tmReserved = 0 ;
-	m_info.m_task.qType = 0 ;
-	m_info.m_timer = this ;
-    InsXTime((QElemPtr) &m_info.m_task ) ;
-    PrimeTime( (QElemPtr) &m_info.m_task , m_milli ) ;
+    m_info->m_task.tmWakeUp = 0 ;
+    m_info->m_task.tmReserved = 0 ;
+	m_info->m_task.qType = 0 ;
+	m_info->m_timer = this ;
+    InsXTime((QElemPtr) &m_info->m_task ) ;
+    PrimeTime( (QElemPtr) &m_info->m_task , m_milli ) ;
     return FALSE;
 }
 
 void wxTimer::Stop()
 {
     m_milli = 0 ;
-    if ( m_info.m_task.tmAddr )
+    if ( m_info->m_task.tmAddr )
     {
-    	RmvTime(  (QElemPtr) &m_info.m_task ) ;
-    	DisposeTimerUPP(m_info.m_task.tmAddr) ;
-    	m_info.m_task.tmAddr = NULL ;
+    	RmvTime(  (QElemPtr) &m_info->m_task ) ;
+    	DisposeTimerUPP(m_info->m_task.tmAddr) ;
+    	m_info->m_task.tmAddr = NULL ;
     }
     wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ;
 }
diff --git a/src/mac/toolbar.cpp b/src/mac/toolbar.cpp
index 9604fbc2c1..66bed14b79 100644
--- a/src/mac/toolbar.cpp
+++ b/src/mac/toolbar.cpp
@@ -168,7 +168,7 @@ bool wxToolBar::Realize()
 
     Point localOrigin ;
     Rect clipRect ;
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
     wxWindow *win ;
     
     int lx , ly ;
@@ -215,20 +215,20 @@ bool wxToolBar::Realize()
                 if ( bmap->m_bitmapType == kMacBitmapTypePict )
                 {
                     info.contentType = kControlContentPictHandle ;
-                    info.u.picture = bmap->m_hPict ;
+                    info.u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
                 }
                 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
                 {
                     if ( tool->GetBitmap1().GetMask() )
                     {
                         info.contentType = kControlContentCIconHandle ;
-                        info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , tool->GetBitmap1().GetMask()->GetMaskBitmap() ,
+                        info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(tool->GetBitmap1().GetMask()->GetMaskBitmap()) ,
                                                                8 , 16 ) ;
                     }
                     else
                     {
                         info.contentType = kControlContentCIconHandle ;
-                        info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , NULL ,
+                        info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
                                                                8 , 16 ) ;
                     }
                 }
@@ -270,7 +270,7 @@ bool wxToolBar::Realize()
             /*
               ::SetControlFontStyle( m_macToolHandle , &controlstyle ) ;
             */
-            ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
+            ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
             wxASSERT_MSG( container != NULL , "No valid mac container control" ) ;
             ::EmbedControl( m_macToolHandle , container ) ;
             
@@ -346,7 +346,7 @@ wxSize wxToolBar::GetToolSize() const
     return wxSize(m_defaultWidth + 4, m_defaultHeight + 4);
 }
 
-void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) 
+void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) 
 {
     int index = 0 ;
     for ( index = 0 ; index < m_macToolHandles.Count() ; ++index )
@@ -356,7 +356,7 @@ void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpar
             wxToolBarTool *tool = (wxToolBarTool *)m_tools.Nth( index )->Data();
             if ( tool->CanBeToggled() )
             {
-                tool->Toggle( GetControlValue( control ) ) ;
+                tool->Toggle( GetControlValue( (ControlHandle) control ) ) ;
             }
             OnLeftClick( tool->GetId() , tool -> IsToggled() ) ;
             break ;
@@ -410,7 +410,7 @@ void wxToolBar::MacSuperChangedPosition()
     int maxHeight = 0 ;
     int toolcount = 0 ;
     {
-      WindowRef rootwindow = MacGetRootWindow() ;
+      WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
     	while (node)
     	{
     		wxToolBarTool *tool = (wxToolBarTool *)node->Data();
@@ -611,7 +611,7 @@ void  wxToolBar::OnMouse( wxMouseEvent &event )
 		Point		localwhere ;
 		GrafPtr		port ;
 		SInt16		controlpart ;
-		WindowRef	window = MacGetRootWindow() ;
+		WindowRef	window = (WindowRef) MacGetRootWindow() ;
 		
 		localwhere.h = x ;
 		localwhere.v = y ;
diff --git a/src/mac/tooltip.cpp b/src/mac/tooltip.cpp
index 45877f9a1c..0655699087 100644
--- a/src/mac/tooltip.cpp
+++ b/src/mac/tooltip.cpp
@@ -21,13 +21,14 @@
 #include "wx/tooltip.h"
 #include "wx/timer.h"
 #include "wx/geometry.h"
-#include "wx/mac/aga.h"
 #include "wx/mac/uma.h"
 
 //-----------------------------------------------------------------------------
 // global data
 //-----------------------------------------------------------------------------
 
+class wxMacToolTipTimer ;
+
 class wxMacToolTip
 {
 	public :
@@ -48,6 +49,7 @@ class wxMacToolTip
 		PicHandle	m_backpict ;
 		bool		m_shown ;
 		long		m_mark ;
+		wxMacToolTipTimer* m_timer ;
 } ;
 
 class wxMacToolTipTimer : wxTimer
@@ -60,7 +62,6 @@ public:
 		if ( m_mark == m_tip->GetMark() )
 			m_tip->Draw() ;
 
-		delete this;
 	}
 	
 protected:
@@ -148,7 +149,7 @@ void wxToolTip::RelayEvent( wxWindow *win , wxMouseEvent &event )
 				s_ToolTipArea = wxRect2DInt( event.m_x - 2 , event.m_y - 2 , 4 , 4 ) ;
 				s_LastWindowEntered = win ;
 				
-				WindowRef window = win->MacGetRootWindow() ;
+				WindowRef window = MAC_WXHWND( win->MacGetRootWindow() ) ;
 				int x = event.m_x ;
 				int y = event.m_y ;
 				wxPoint local( x , y ) ;
@@ -179,6 +180,7 @@ wxMacToolTip::wxMacToolTip()
 	m_backpict = NULL ;
 	m_mark = 0 ;
 	m_shown = false ;
+    m_timer = NULL ;
 }
 
 void wxMacToolTip::Setup( WindowRef window  , wxString text , wxPoint localPosition ) 
@@ -190,11 +192,15 @@ void wxMacToolTip::Setup( WindowRef window  , wxString text , wxPoint localPosit
 	m_window = window ;
 	s_ToolTipWindowRef = window ;
 	m_backpict = NULL ;
-	new wxMacToolTipTimer( this , s_ToolTipDelay ) ;
+	if ( m_timer )
+	    delete m_timer ;
+	m_timer = new wxMacToolTipTimer( this , s_ToolTipDelay ) ;
 }
 
 wxMacToolTip::~wxMacToolTip() 
 {
+    if ( m_timer )
+        delete m_timer ;
 	if ( m_backpict ) 
 		Clear() ;
 }
@@ -219,11 +225,8 @@ void wxMacToolTip::Draw()
 */
 #endif
 	  {
-  		#if TARGET_CARBON
-  		AGAPortHelper help( GetWindowPort( m_window ) );
-  		#else
-  		AGAPortHelper help( ( m_window ) );
-  		#endif
+   		wxMacPortStateHelper help( GetWindowPort( m_window ) );
+ 
   		m_shown = true ;
 
   		TextFont( kFontIDGeneva ) ;
@@ -309,7 +312,7 @@ void wxMacToolTip::Draw()
 	}
 }
 
-void wxToolTip::NotifyWindowDelete( WindowRef win ) 
+void wxToolTip::NotifyWindowDelete( WXHWND win ) 
 {
 	if ( win == s_ToolTipWindowRef )
 	{
@@ -325,11 +328,8 @@ void wxMacToolTip::Clear()
 		 
 	if ( m_window == s_ToolTipWindowRef && m_backpict )
 	{
-		#if TARGET_CARBON
-		AGAPortHelper help( GetWindowPort(m_window) ) ;
-		#else
-		AGAPortHelper help( (m_window) ) ;
-		#endif
+		wxMacPortStateHelper help( GetWindowPort(m_window) ) ;
+
 		m_shown = false ;
 
 		BackColor( whiteColor ) ;
diff --git a/src/mac/toplevel.cpp b/src/mac/toplevel.cpp
index 8c84e811e0..83b905c227 100644
--- a/src/mac/toplevel.cpp
+++ b/src/mac/toplevel.cpp
@@ -65,7 +65,7 @@ wxWindowList wxModelessWindows;
 // Find an item given the Macintosh Window Reference
 
 wxList *wxWinMacWindowList = NULL;
-wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
+wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef)
 {
     wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
     if (!node)
@@ -73,7 +73,7 @@ wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
     return (wxTopLevelWindowMac *)node->Data();
 }
 
-void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win)
+void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win)
 {
     // adding NULL WindowRef is (first) surely a result of an error and
     // (secondly) breaks menu command processing
@@ -93,7 +93,7 @@ void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
 // wxTopLevelWindowMac creation
 // ----------------------------------------------------------------------------
 
-WindowRef wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
+WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
 
 void wxTopLevelWindowMac::Init()
 {
@@ -131,7 +131,7 @@ bool wxTopLevelWindowMac::Create(wxWindow *parent,
 wxTopLevelWindowMac::~wxTopLevelWindowMac()
 {
     wxToolTip::NotifyWindowDelete(m_macWindow) ;
-    UMADisposeWindow( m_macWindow ) ;
+    UMADisposeWindow( (WindowRef) m_macWindow ) ;
 
     wxRemoveMacWindowAssociation( this ) ;
 
@@ -150,7 +150,7 @@ wxTopLevelWindowMac::~wxTopLevelWindowMac()
           wxTheApp->ExitMainLoop() ;        
         }
     }
-    DisposeRgn( m_macNoEraseUpdateRgn ) ;
+    DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
 }
 
 
@@ -267,27 +267,27 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
         attr |= kWindowCloseBoxAttribute ;
     }
     
-    ::CreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindow ) ;
+    ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
     wxAssociateWinWithMacWindow( m_macWindow , this ) ;
     wxString label ;
     if( wxApp::s_macDefaultEncodingIsPC )
         label = wxMacMakeMacStringFromPC( title ) ;
     else
         label = title ;
-    UMASetWTitleC( m_macWindow , label ) ;
-    ::CreateRootControl( m_macWindow , &m_macRootControl ) ;
+    UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
+    ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
 
     m_macFocus = NULL ;
 }
 
-void wxTopLevelWindowMac::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window  , wxWindowMac** rootwin) 
+void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window  , wxWindowMac** rootwin) 
 {
-    localOrigin->h = 0;
-    localOrigin->v = 0;
-    clipRect->left = 0;
-    clipRect->top = 0;
-    clipRect->right = m_width;
-    clipRect->bottom = m_height;
+    ((Point*)localOrigin)->h = 0;
+    ((Point*)localOrigin)->v = 0;
+    ((Rect*)clipRect)->left = 0;
+    ((Rect*)clipRect)->top = 0;
+    ((Rect*)clipRect)->right = m_width;
+    ((Rect*)clipRect)->bottom = m_height;
     *window = m_macWindow ;
     *rootwin = this ;
 }
@@ -297,7 +297,7 @@ void wxTopLevelWindowMac::Clear()
   wxWindow::Clear() ;
 }
 
-ControlHandle wxTopLevelWindowMac::MacGetContainerForEmbedding() 
+WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding() 
 {
     return m_macRootControl ;
 }
@@ -305,19 +305,17 @@ ControlHandle wxTopLevelWindowMac::MacGetContainerForEmbedding()
 
 void wxTopLevelWindowMac::MacUpdate( long timestamp)
 {
-    #if TARGET_CARBON
-    AGAPortHelper help( GetWindowPort(m_macWindow) ) ;
-    #else
-    AGAPortHelper help( (m_macWindow) ) ;
-    #endif
-    BeginUpdate( m_macWindow ) ;
+
+    wxMacPortStateHelper help( GetWindowPort( (WindowRef) m_macWindow) ) ;
+
+    BeginUpdate( (WindowRef)m_macWindow ) ;
 
     RgnHandle       updateRgn = NewRgn();    
     RgnHandle       diffRgn = NewRgn() ;
     if ( updateRgn && diffRgn )
     {
-        GetPortVisibleRegion( GetWindowPort( m_macWindow ), updateRgn );
-        DiffRgn( updateRgn , m_macNoEraseUpdateRgn , diffRgn ) ;
+        GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn );
+        DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
         if ( !EmptyRgn( updateRgn ) )
         {
             MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn )  ) ;
@@ -327,8 +325,8 @@ void wxTopLevelWindowMac::MacUpdate( long timestamp)
         DisposeRgn( updateRgn );
     if ( diffRgn )
         DisposeRgn( diffRgn );
-    EndUpdate( m_macWindow ) ;
-    SetEmptyRgn( m_macNoEraseUpdateRgn ) ;
+    EndUpdate( (WindowRef)m_macWindow ) ;
+    SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
     m_macNeedsErasing = false ;
 }
 
@@ -336,21 +334,22 @@ void wxTopLevelWindowMac::MacUpdate( long timestamp)
 // Raise the window to the top of the Z order
 void wxTopLevelWindowMac::Raise()
 {
-    ::BringToFront( m_macWindow ) ;
+    ::BringToFront( (WindowRef)m_macWindow ) ;
 }
 
 // Lower the window to the bottom of the Z order
 void wxTopLevelWindowMac::Lower()
 {
-    ::SendBehind( m_macWindow , NULL ) ;
+    ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
 }
 
 Point lastWhere ;
 long lastWhen = 0 ;
 extern int wxBusyCursorCount ;
 
-void wxTopLevelWindowMac::MacFireMouseEvent( EventRecord *ev )
+void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr )
 {
+    EventRecord *ev = (EventRecord*) evr ;
     wxMouseEvent event(wxEVT_LEFT_DOWN);
     bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
     bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
@@ -388,7 +387,7 @@ void wxTopLevelWindowMac::MacFireMouseEvent( EventRecord *ev )
         
     GrafPtr     port ;  
     ::GetPort( &port ) ;
-    ::SetPort( UMAGetWindowPort( m_macWindow ) ) ;
+    ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ;
     ::GlobalToLocal( &localwhere ) ;
     ::SetPort( port ) ;
 
@@ -449,12 +448,12 @@ void wxTopLevelWindowMac::MacFireMouseEvent( EventRecord *ev )
     }
 }
 
-void wxTopLevelWindowMac::MacMouseDown( EventRecord *ev , short part)
+void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part)
 {
     MacFireMouseEvent( ev ) ;
 }
 
-void wxTopLevelWindowMac::MacMouseUp( EventRecord *ev , short part)
+void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part)
 {
     switch (part)
     {
@@ -466,7 +465,7 @@ void wxTopLevelWindowMac::MacMouseUp( EventRecord *ev , short part)
     }
 }
 
-void wxTopLevelWindowMac::MacMouseMoved( EventRecord *ev , short part)
+void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part)
 {
     switch (part)
     {
@@ -477,20 +476,20 @@ void wxTopLevelWindowMac::MacMouseMoved( EventRecord *ev , short part)
             break ;
     }
 }
-void wxTopLevelWindowMac::MacActivate( EventRecord *ev , bool inIsActivating )
+void wxTopLevelWindowMac::MacActivate( WXEVENTREF ev , bool inIsActivating )
 {
     wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
-    event.m_timeStamp = ev->when ;
+    event.m_timeStamp = ((EventRecord*)ev)->when ;
     event.SetEventObject(this);
     
     GetEventHandler()->ProcessEvent(event);
     
-    UMAHighlightAndActivateWindow( m_macWindow , inIsActivating ) ;
+    UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ;
     
     MacSuperEnabled( inIsActivating ) ;
 }
 
-void wxTopLevelWindowMac::MacKeyDown( EventRecord *ev ) 
+void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ) 
 {
 }
 
@@ -505,7 +504,7 @@ void wxTopLevelWindowMac::SetTitle(const wxString& title)
     else
         label = m_label ;
 
-    UMASetWTitleC( m_macWindow , label ) ;
+    UMASetWTitleC( (WindowRef)m_macWindow , label ) ;
 }
 
 bool wxTopLevelWindowMac::Show(bool show)
@@ -515,8 +514,8 @@ bool wxTopLevelWindowMac::Show(bool show)
 
     if (show)
     {
-      ::ShowWindow( m_macWindow ) ;
-      ::SelectWindow( m_macWindow ) ;
+      ::ShowWindow( (WindowRef)m_macWindow ) ;
+      ::SelectWindow( (WindowRef)m_macWindow ) ;
       // no need to generate events here, they will get them triggered by macos
       // actually they should be , but apparently they are not
       wxSize size(m_width, m_height);
@@ -526,7 +525,7 @@ bool wxTopLevelWindowMac::Show(bool show)
     }
     else
     {
-      ::HideWindow( m_macWindow ) ;
+      ::HideWindow( (WindowRef)m_macWindow ) ;
     }
 
     if ( !show )
@@ -581,10 +580,10 @@ void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
         m_height = actualHeight ;
 
         if ( doMove )
-            ::MoveWindow(m_macWindow, m_x, m_y  , false); // don't make frontmost
+            ::MoveWindow((WindowRef)m_macWindow, m_x, m_y  , false); // don't make frontmost
         
         if ( doResize )
-            ::SizeWindow(m_macWindow, m_width, m_height  , true); 
+            ::SizeWindow((WindowRef)m_macWindow, m_width, m_height  , true); 
         
         // the OS takes care of invalidating and erasing the new area
         // we have erased the old one   
@@ -632,11 +631,11 @@ void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
  * will get the eraseBackground event first
  */
  
-void wxTopLevelWindowMac::MacInvalidate( const Rect * rect, bool eraseBackground ) 
+void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ) 
 {
   GrafPtr formerPort ;
   GetPort( &formerPort ) ;
-  SetPortWindowPort( m_macWindow ) ;
+  SetPortWindowPort( (WindowRef)m_macWindow ) ;
   
   m_macNeedsErasing |= eraseBackground ;
   
@@ -651,11 +650,11 @@ void wxTopLevelWindowMac::MacInvalidate( const Rect * rect, bool eraseBackground
     RgnHandle       diffRgn = NewRgn() ;
     if ( updateRgn && diffRgn )
     {
-        GetWindowUpdateRgn( m_macWindow , updateRgn );
+        GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn );
         Point pt = {0,0} ;
         LocalToGlobal( &pt ) ;
         OffsetRgn( updateRgn , -pt.h , -pt.v ) ;
-        DiffRgn( updateRgn , m_macNoEraseUpdateRgn , diffRgn ) ;
+        DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;
         if ( !EmptyRgn( diffRgn ) )
         {
             m_macNeedsErasing = true ;
@@ -669,12 +668,12 @@ void wxTopLevelWindowMac::MacInvalidate( const Rect * rect, bool eraseBackground
     if ( !m_macNeedsErasing )
     {
       RgnHandle rectRgn = NewRgn() ;
-      SetRectRgn( rectRgn , rect->left , rect->top , rect->right , rect->bottom ) ;
-      UnionRgn( m_macNoEraseUpdateRgn , rectRgn , m_macNoEraseUpdateRgn ) ;
+      SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ;
+      UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ;
       DisposeRgn( rectRgn ) ;
     }
   }
-  InvalWindowRect( m_macWindow , rect ) ;
+  InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ;
   // turn this on to debug the refreshing cycle
 #if wxMAC_DEBUG_REDRAW
   PaintRect( rect ) ;
diff --git a/src/mac/uma.cpp b/src/mac/uma.cpp
index f76e815114..1c31f87d4c 100644
--- a/src/mac/uma.cpp
+++ b/src/mac/uma.cpp
@@ -142,6 +142,7 @@ bool UMAGetProcessModeDoesActivateOnFGSwitch()
 
 void UMASetMenuTitle( MenuRef menu , StringPtr title )
 {
+/*
 #if !TARGET_CARBON
 	long 			size = GetHandleSize( (Handle) menu ) ;
 	const long 		headersize = 14 ;
@@ -164,8 +165,9 @@ void UMASetMenuTitle( MenuRef menu , StringPtr title )
 		SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
 	}
 #else
+*/
 	SetMenuTitle( menu , title ) ;
-#endif
+//#endif
 }
 
 UInt32 UMAMenuEvent( EventRecord *inEvent )
@@ -602,3 +604,55 @@ OSStatus UMAGetHelpMenu(
   return helpMenuStatus ;
 #endif
 }
+
+wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport) 
+{
+  m_clip = NULL ;
+  Setup( newport ) ;
+}
+
+wxMacPortStateHelper::wxMacPortStateHelper()
+{
+	m_clip = NULL ;
+}
+
+void wxMacPortStateHelper::Setup( GrafPtr newport )
+{
+	GetPort( &m_oldPort ) ;
+	SetPort( newport ) ;
+	wxASSERT_MSG( m_clip == NULL , "Cannot call setup twice" ) ;
+	m_clip = NewRgn() ;
+	GetClip( m_clip );
+	m_textFont = GetPortTextFont( (CGrafPtr) newport);
+	m_textSize = GetPortTextSize( (CGrafPtr) newport);
+	m_textStyle = GetPortTextFace( (CGrafPtr) newport);
+	m_textMode = GetPortTextMode( (CGrafPtr) newport);	
+	GetThemeDrawingState( &m_drawingState ) ;
+	m_currentPort = newport ;
+}
+void wxMacPortStateHelper::Clear()
+{
+	if ( m_clip )
+	{
+		DisposeRgn( m_clip ) ;
+		DisposeThemeDrawingState( m_drawingState ) ;
+		m_clip = NULL ;
+	}
+}
+
+wxMacPortStateHelper::~wxMacPortStateHelper()
+{
+	if ( m_clip )
+	{
+		SetPort( m_currentPort ) ;
+		SetClip( m_clip ) ;
+		DisposeRgn( m_clip ) ;
+		TextFont( m_textFont );
+		TextSize( m_textSize );
+		TextFace( m_textStyle );
+		TextMode( m_textMode );
+		SetThemeDrawingState( m_drawingState , true ) ;
+		SetPort( m_oldPort ) ;
+	}
+}
+
diff --git a/src/mac/wave.cpp b/src/mac/wave.cpp
index f0891a6546..d06eee4838 100644
--- a/src/mac/wave.cpp
+++ b/src/mac/wave.cpp
@@ -17,6 +17,10 @@
 #include "wx/string.h"
 #include "wx/wave.h"
 
+#ifdef __WXMAC__
+#include "wx/mac/private.h"
+#endif
+
 wxWave::wxWave()
   : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true)
 {
@@ -136,7 +140,7 @@ bool wxWave::Play(bool async, bool looped) const
 	  
 	  hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd);
 
-	  if ((hSnd != NULL) && (SndPlay(m_sndChan, hSnd, async) == noErr))
+	  if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, async) == noErr))
 	    ret = true;
 	} 
 	
diff --git a/src/mac/window.cpp b/src/mac/window.cpp
index 7bf95a6ca3..bd38b3ccd2 100644
--- a/src/mac/window.cpp
+++ b/src/mac/window.cpp
@@ -205,7 +205,7 @@ void wxWindowMac::SetFocus()
             wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
             if ( control && control->GetMacControl() )
             {
-                UMASetKeyboardFocus( gFocusWindow->MacGetRootWindow() , control->GetMacControl()  , kControlFocusNoPart ) ;
+                UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl()  , kControlFocusNoPart ) ;
                 control->MacRedrawControl() ;
             }
             #endif
@@ -230,7 +230,7 @@ void wxWindowMac::SetFocus()
             wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
             if ( control && control->GetMacControl() )
             {
-                UMASetKeyboardFocus( gFocusWindow->MacGetRootWindow() , control->GetMacControl()  , kControlEditTextPart ) ;
+                UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl()  , kControlEditTextPart ) ;
             }
       #endif
             wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
@@ -318,8 +318,8 @@ bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
     menu->UpdateUI();
     ClientToScreen( &x , &y ) ;
 
-    ::InsertMenu( menu->GetHMenu() , -1 ) ;
-    long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ;
+    ::InsertMenu( (MenuHandle) menu->GetHMenu() , -1 ) ;
+    long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
     menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ;
     ::DeleteMenu( menu->MacGetMenuId() ) ;
     menu->SetInvokingWindow(NULL);
@@ -330,7 +330,7 @@ bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
 
 void wxWindowMac::DoScreenToClient(int *x, int *y) const
 {
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
 
     Point       localwhere = {0,0} ;
 
@@ -351,7 +351,7 @@ void wxWindowMac::DoScreenToClient(int *x, int *y) const
 
 void wxWindowMac::DoClientToScreen(int *x, int *y) const
 {
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
     
     MacClientToRootWindow( x , y ) ;
     
@@ -681,7 +681,7 @@ bool wxWindowMac::Show(bool show)
     MacSuperShown( show ) ;
     if ( !show )
     {
-        WindowRef window = MacGetRootWindow() ;
+        WindowRef window = (WindowRef) MacGetRootWindow() ;
         wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
         if ( win && !win->m_isBeingDeleted )
             Refresh() ; 
@@ -869,7 +869,7 @@ const wxBrush& wxWindowMac::MacGetBackgroundBrush()
         // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
         // either a non gray background color or a non control window
         
-            WindowRef window = MacGetRootWindow() ;
+            WindowRef window = (WindowRef) MacGetRootWindow() ;
             
             wxWindowMac* parent = GetParent() ;
             while( parent )
@@ -902,7 +902,7 @@ const wxBrush& wxWindowMac::MacGetBackgroundBrush()
                         extent.top-- ;
                         extent.right = x + size.x ;
                         extent.bottom = y + size.y ;
-                        m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , extent ) ; // todo eventually change for inactive
+                        m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive
                         break ;
                     }
                 }
@@ -932,7 +932,7 @@ void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
     wxWindowDC dc(this) ;
     wxMacPortSetter helper(&dc) ;
     
-    MacPaintBorders( dc.m_macLocalOrigin.h , dc.m_macLocalOrigin.v) ;
+    MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
 }
 
 int wxWindowMac::GetScrollPos(int orient) const
@@ -1120,7 +1120,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
             SectRect( &scrollrect , &r , &scrollrect ) ;        
         }
         ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
-        InvalWindowRgn( MacGetRootWindow() ,  updateRgn ) ;
+        InvalWindowRgn( (WindowRef) MacGetRootWindow() ,  updateRgn ) ;
         DisposeRgn( updateRgn ) ;
     }
     
@@ -1309,7 +1309,7 @@ bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac**
           return FALSE;
     }
     
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
 
     wxPoint newPoint( point ) ;
 
@@ -1363,7 +1363,7 @@ bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
     if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) )
         return FALSE ; 
     
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
 
     event.m_x -= m_x;
     event.m_y -= m_y;
@@ -1425,7 +1425,7 @@ void wxWindowMac::Update()
 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const 
 {
     wxTopLevelWindowMac* win = NULL ;
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
     if ( window )
     {
         win = wxFindWinFromMacWindow( window ) ;
@@ -1510,19 +1510,20 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion()
   return m_macVisibleRegion ;
 }
 
-void wxWindowMac::MacRedraw( RgnHandle updatergn , long time, bool erase)
+void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
 {
+    RgnHandle updatergn = (RgnHandle) updatergnr ;
     // updatergn is always already clipped to our boundaries
     // it is in window coordinates, not in client coordinates
     
-    WindowRef window = MacGetRootWindow() ;
+    WindowRef window = (WindowRef) MacGetRootWindow() ;
 
     {
         // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
         RgnHandle ownUpdateRgn = NewRgn() ;
         CopyRgn( updatergn , ownUpdateRgn ) ;
                 
-        SectRgn( ownUpdateRgn , MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ;
+        SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ;
         
         // newupdate is the update region in client coordinates
         RgnHandle newupdate = NewRgn() ;
@@ -1578,7 +1579,7 @@ void wxWindowMac::MacRedraw( RgnHandle updatergn , long time, bool erase)
  
 }
 
-WindowRef wxWindowMac::MacGetRootWindow() const
+WXHWND wxWindowMac::MacGetRootWindow() const
 {
     wxWindowMac *iter = (wxWindowMac*)this ;
     
@@ -1711,7 +1712,7 @@ bool wxWindowMac::AcceptsFocus() const
     return MacCanFocus() && wxWindowBase::AcceptsFocus();
 }
 
-ControlHandle wxWindowMac::MacGetContainerForEmbedding() 
+WXWidget wxWindowMac::MacGetContainerForEmbedding() 
 {
     return GetParent()->MacGetContainerForEmbedding() ;
 }
-- 
2.47.2