1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/classic/checkbox.cpp 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  18 #include "wx/checkbox.h" 
  20 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
) 
  21 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
) 
  23 #include "wx/mac/uma.h" 
  25 // Single check box item 
  26 bool wxCheckBox::Create(wxWindow 
*parent
, wxWindowID id
, const wxString
& label
, 
  28            const wxSize
& size
, long style
, 
  29            const wxValidator
& validator
, 
  32     if ( !wxCheckBoxBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) ) 
  38     MacPreControlCreate( parent 
, id 
,  label 
, pos 
, size 
,style
, validator 
, name 
, &bounds 
, title 
) ; 
  40     SInt16 maxValue 
= 1 /* kControlCheckboxCheckedValue */; 
  41     if (style 
& wxCHK_3STATE
) 
  43         maxValue 
= 2 /* kControlCheckboxMixedValue */; 
  46     m_macControl 
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds 
, title 
, false , 0 , 0 , maxValue
, 
  47           kControlCheckBoxProc 
, (long) this ) ; 
  49     MacPostControlCreate() ; 
  54 void wxCheckBox::SetValue(bool val
) 
  58         Set3StateValue(wxCHK_CHECKED
); 
  62         Set3StateValue(wxCHK_UNCHECKED
); 
  66 bool wxCheckBox::GetValue() const 
  68     return (DoGet3StateValue() != 0); 
  71 void wxCheckBox::Command (wxCommandEvent 
& event
) 
  73     int state 
= event
.GetInt(); 
  75     wxCHECK_RET( (state 
== wxCHK_UNCHECKED
) || (state 
== wxCHK_CHECKED
) 
  76         || (state 
== wxCHK_UNDETERMINED
), 
  77         wxT("event.GetInt() returned an invalid checkbox state") ); 
  79     Set3StateValue((wxCheckBoxState
) state
); 
  81     ProcessCommand(event
); 
  84 wxCheckBoxState 
wxCheckBox::DoGet3StateValue() const 
  86     return (wxCheckBoxState
) ::GetControl32BitValue( (ControlHandle
) m_macControl 
); 
  89 void wxCheckBox::DoSet3StateValue(wxCheckBoxState val
) 
  91     ::SetControl32BitValue( (ControlHandle
) m_macControl 
, (int) val
) ; 
  95 void wxCheckBox::MacHandleControlClick( WXWidget 
WXUNUSED(control
), wxInt16 
WXUNUSED(controlpart
) , bool WXUNUSED(mouseStillDown
) ) 
  97     wxCommandEvent 
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId 
); 
  98     wxCheckBoxState state 
= Get3StateValue(); 
 100     if (state 
== wxCHK_UNCHECKED
) 
 102         state 
= wxCHK_CHECKED
; 
 104     else if (state 
== wxCHK_CHECKED
) 
 106         // If the style flag to allow the user setting the undetermined state 
 107         // is set, then set the state to undetermined. Otherwise set state to 
 109         if ( Is3rdStateAllowedForUser() ) 
 111             state 
= wxCHK_UNDETERMINED
; 
 115             state 
= wxCHK_UNCHECKED
; 
 118     else if (state 
== wxCHK_UNDETERMINED
) 
 120         state 
= wxCHK_UNCHECKED
; 
 122         Set3StateValue(state
); 
 125     event
.SetEventObject(this); 
 126     ProcessCommand(event
); 
 130 bool wxBitmapCheckBox::Create(wxWindow 
*parent
, wxWindowID id
, 
 131                               const wxBitmap 
*label
, 
 133                               const wxSize
& size
, long style
, 
 134                               const wxValidator
& validator
, 
 135                               const wxString
& name
) 
 138     SetValidator(validator
); 
 139     m_windowStyle 
= style
; 
 141     if (parent
) parent
->AddChild(this); 
 144         m_windowId 
= NewControlId(); 
 148     // TODO: Create the bitmap checkbox 
 153 void wxBitmapCheckBox::SetLabel(const wxBitmap 
*bitmap
) 
 156     wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented")); 
 159 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 161     wxControl::SetSize( x 
, y 
, width 
, height 
, sizeFlags 
) ; 
 164 void wxBitmapCheckBox::SetValue(bool val
) 
 167     wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented")); 
 170 bool wxBitmapCheckBox::GetValue() const 
 173     wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented"));