X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/570aaadf1ff3f8c3f8ecfea44dbeae64532c82c4..c34e3c7930684745d6aaf4696fc18faa32463d0e:/src/cocoa/checkbox.mm diff --git a/src/cocoa/checkbox.mm b/src/cocoa/checkbox.mm index 71fb5d4dc4..90dd25fba1 100644 --- a/src/cocoa/checkbox.mm +++ b/src/cocoa/checkbox.mm @@ -13,6 +13,8 @@ #include "wx/checkbox.h" #include "wx/log.h" +#include "wx/cocoa/autorelease.h" + #import #import @@ -29,11 +31,11 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid, const wxValidator& validator, const wxString& name) { + wxAutoNSAutoreleasePool pool; if(!CreateControl(parent,winid,pos,size,style,validator,name)) return false; m_cocoaNSView = NULL; - NSRect cocoaRect = NSMakeRect(10,10,20,20); - SetNSButton([[NSButton alloc] initWithFrame: cocoaRect]); + SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); [m_cocoaNSView release]; [GetNSButton() setButtonType: NSSwitchButton]; [GetNSButton() setTitle:[NSString stringWithCString: label.c_str()]]; @@ -41,6 +43,8 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid, if(m_parent) m_parent->CocoaAddChild(this); + SetInitialFrameRect(pos,size); + return true; } @@ -49,17 +53,27 @@ wxCheckBox::~wxCheckBox() DisassociateNSButton(m_cocoaNSView); } -void wxCheckBox::SetValue(bool) +void wxCheckBox::SetValue(bool value) { + if(value) + [GetNSButton() setState: NSOnState]; + else + [GetNSButton() setState: NSOffState]; } bool wxCheckBox::GetValue() const { - return false; + int state = [GetNSButton() state]; + wxASSERT(state!=NSMixedState); + return state==NSOnState; } void wxCheckBox::Cocoa_wxNSButtonAction(void) { wxLogDebug("Checkbox"); + wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, GetId()); + InitCommandEvent(event); // event.SetEventObject(this); + event.SetInt(GetValue()); + Command(event); }