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