X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7fc77f30f423b59b826103bd28c57a437c1553ab..243f5c2d917b77474b6d159fc338ec669d70cc91:/src/cocoa/checkbox.mm?ds=sidebyside diff --git a/src/cocoa/checkbox.mm b/src/cocoa/checkbox.mm index 921a1d3a28..04204304f1 100644 --- a/src/cocoa/checkbox.mm +++ b/src/cocoa/checkbox.mm @@ -9,11 +9,15 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -#include "wx/app.h" -#include "wx/checkbox.h" -#include "wx/log.h" +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/app.h" + #include "wx/checkbox.h" +#endif //WX_PRECOMP #include "wx/cocoa/autorelease.h" +#include "wx/cocoa/string.h" #import #import @@ -35,34 +39,45 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid, 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()]]; + [GetNSButton() setTitle:wxNSStringWithWxString(wxStripMenuCodes(label))]; [GetNSControl() sizeToFit]; if(m_parent) m_parent->CocoaAddChild(this); + SetInitialFrameRect(pos,size); + return true; } wxCheckBox::~wxCheckBox() { - DisassociateNSButton(m_cocoaNSView); + DisassociateNSButton(GetNSButton()); } -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); }