Added empty base class constructors. This will still be broken for anything
[wxWidgets.git] / src / cocoa / checkbox.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        cocoa/checkbox.mm
3 // Purpose:     wxCheckBox
4 // Author:      David Elliott
5 // Modified by:
6 // Created:     2003/03/16
7 // RCS-ID:      $Id: 
8 // Copyright:   (c) 2003 David Elliott
9 // Licence:     wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13 #ifndef WX_PRECOMP
14     #include "wx/log.h"
15     #include "wx/app.h"
16     #include "wx/checkbox.h"
17 #endif //WX_PRECOMP
18
19 #include "wx/cocoa/autorelease.h"
20 #include "wx/cocoa/string.h"
21
22 #import <AppKit/NSButton.h>
23 #import <Foundation/NSString.h>
24
25 wxCheckBoxBase::wxCheckBoxBase()
26 {
27 }
28
29 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
30 BEGIN_EVENT_TABLE(wxCheckBox, wxCheckBoxBase)
31 END_EVENT_TABLE()
32 WX_IMPLEMENT_COCOA_OWNER(wxCheckBox,NSButton,NSControl,NSView)
33
34 bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid,
35            const wxString& label,
36            const wxPoint& pos,
37            const wxSize& size,
38            long style,
39            const wxValidator& validator,
40            const wxString& name)
41 {
42     wxAutoNSAutoreleasePool pool;
43     if(!CreateControl(parent,winid,pos,size,style,validator,name))
44         return false;
45     m_cocoaNSView = NULL;
46     SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
47     [m_cocoaNSView release];
48     [GetNSButton() setButtonType: NSSwitchButton];
49     [GetNSButton() setTitle:wxNSStringWithWxString(wxStripMenuCodes(label))];
50     [GetNSControl() sizeToFit];
51
52     if(m_parent)
53         m_parent->CocoaAddChild(this);
54     SetInitialFrameRect(pos,size);
55
56     return true;
57 }
58
59 wxCheckBox::~wxCheckBox()
60 {
61     DisassociateNSButton(GetNSButton());
62 }
63
64 void wxCheckBox::SetValue(bool value)
65 {
66     if(value)
67         [GetNSButton() setState: NSOnState];
68     else
69         [GetNSButton() setState: NSOffState];
70 }
71
72 bool wxCheckBox::GetValue() const
73 {
74     int state = [GetNSButton() state];
75     wxASSERT(state!=NSMixedState);
76     return state==NSOnState;
77 }
78
79 void wxCheckBox::Cocoa_wxNSButtonAction(void)
80 {
81     wxLogDebug("Checkbox");
82     wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, GetId());
83     InitCommandEvent(event); //    event.SetEventObject(this);
84     event.SetInt(GetValue());
85     Command(event);
86 }
87