1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/button.mm
4 // Author: David Elliott
8 // Copyright: (c) 2002 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/button.h"
19 #import <AppKit/NSButton.h>
20 #include "wx/cocoa/string.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
23 BEGIN_EVENT_TABLE(wxButton, wxButtonBase)
25 WX_IMPLEMENT_COCOA_OWNER(wxButton,NSButton,NSControl,NSView)
27 bool wxButton::Create(wxWindow *parent, wxWindowID winid,
28 const wxString& label, const wxPoint& pos,
29 const wxSize& size, long style,
30 const wxValidator& validator, const wxString& name)
32 wxLogDebug("Creating control with id=%d",winid);
33 if(!CreateControl(parent,winid,pos,size,style,validator,name))
35 wxLogDebug("Created control with id=%d",GetId());
36 NSRect cocoaRect = NSMakeRect(10,10,20,20);
38 SetNSButton([[NSButton alloc] initWithFrame: cocoaRect]);
39 // NOTE: YES we want to release this (to match the alloc).
40 // DoAddChild(this) will retain us again since addSubView doesn't.
41 [m_cocoaNSView release];
43 [GetNSButton() setBezelStyle:NSRoundedBezelStyle];
44 [GetNSButton() setTitle:wxNSStringWithWxString(label)];
45 [GetNSControl() sizeToFit];
48 m_parent->CocoaAddChild(this);
55 DisassociateNSButton(m_cocoaNSView);
58 void wxButton::Cocoa_wxNSButtonAction(void)
61 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
62 InitCommandEvent(event); // event.SetEventObject(this);