1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/checkbox.mm
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/checkbox.h"
16 #include "wx/cocoa/autorelease.h"
18 #import <AppKit/NSButton.h>
19 #import <Foundation/NSString.h>
21 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
22 BEGIN_EVENT_TABLE(wxCheckBox, wxCheckBoxBase)
24 WX_IMPLEMENT_COCOA_OWNER(wxCheckBox,NSButton,NSControl,NSView)
26 bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid,
27 const wxString& label,
31 const wxValidator& validator,
34 wxAutoNSAutoreleasePool pool;
35 if(!CreateControl(parent,winid,pos,size,style,validator,name))
38 SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
39 [m_cocoaNSView release];
40 [GetNSButton() setButtonType: NSSwitchButton];
41 [GetNSButton() setTitle:[NSString stringWithCString: label.c_str()]];
42 [GetNSControl() sizeToFit];
45 m_parent->CocoaAddChild(this);
46 SetInitialFrameRect(pos,size);
51 wxCheckBox::~wxCheckBox()
53 DisassociateNSButton(m_cocoaNSView);
56 void wxCheckBox::SetValue(bool value)
59 [GetNSButton() setState: NSOnState];
61 [GetNSButton() setState: NSOffState];
64 bool wxCheckBox::GetValue() const
66 int state = [GetNSButton() state];
67 wxASSERT(state!=NSMixedState);
68 return state==NSOnState;
71 void wxCheckBox::Cocoa_wxNSButtonAction(void)
73 wxLogDebug("Checkbox");
74 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, GetId());
75 InitCommandEvent(event); // event.SetEventObject(this);
76 event.SetInt(GetValue());