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"
 
  21 #import <AppKit/NSButton.h>
 
  22 #import <Foundation/NSString.h>
 
  24 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
 
  25 BEGIN_EVENT_TABLE(wxCheckBox, wxCheckBoxBase)
 
  27 WX_IMPLEMENT_COCOA_OWNER(wxCheckBox,NSButton,NSControl,NSView)
 
  29 bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid,
 
  30            const wxString& label,
 
  34            const wxValidator& validator,
 
  37     wxAutoNSAutoreleasePool pool;
 
  38     if(!CreateControl(parent,winid,pos,size,style,validator,name))
 
  41     SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
 
  42     [m_cocoaNSView release];
 
  43     [GetNSButton() setButtonType: NSSwitchButton];
 
  44     [GetNSButton() setTitle:[NSString stringWithCString: label.c_str()]];
 
  45     [GetNSControl() sizeToFit];
 
  48         m_parent->CocoaAddChild(this);
 
  49     SetInitialFrameRect(pos,size);
 
  54 wxCheckBox::~wxCheckBox()
 
  56     DisassociateNSButton(GetNSButton());
 
  59 void wxCheckBox::SetValue(bool value)
 
  62         [GetNSButton() setState: NSOnState];
 
  64         [GetNSButton() setState: NSOffState];
 
  67 bool wxCheckBox::GetValue() const
 
  69     int state = [GetNSButton() state];
 
  70     wxASSERT(state!=NSMixedState);
 
  71     return state==NSOnState;
 
  74 void wxCheckBox::Cocoa_wxNSButtonAction(void)
 
  76     wxLogDebug("Checkbox");
 
  77     wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, GetId());
 
  78     InitCommandEvent(event); //    event.SetEventObject(this);
 
  79     event.SetInt(GetValue());