]>
Commit | Line | Data |
---|---|---|
da0634c1 DE |
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 | ||
449c5673 DE |
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 | |
da0634c1 | 18 | |
7fc77f30 DE |
19 | #include "wx/cocoa/autorelease.h" |
20 | ||
da0634c1 DE |
21 | #import <AppKit/NSButton.h> |
22 | #import <Foundation/NSString.h> | |
23 | ||
24 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) | |
25 | BEGIN_EVENT_TABLE(wxCheckBox, wxCheckBoxBase) | |
26 | END_EVENT_TABLE() | |
27 | WX_IMPLEMENT_COCOA_OWNER(wxCheckBox,NSButton,NSControl,NSView) | |
28 | ||
29 | bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid, | |
30 | const wxString& label, | |
31 | const wxPoint& pos, | |
32 | const wxSize& size, | |
33 | long style, | |
34 | const wxValidator& validator, | |
35 | const wxString& name) | |
36 | { | |
7fc77f30 | 37 | wxAutoNSAutoreleasePool pool; |
da0634c1 DE |
38 | if(!CreateControl(parent,winid,pos,size,style,validator,name)) |
39 | return false; | |
40 | m_cocoaNSView = NULL; | |
8d656ea9 | 41 | SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); |
da0634c1 DE |
42 | [m_cocoaNSView release]; |
43 | [GetNSButton() setButtonType: NSSwitchButton]; | |
44 | [GetNSButton() setTitle:[NSString stringWithCString: label.c_str()]]; | |
45 | [GetNSControl() sizeToFit]; | |
46 | ||
47 | if(m_parent) | |
48 | m_parent->CocoaAddChild(this); | |
8d656ea9 DE |
49 | SetInitialFrameRect(pos,size); |
50 | ||
da0634c1 DE |
51 | return true; |
52 | } | |
53 | ||
54 | wxCheckBox::~wxCheckBox() | |
55 | { | |
911e17c6 | 56 | DisassociateNSButton(GetNSButton()); |
da0634c1 DE |
57 | } |
58 | ||
a0c6a355 | 59 | void wxCheckBox::SetValue(bool value) |
da0634c1 | 60 | { |
a0c6a355 DE |
61 | if(value) |
62 | [GetNSButton() setState: NSOnState]; | |
63 | else | |
64 | [GetNSButton() setState: NSOffState]; | |
da0634c1 DE |
65 | } |
66 | ||
67 | bool wxCheckBox::GetValue() const | |
68 | { | |
a0c6a355 DE |
69 | int state = [GetNSButton() state]; |
70 | wxASSERT(state!=NSMixedState); | |
71 | return state==NSOnState; | |
da0634c1 DE |
72 | } |
73 | ||
74 | void wxCheckBox::Cocoa_wxNSButtonAction(void) | |
75 | { | |
76 | wxLogDebug("Checkbox"); | |
a0c6a355 DE |
77 | wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, GetId()); |
78 | InitCommandEvent(event); // event.SetEventObject(this); | |
79 | event.SetInt(GetValue()); | |
80 | Command(event); | |
da0634c1 DE |
81 | } |
82 |