]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/checkbox_osx.cpp
Handle accelerators earlier in keyboard processing code in wxGTK.
[wxWidgets.git] / src / osx / checkbox_osx.cpp
index 0e224f15d74b19bdc6bce4c96f8097121cd76bb2..e45c547eabb633ef3f5ea8758a4357cfba1d3970 100644 (file)
@@ -1,10 +1,10 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        src/mac/carbon/checkbox.cpp
+// Name:        src/osx/checkbox_osx.cpp
 // Purpose:     wxCheckBox
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     04/01/98
-// RCS-ID:      $Id: checkbox.cpp 54129 2008-06-11 19:30:52Z SC $
+// RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
 // Licence:       wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -16,7 +16,6 @@
 #include "wx/checkbox.h"
 #include "wx/osx/private.h"
 
-IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
 
 // Single check box item
@@ -28,15 +27,16 @@ bool wxCheckBox::Create(wxWindow *parent,
     long style,
     const wxValidator& validator,
     const wxString& name)
-{
-    m_macIsUserPane = false ;
-
+{    
+    DontCreatePeer();
+    
     if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) )
         return false;
 
     m_labelOrig = m_label = label ;
 
-    m_peer = wxWidgetImpl::CreateCheckBox( this, parent, id, label, pos, size, style, GetExtraStyle() ) ;
+    WXValidateStyle( &style );
+    SetPeer(wxWidgetImpl::CreateCheckBox( this, parent, id, label, pos, size, style, GetExtraStyle() )) ;
 
     MacPostControlCreate(pos, size) ;
 
@@ -72,44 +72,62 @@ void wxCheckBox::Command(wxCommandEvent & event)
 
 wxCheckBoxState wxCheckBox::DoGet3StateValue() const
 {
-    return (wxCheckBoxState)m_peer->GetValue() ;
+    return (wxCheckBoxState)GetPeer()->GetValue() ;
 }
 
 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val)
 {
-    m_peer->SetValue( val ) ;
+    GetPeer()->SetValue( val ) ;
 }
 
-bool wxCheckBox::HandleClicked( double timestampsec ) 
+bool wxCheckBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
 {
-    wxCheckBoxState origState, newState;
-
-    newState = origState = Get3StateValue();
+    bool sendEvent = true;
+    wxCheckBoxState newState = Get3StateValue();
 
-    switch (origState)
+    if ( !GetPeer()->ButtonClickDidStateChange() )
+    {
+        wxCheckBoxState origState ;
+
+        origState = Get3StateValue();
+
+        switch (origState)
+        {
+            case wxCHK_UNCHECKED:
+                newState = wxCHK_CHECKED;
+                break;
+
+            case wxCHK_CHECKED:
+                // If the style flag to allow the user setting the undetermined state is set,
+                // then set the state to undetermined; otherwise set state to unchecked.
+                newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED;
+                break;
+
+            case wxCHK_UNDETERMINED:
+                newState = wxCHK_UNCHECKED;
+                break;
+
+            default:
+                break;
+        }
+        
+        if (newState == origState)
+            sendEvent = false;
+        else
+            Set3StateValue( newState );
+    }
+    else
     {
-        case wxCHK_UNCHECKED:
+        // in case we cannot avoid this user state change natively (eg cocoa) we intercept it here
+        if ( newState == wxCHK_UNDETERMINED && !Is3rdStateAllowedForUser() )
+        {
             newState = wxCHK_CHECKED;
-            break;
-
-        case wxCHK_CHECKED:
-            // If the style flag to allow the user setting the undetermined state is set,
-            // then set the state to undetermined; otherwise set state to unchecked.
-            newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED;
-            break;
-
-        case wxCHK_UNDETERMINED:
-            newState = wxCHK_UNCHECKED;
-            break;
-
-        default:
-            break;
+            Set3StateValue( newState );
+        }
     }
-
-    if (newState != origState)
+    
+    if (sendEvent)
     {
-        Set3StateValue( newState );
-
         wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
         event.SetInt( newState );
         event.SetEventObject( this );