1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:       wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  13 #pragma implementation "checkbox.h" 
  16 #include "wx/wxprec.h" 
  20 #include "wx/checkbox.h" 
  22 #if !USE_SHARED_LIBRARY 
  23 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
) 
  24 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
) 
  27 #include "wx/mac/uma.h" 
  29 // Single check box item 
  30 bool wxCheckBox::Create(wxWindow 
*parent
, wxWindowID id
, const wxString
& label
, 
  32            const wxSize
& size
, long style
, 
  33            const wxValidator
& validator
, 
  36     m_macIsUserPane 
= FALSE 
; 
  38     if ( !wxCheckBoxBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) ) 
  43     SInt32 maxValue 
= 1 /* kControlCheckboxCheckedValue */; 
  44     if (style 
& wxCHK_3STATE
) 
  45         maxValue 
= 2 /* kControlCheckboxMixedValue */; 
  47     Rect bounds 
= wxMacGetBoundsForControl( this , pos 
, size 
) ; 
  48     m_peer 
= new wxMacControl(this) ; 
  49     verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds 
, 
  50         CFSTR("") , 0 , false , m_peer
->GetControlRefAddr() ) ); 
  52     m_peer
->SetMaximum( maxValue 
) ; 
  54     MacPostControlCreate(pos
,size
) ; 
  59 void wxCheckBox::SetValue(bool val
) 
  63         Set3StateValue(wxCHK_CHECKED
); 
  67         Set3StateValue(wxCHK_UNCHECKED
); 
  71 bool wxCheckBox::GetValue() const 
  73     return (DoGet3StateValue() != 0); 
  76 void wxCheckBox::Command (wxCommandEvent 
& event
) 
  78     int state 
= event
.GetInt(); 
  80     wxCHECK_RET( (state 
== wxCHK_UNCHECKED
) || (state 
== wxCHK_CHECKED
) 
  81         || (state 
== wxCHK_UNDETERMINED
), 
  82         wxT("event.GetInt() returned an invalid checkbox state") ); 
  84     Set3StateValue((wxCheckBoxState
) state
); 
  86     ProcessCommand(event
); 
  89 wxCheckBoxState 
wxCheckBox::DoGet3StateValue() const 
  91     return (wxCheckBoxState
) m_peer
->GetValue() ; 
  94 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val
) 
  96     m_peer
->SetValue( val 
) ; 
  99 wxInt32 
wxCheckBox::MacControlHit(WXEVENTHANDLERREF 
WXUNUSED(handler
) , WXEVENTREF 
WXUNUSED(event
) )  
 101     wxCommandEvent 
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId 
); 
 102     wxCheckBoxState state 
= Get3StateValue(); 
 104     if (state 
== wxCHK_UNCHECKED
) 
 106         state 
= wxCHK_CHECKED
; 
 108     else if (state 
== wxCHK_CHECKED
) 
 110         // If the style flag to allow the user setting the undetermined state 
 111         // is set, then set the state to undetermined. Otherwise set state to 
 113         if ( Is3rdStateAllowedForUser() ) 
 115             state 
= wxCHK_UNDETERMINED
; 
 119             state 
= wxCHK_UNCHECKED
; 
 122     else if (state 
== wxCHK_UNDETERMINED
) 
 124         state 
= wxCHK_UNCHECKED
; 
 126     Set3StateValue(state
); 
 129     event
.SetEventObject(this); 
 130     ProcessCommand(event
); 
 136 bool wxBitmapCheckBox::Create(wxWindow 
*parent
, wxWindowID id
, 
 137                               const wxBitmap 
*label
, 
 139                               const wxSize
& size
, long style
, 
 140                               const wxValidator
& validator
, 
 141                               const wxString
& name
) 
 144     SetValidator(validator
); 
 145     m_windowStyle 
= style
; 
 147     if (parent
) parent
->AddChild(this); 
 150         m_windowId 
= NewControlId(); 
 154     // TODO: Create the bitmap checkbox 
 159 void wxBitmapCheckBox::SetLabel(const wxBitmap 
*bitmap
) 
 162     wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented")); 
 165 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 167     wxControl::SetSize( x 
, y 
, width 
, height 
, sizeFlags 
) ; 
 170 void wxBitmapCheckBox::SetValue(bool val
) 
 173     wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented")); 
 176 bool wxBitmapCheckBox::GetValue() const 
 179     wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));