]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/checkbox.mm
moved compat content to formats, there will be more wx-specific formats
[wxWidgets.git] / src / cocoa / checkbox.mm
index 921a1d3a287c93dc07d97bfec019ccefcfcc8d6a..90dd25fba123634750ad1ebfe00d8fd9dd8045e4 100644 (file)
@@ -35,8 +35,7 @@ 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()]];
@@ -44,6 +43,8 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid,
 
     if(m_parent)
         m_parent->CocoaAddChild(this);
+    SetInitialFrameRect(pos,size);
+
     return true;
 }
 
@@ -52,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);
 }