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 wxCheckBoxBase::wxCheckBoxBase()
29 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
30 BEGIN_EVENT_TABLE(wxCheckBox, wxCheckBoxBase)
32 WX_IMPLEMENT_COCOA_OWNER(wxCheckBox,NSButton,NSControl,NSView)
34 bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid,
35 const wxString& label,
39 const wxValidator& validator,
42 wxAutoNSAutoreleasePool pool;
43 if(!CreateControl(parent,winid,pos,size,style,validator,name))
46 SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
47 [m_cocoaNSView release];
48 [GetNSButton() setButtonType: NSSwitchButton];
49 [GetNSButton() setTitle:wxNSStringWithWxString(wxStripMenuCodes(label))];
50 [GetNSControl() sizeToFit];
53 m_parent->CocoaAddChild(this);
54 SetInitialFrameRect(pos,size);
59 wxCheckBox::~wxCheckBox()
61 DisassociateNSButton(GetNSButton());
64 void wxCheckBox::SetValue(bool value)
67 [GetNSButton() setState: NSOnState];
69 [GetNSButton() setState: NSOffState];
72 bool wxCheckBox::GetValue() const
74 int state = [GetNSButton() state];
75 wxASSERT(state!=NSMixedState);
76 return state==NSOnState;
79 void wxCheckBox::Cocoa_wxNSButtonAction(void)
81 wxLogDebug("Checkbox");
82 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, GetId());
83 InitCommandEvent(event); // event.SetEventObject(this);
84 event.SetInt(GetValue());