1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/checkbox.mm
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/checkbox.h"
19 #include "wx/cocoa/autorelease.h"
20 #include "wx/cocoa/string.h"
22 #import <AppKit/NSButton.h>
23 #import <Foundation/NSString.h>
25 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
26 BEGIN_EVENT_TABLE(wxCheckBox, wxCheckBoxBase)
28 WX_IMPLEMENT_COCOA_OWNER(wxCheckBox,NSButton,NSControl,NSView)
30 bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid,
31 const wxString& label,
35 const wxValidator& validator,
38 wxAutoNSAutoreleasePool pool;
39 if(!CreateControl(parent,winid,pos,size,style,validator,name))
42 SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
43 [m_cocoaNSView release];
44 [GetNSButton() setButtonType: NSSwitchButton];
45 [GetNSButton() setTitle:wxNSStringWithWxString(wxStripMenuCodes(label))];
46 [GetNSControl() sizeToFit];
49 m_parent->CocoaAddChild(this);
50 SetInitialFrameRect(pos,size);
55 wxCheckBox::~wxCheckBox()
57 DisassociateNSButton(GetNSButton());
60 void wxCheckBox::SetValue(bool value)
63 [GetNSButton() setState: NSOnState];
65 [GetNSButton() setState: NSOffState];
68 bool wxCheckBox::GetValue() const
70 int state = [GetNSButton() state];
71 wxASSERT(state!=NSMixedState);
72 return state==NSOnState;
75 void wxCheckBox::Cocoa_wxNSButtonAction(void)
77 wxLogDebug(wxT("Checkbox"));
78 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, GetId());
79 InitCommandEvent(event); // event.SetEventObject(this);
80 event.SetInt(GetValue());