]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/control.cpp
warning fix
[wxWidgets.git] / src / mac / control.cpp
index d570e2c5a1ee02a7a0129150830ca9e1cffc83d0..e3511e87a139f569c1a913ed01cd0316ebd3ed2d 100644 (file)
 #endif
 
 #include "wx/control.h"
 #endif
 
 #include "wx/control.h"
+#include "wx/panel.h"
+#include "wx/app.h"
+#include "wx/dc.h"
 #include "wx/notebook.h"
 #include "wx/tabctrl.h"
 #include "wx/notebook.h"
 #include "wx/tabctrl.h"
+#include "wx/radiobox.h"
 #include "wx/spinbutt.h"
 #include "wx/spinbutt.h"
+#include "wx/scrolbar.h"
+#include "wx/button.h"
+#include "wx/dialog.h"
+#include "wx/statbox.h"
+#include "wx/sizer.h"
+#include "wx/stattext.h"
 
 #if !USE_SHARED_LIBRARY
 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
 
 #if !USE_SHARED_LIBRARY
 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
@@ -34,6 +44,7 @@ END_EVENT_TABLE()
 
 ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
 
 
 ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
 
+pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ;
 pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode )
 {
        if ( partCode != 0)
 pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode )
 {
        if ( partCode != 0)
@@ -48,28 +59,53 @@ pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCod
 
 wxControl::wxControl()
 {
 
 wxControl::wxControl()
 {
-               m_macControl = NULL ;
-               m_macHorizontalBorder = 0 ; // additional pixels around the real control
-               m_macVerticalBorder = 0 ;
+       m_macControl = NULL ;
+       m_macHorizontalBorder = 0 ; // additional pixels around the real control
+       m_macVerticalBorder = 0 ;
     m_backgroundColour = *wxWHITE;
     m_foregroundColour = *wxBLACK;
     m_backgroundColour = *wxWHITE;
     m_foregroundColour = *wxBLACK;
-    m_callback = 0;
+#if WXWIN_COMPATIBILITY
+  m_callback = 0;
+#endif // WXWIN_COMPATIBILITY
 
        if ( wxMacLiveScrollbarActionUPP == NULL )
        {
 
        if ( wxMacLiveScrollbarActionUPP == NULL )
        {
+#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
+        wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc );
+#else
                wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ;
                wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ;
+#endif
        }
 }
 
        }
 }
 
+bool wxControl::Create(wxWindow *parent, wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size, long style,
+                       const wxValidator& validator,
+                       const wxString& name)
+{
+       m_macControl = NULL ;
+       m_macHorizontalBorder = 0 ; // additional pixels around the real control
+       m_macVerticalBorder = 0 ;
+    bool rval = wxWindow::Create(parent, id, pos, size, style, name);
+    if (rval) {
+#if wxUSE_VALIDATORS
+        SetValidator(validator);
+#endif
+    }
+    return rval;
+}
+
 wxControl::~wxControl()
 {
 wxControl::~wxControl()
 {
+    m_isBeingDeleted = TRUE;
     // If we delete an item, we should initialize the parent panel,
     // because it could now be invalid.
     // If we delete an item, we should initialize the parent panel,
     // because it could now be invalid.
-    wxWindow *parent = (wxWindow *)GetParent();
-    if (parent)
+    wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
+    if ( panel )
     {
     {
-        if (parent->GetDefaultItem() == (wxButton*) this)
-            parent->SetDefaultItem(NULL);
+        if (panel->GetDefaultItem() == (wxButton*) this)
+            panel->SetDefaultItem(NULL);
     }
     if ( m_macControl )
     {
     }
     if ( m_macControl )
     {
@@ -78,71 +114,56 @@ wxControl::~wxControl()
     }
 }
 
     }
 }
 
-void wxControl::SetLabel(const wxString& label)
+void wxControl::SetLabel(const wxString& title)
 {
 {
-       m_label = label ;
+       m_label = title ;
 
        if ( m_macControl )
        {
                Str255 maclabel ;
 
        if ( m_macControl )
        {
                Str255 maclabel ;
-               
-               strcpy( (char*) maclabel , label ) ;
-               c2pstr( (char*) maclabel ) ;
+               wxString label ;
        
        
+               if( wxApp::s_macDefaultEncodingIsPC )
+                       label = wxMacMakeMacStringFromPC( title ) ;
+               else
+                       label = title ;
+               
+#if TARGET_CARBON
+               c2pstrcpy( (StringPtr) maclabel , label ) ;
+#else
+               strcpy( (char *) maclabel , label ) ;
+               c2pstr( (char *) maclabel ) ;
+#endif
                ::SetControlTitle( m_macControl , maclabel ) ;
        }
                ::SetControlTitle( m_macControl , maclabel ) ;
        }
+       Refresh() ;
 }
 
 }
 
-wxString wxControl::GetLabel() const
+wxSize wxControl::DoGetBestSize() const
 {
 {
-    return m_label ;
+    return wxSize(20, 20);
 }
 
 }
 
-void wxControl::ProcessCommand (wxCommandEvent & event)
+bool wxControl::ProcessCommand (wxCommandEvent & event)
 {
   // Tries:
   // 1) A callback function (to become obsolete)
   // 2) OnCommand, starting at this window and working up parent hierarchy
   // 3) OnCommand then calls ProcessEvent to search the event tables.
 {
   // Tries:
   // 1) A callback function (to become obsolete)
   // 2) OnCommand, starting at this window and working up parent hierarchy
   // 3) OnCommand then calls ProcessEvent to search the event tables.
-  if (m_callback)
+#if WXWIN_COMPATIBILITY
+    if ( m_callback )
     {
     {
-      (void) (*(m_callback)) (*this, event);
+        (void)(*m_callback)(this, event);
+
+        return TRUE;
     }
     else
     }
     else
+#endif // WXWIN_COMPATIBILITY
     {
     {
-      GetEventHandler()->OnCommand(*this, event);
+      return GetEventHandler()->ProcessEvent(event);
     }
 }
 
     }
 }
 
-void wxControl::Centre (int direction)
-{
-  int x, y, width, height, panel_width, panel_height, new_x, new_y;
-
-  wxWindow *parent = (wxWindow *) GetParent ();
-  if (!parent)
-    return;
-
-  parent->GetClientSize (&panel_width, &panel_height);
-  GetSize (&width, &height);
-  GetPosition (&x, &y);
-
-  new_x = x;
-  new_y = y;
-
-  if (direction & wxHORIZONTAL)
-    new_x = (int) ((panel_width - width) / 2);
-
-  if (direction & wxVERTICAL)
-    new_y = (int) ((panel_height - height) / 2);
-
-  SetSize (new_x, new_y, width, height);
-}
-
-void wxControl::SetClientSize (int width, int height)
-{
-  SetSize (-1, -1, width, height);
-}
-
 // ------------------------
 wxList *wxWinMacControlList = NULL;
 wxControl *wxFindControlFromMacControl(ControlHandle inControl )
 // ------------------------
 wxList *wxWinMacControlList = NULL;
 wxControl *wxFindControlFromMacControl(ControlHandle inControl )
@@ -199,22 +220,25 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
        m_y = y ;
                
 
        m_y = y ;
                
 
-       Point localOrigin ;
-       Rect    clipRect ;
-       
        parent->MacClientToRootWindow( &x , &y ) ;
        outBounds->top = y + m_macVerticalBorder ;
        outBounds->left = x + m_macHorizontalBorder ;
        outBounds->bottom = outBounds->top + m_height - 2 * m_macVerticalBorder;
        outBounds->right = outBounds->left + m_width - 2 * m_macHorizontalBorder ;
 
        parent->MacClientToRootWindow( &x , &y ) ;
        outBounds->top = y + m_macVerticalBorder ;
        outBounds->left = x + m_macHorizontalBorder ;
        outBounds->bottom = outBounds->top + m_height - 2 * m_macVerticalBorder;
        outBounds->right = outBounds->left + m_width - 2 * m_macHorizontalBorder ;
 
-       strcpy( (char*) maclabel , label ) ;
+       char c_text[255];
+       strcpy( c_text , label ) ;
        if( wxApp::s_macDefaultEncodingIsPC )
        {
        if( wxApp::s_macDefaultEncodingIsPC )
        {
-               wxMacConvertFromPCForControls( (char*) maclabel ) ;
+               wxMacConvertFromPCForControls( c_text ) ;
        }
 
        }
 
-       c2pstr( (char*) maclabel ) ;
+#if TARGET_CARBON
+       c2pstrcpy( (StringPtr) maclabel , c_text ) ;
+#else
+       strcpy( (char *) maclabel , c_text ) ;
+       c2pstr( (char *) maclabel ) ;
+#endif
 }
 
 void wxControl::MacPostControlCreate()
 }
 
 void wxControl::MacPostControlCreate()
@@ -225,7 +249,7 @@ void wxControl::MacPostControlCreate()
        {
                // no font
        }
        {
                // no font
        }
-       else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) )
+       else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) )
        {
                ControlFontStyleRec             controlstyle ;
                controlstyle.flags = kControlUseFontMask ;
        {
                ControlFontStyleRec             controlstyle ;
                controlstyle.flags = kControlUseFontMask ;
@@ -244,8 +268,10 @@ void wxControl::MacPostControlCreate()
        ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
        wxASSERT_MSG( container != NULL , "No valid mac container control" ) ;
        ::UMAEmbedControl( m_macControl , container ) ;
        ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
        wxASSERT_MSG( container != NULL , "No valid mac container control" ) ;
        ::UMAEmbedControl( m_macControl , container ) ;
+       m_macControlIsShown  = true ;
        MacAdjustControlRect() ;
        wxAssociateControlWithMacControl( m_macControl , this ) ;
        MacAdjustControlRect() ;
        wxAssociateControlWithMacControl( m_macControl , this ) ;
+       UMAShowControl( m_macControl ) ;
 }
 
 void wxControl::MacAdjustControlRect() 
 }
 
 void wxControl::MacAdjustControlRect() 
@@ -278,14 +304,18 @@ void wxControl::MacAdjustControlRect()
                {
                        if ( IsKindOf( CLASSINFO( wxButton ) ) )
                        {
                {
                        if ( IsKindOf( CLASSINFO( wxButton ) ) )
                        {
-                               m_width = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder;
+                               m_width = m_label.Length() * 8 + 12 ;
+                               if ( m_width < 70 )
+                                 m_width = 70 ;
                        }
                        else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
                        {
                                m_width = m_label.Length() * 8 ;
                        }
                        else
                        }
                        else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
                        {
                                m_width = m_label.Length() * 8 ;
                        }
                        else
-                               m_width = bestsize.right - bestsize.left + 2 * m_macHorizontalBorder;
+                               m_width = bestsize.right - bestsize.left ;
+                       
+                       m_width += 2 * m_macHorizontalBorder ;
                }
                if ( m_height == -1 )
                {
                }
                if ( m_height == -1 )
                {
@@ -299,7 +329,7 @@ void wxControl::MacAdjustControlRect()
                wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ;
                if ( helper.Ok() )
                {
                wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ;
                if ( helper.Ok() )
                {
-           UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height -  2 * m_macVerticalBorder ) ;
+               UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height -  2 * m_macVerticalBorder ) ;
                }
        }
 }
                }
        }
 }
@@ -315,8 +345,10 @@ void wxControl::MacSuperChangedPosition()
 {
        if ( m_macControl )
        {
 {
        if ( m_macControl )
        {
-               int former_mac_x = (**m_macControl).contrlRect.left ;
-               int former_mac_y = (**m_macControl).contrlRect.top ;
+               Rect contrlRect ;               
+               GetControlBounds( 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()->MacClientToRootWindow( & mac_x , & mac_y ) ;
                int mac_x = m_x ;
                int mac_y = m_y ;
                GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ;
@@ -328,15 +360,15 @@ void wxControl::MacSuperChangedPosition()
        
                if ( mac_x != former_mac_x || mac_y != former_mac_y )
                {
        
                if ( mac_x != former_mac_x || mac_y != former_mac_y )
                {
-                       {
-                               Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ;
-                               InvalRect( &inval ) ;
-                       }
-               UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ;
-                       {
-                               Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
-                               InvalRect( &inval ) ;
-                       }
+                       {
+                               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 ) ;
+                       {
+                               Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
+                               InvalWindowRect( rootwindow , &inval ) ;
+                       }
                }
                if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) )
                {
                }
                if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) )
                {
@@ -352,6 +384,7 @@ void wxControl::MacSuperChangedPosition()
 
 void wxControl::MacSuperEnabled( bool enabled ) 
 {
 
 void wxControl::MacSuperEnabled( bool enabled ) 
 {
+/*
        if ( m_macControl )
        {
                if ( UMAHasAppearance() )
        if ( m_macControl )
        {
                if ( UMAHasAppearance() )
@@ -380,6 +413,7 @@ void wxControl::MacSuperEnabled( bool enabled )
                }
        }
        wxWindow::MacSuperEnabled( enabled ) ;
                }
        }
        wxWindow::MacSuperEnabled( enabled ) ;
+*/
 }
 
 void  wxControl::MacSuperShown( bool show ) 
 }
 
 void  wxControl::MacSuperShown( bool show ) 
@@ -388,12 +422,19 @@ void  wxControl::MacSuperShown( bool show )
        {
                if ( !show )
                {
        {
                if ( !show )
                {
-                       ::UMAHideControl( m_macControl ) ;
+                       if ( m_macControlIsShown )
+                       {
+                               ::UMAHideControl( m_macControl ) ;
+                               m_macControlIsShown = false ;
+                       }
                }
                else
                {
                }
                else
                {
-                       if ( m_macShown )
+                       if ( MacIsReallyShown() && !m_macControlIsShown )
+                       {
                                ::UMAShowControl( m_macControl ) ;
                                ::UMAShowControl( m_macControl ) ;
+                               m_macControlIsShown = true ;
+                       }
                }
        }
                
                }
        }
                
@@ -419,8 +460,10 @@ void  wxControl::DoSetSize(int x, int y,
        int former_w = m_width ;
        int former_h = m_height ;
        
        int former_w = m_width ;
        int former_h = m_height ;
        
-       int former_mac_x = (**m_macControl).contrlRect.left ;
-       int former_mac_y = (**m_macControl).contrlRect.top ;
+       Rect contrlRect ;               
+       GetControlBounds( m_macControl , &contrlRect ) ; 
+       int former_mac_x = contrlRect.left ;
+       int former_mac_y = contrlRect.top ;
        
   int currentX, currentY;
   GetPosition(&currentX, &currentY);
        
   int currentX, currentY;
   GetPosition(&currentX, &currentY);
@@ -431,9 +474,9 @@ void  wxControl::DoSetSize(int x, int y,
   int actualHeight = height;
   int actualX = x;
   int actualY = y;
   int actualHeight = height;
   int actualX = x;
   int actualY = y;
-  if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+  if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
       actualX = currentX;
       actualX = currentX;
-  if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+  if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
       actualY = currentY;
   if (width == -1)
       actualWidth = currentW ;
       actualY = currentY;
   if (width == -1)
       actualWidth = currentW ;
@@ -444,7 +487,8 @@ void  wxControl::DoSetSize(int x, int y,
                return ;
                
        AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
                return ;
                
        AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
-       wxMacDrawingHelper focus( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ;
+       WindowRef macrootwindow = GetMacRootWindow() ;
+       wxMacDrawingHelper focus( wxFindWinFromMacWindow( macrootwindow ) ) ;
 
        int mac_x = actualX ;
        int mac_y = actualY ;
 
        int mac_x = actualX ;
        int mac_y = actualY ;
@@ -452,15 +496,15 @@ void  wxControl::DoSetSize(int x, int y,
        
        if ( mac_x != former_mac_x || mac_y != former_mac_y )
        {
        
        if ( mac_x != former_mac_x || mac_y != former_mac_y )
        {
-               {
-                       Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ;
-                       InvalRect( &inval ) ;
-               }
-       UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y  + m_macVerticalBorder ) ;
-               {
-                       Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
-                       InvalRect( &inval ) ;
-               }
+               {
+                       Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ;
+                       InvalWindowRect( macrootwindow, &inval ) ;
+               }
+               UMAMoveControl( 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(macrootwindow, &inval ) ;
+               }
        }
 
        if ( actualX != former_x || actualY != former_y )
        }
 
        if ( actualX != former_x || actualY != former_y )
@@ -470,29 +514,29 @@ void  wxControl::DoSetSize(int x, int y,
 
                MacRepositionScrollBars() ;
                // To consider -> should the parameters be the effective or the virtual coordinates (AdjustForParent..)
 
                MacRepositionScrollBars() ;
                // To consider -> should the parameters be the effective or the virtual coordinates (AdjustForParent..)
-    wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
-    event.SetEventObject(this);
-    GetEventHandler()->ProcessEvent(event);
+        wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
+        event.SetEventObject(this);
+        GetEventHandler()->ProcessEvent(event);
        }               
        if ( actualWidth != former_w || actualHeight != former_h )
        {
                {
                        Rect inval = { mac_y , mac_x , mac_y + former_h , mac_x + former_w } ;
        }               
        if ( actualWidth != former_w || actualHeight != former_h )
        {
                {
                        Rect inval = { mac_y , mac_x , mac_y + former_h , mac_x + former_w } ;
-                       InvalRect( &inval ) ;
+                       InvalWindowRect( macrootwindow, &inval ) ;
                }
                m_width = actualWidth ;
                m_height = actualHeight ;
 
                }
                m_width = actualWidth ;
                m_height = actualHeight ;
 
-       UMASizeControl( m_macControl ,  m_width - 2 * m_macHorizontalBorder, m_height -  2 * m_macVerticalBorder ) ;
+               UMASizeControl( m_macControl ,  m_width - 2 * m_macHorizontalBorder, m_height -  2 * m_macVerticalBorder ) ;
                {
                        Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
                {
                        Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
-                       InvalRect( &inval ) ;
+                       InvalWindowRect( macrootwindow , &inval ) ;
                }
 
                MacRepositionScrollBars() ;
                }
 
                MacRepositionScrollBars() ;
-    wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
-    event.SetEventObject(this);
-    GetEventHandler()->ProcessEvent(event);
+        wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
+        event.SetEventObject(this);
+        GetEventHandler()->ProcessEvent(event);
        }
        if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) )
        {
        }
        if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) )
        {
@@ -503,51 +547,46 @@ void  wxControl::DoSetSize(int x, int y,
        }
 }
 
        }
 }
 
-void  wxControl::DoSetClientSize(int width, int height)
-{
-       DoSetSize( -1 , -1 , width , height ) ;
-}
-
 bool  wxControl::Show(bool show) 
 {
 bool  wxControl::Show(bool show) 
 {
-       if ( m_macControl == NULL )
-               return wxWindow::Show( show ) ;
-       
-       if ( m_macShown == show )
-               return TRUE ;
-
-       if ( show )
-               ::UMAShowControl( m_macControl ) ;
-       else
-               ::UMAHideControl( m_macControl ) ;
-
-       return wxWindow::Show( show ) ;
+       if ( !wxWindow::Show( show ) )
+               return FALSE ;
+               
+       if ( m_macControl )
+       {
+               if ( !show )
+               {
+                       if ( m_macControlIsShown )
+                       {
+                               ::UMAHideControl( m_macControl ) ;
+                               m_macControlIsShown = false ;
+                       }
+               }
+               else
+               {
+                       if ( MacIsReallyShown() && !m_macControlIsShown )
+                       {
+                               ::UMAShowControl( m_macControl ) ;
+                               m_macControlIsShown = true ;
+                       }
+               }
+       }
+       return TRUE ;
 }
 
 }
 
-void  wxControl::Enable(bool enable) 
+bool  wxControl::Enable(bool enable) 
 {
 {
-       if ( m_macControl == NULL )
-               return wxWindow::Enable( enable ) ;
-       
-       if ( m_macEnabled == enable )
-               return ;
+    if ( !wxWindow::Enable(enable) )
+        return FALSE;
 
 
-       if ( UMAHasAppearance() )
-       {
-               if ( enable )
-                       ::ActivateControl( m_macControl ) ;
-               else
-                       ::DeactivateControl( m_macControl ) ;
-       }
-       else
+       if ( m_macControl )
        {
                if ( enable )
        {
                if ( enable )
-                       ::HiliteControl( m_macControl , 0 ) ;
+                   UMAActivateControl( m_macControl ) ;
                else
                else
-                       ::HiliteControl( m_macControl , 255 ) ;
+                   UMADeactivateControl( m_macControl ) ;
        }
        }
-
-       return wxWindow::Enable( enable ) ;
+       return TRUE ;
 }
 
 void wxControl::Refresh(bool eraseBack, const wxRect *rect)
 }
 
 void wxControl::Refresh(bool eraseBack, const wxRect *rect)
@@ -562,7 +601,7 @@ void wxControl::Refresh(bool eraseBack, const wxRect *rect)
   }
 }
 
   }
 }
 
-void wxControl::OnPaint(wxPaintEvent& event)
+void wxControl::MacRedrawControl()
 {
        if ( m_macControl )
        {
 {
        if ( m_macControl )
        {
@@ -573,15 +612,16 @@ void wxControl::OnPaint(wxPaintEvent& event)
                        if ( win )
                        {
                                wxMacDrawingHelper help( win ) ;
                        if ( win )
                        {
                                wxMacDrawingHelper help( win ) ;
+                               // the mac control manager always assumes to have the origin at 0,0
                                SetOrigin( 0 , 0 ) ;
                                
                                bool                    hasTabBehind = false ;
                                wxWindow* parent = GetParent() ;
                                while ( parent )
                                {
                                SetOrigin( 0 , 0 ) ;
                                
                                bool                    hasTabBehind = false ;
                                wxWindow* parent = GetParent() ;
                                while ( parent )
                                {
-                                       if( parent->m_macWindowData )
+                                       if( parent->MacGetWindowData() )
                                        {
                                        {
-                                               UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
+                                               UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
                                                break ;
                                        }
                                        
                                                break ;
                                        }
                                        
@@ -596,15 +636,65 @@ void wxControl::OnPaint(wxPaintEvent& event)
                                } 
                                
                                UMADrawControl( m_macControl ) ;
                                } 
                                
                                UMADrawControl( m_macControl ) ;
-                               UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
+                               UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
+                       }
+               }
+       }
+}
+
+void wxControl::OnPaint(wxPaintEvent& event)
+{
+       if ( m_macControl )
+       {
+               WindowRef window = GetMacRootWindow() ;
+               if ( window )
+               {
+                       wxWindow* win = wxFindWinFromMacWindow( window ) ;
+                       if ( win )
+                       {
+                               wxMacDrawingHelper help( win ) ;
+                               // the mac control manager always assumes to have the origin at 0,0
+                               SetOrigin( 0 , 0 ) ;
+
+                               
+                               bool hasTabBehind = false ;
+                               wxWindow* parent = GetParent() ;
+                               while ( parent )
+                               {
+                                       if( parent->MacGetWindowData() )
+                                       {
+                                               UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
+                                               break ;
+                                       }
+                                       
+                                       if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) ||  parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
+                                       {
+                                               if ( ((wxControl*)parent)->m_macControl )
+                                                       SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ;
+                                               break ;
+                                       }
+                                       
+                                       parent = parent->GetParent() ;
+                               } 
+
+                               UMADrawControl( m_macControl ) ;
+                               UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
                        }
                }
        }
        else
        {
                        }
                }
        }
        else
        {
-               wxWindow::OnPaint( event ) ;
+               // wxWindow::OnPaint( event ) ;
        }
 }
        }
 }
+void wxControl::OnEraseBackground(wxEraseEvent& event)
+{
+    // In general, you don't want to erase the background of a control,
+    // or you'll get a flicker.
+    // TODO: move this 'null' function into each control that
+    // might flicker.
+}
+
 
 void  wxControl::OnKeyDown( wxKeyEvent &event ) 
 {
 
 void  wxControl::OnKeyDown( wxKeyEvent &event ) 
 {
@@ -628,7 +718,7 @@ void  wxControl::OnMouseEvent( wxMouseEvent &event )
                return ;
        }
                
                return ;
        }
                
-       if (event.GetEventType() == wxEVT_LEFT_DOWN )
+       if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
        {
                        
                int x = event.m_x ;
        {
                        
                int x = event.m_x ;
@@ -664,10 +754,12 @@ void  wxControl::OnMouseEvent( wxMouseEvent &event )
        
                controlpart = FindControl( localwhere , window , &control ) ;
                {
        
                controlpart = FindControl( localwhere , window , &control ) ;
                {
+               /*
                        if ( AcceptsFocus() && FindFocus() != this )
                        {
                                SetFocus() ;
                        }
                        if ( AcceptsFocus() && FindFocus() != this )
                        {
                                SetFocus() ;
                        }
+               */
                        if ( control && UMAIsControlActive( control ) )
                        {
                                {
                        if ( control && UMAIsControlActive( control ) )
                        {
                                {