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