1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/bmpbuttn.mm
3 // Purpose: wxBitmapButton
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/bmpbuttn.h"
19 #include "wx/cocoa/autorelease.h"
21 #import <AppKit/NSButton.h>
22 #import <Foundation/NSString.h>
24 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxControl)
25 BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase)
27 WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView)
29 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid,
30 const wxBitmap& bitmap, const wxPoint& pos,
31 const wxSize& size, long style,
32 const wxValidator& validator, const wxString& name)
34 wxAutoNSAutoreleasePool pool;
35 wxLogDebug("Creating control with id=%d",winid);
36 if(!CreateControl(parent,winid,pos,size,style,validator,name))
38 wxLogDebug("Created control with id=%d",GetId());
39 NSRect cocoaRect = NSMakeRect(10,10,20,20);
41 SetNSButton([[NSButton alloc] initWithFrame: cocoaRect]);
42 // NOTE: YES we want to release this (to match the alloc).
43 // DoAddChild(this) will retain us again since addSubView doesn't.
44 [m_cocoaNSView release];
46 [GetNSButton() setBezelStyle:NSRoundedBezelStyle];
47 [GetNSButton() setTitle:@"Bitmap Button"];
48 [GetNSControl() sizeToFit];
51 m_parent->CocoaAddChild(this);
56 wxBitmapButton::~wxBitmapButton()
58 DisassociateNSButton(m_cocoaNSView);
61 void wxBitmapButton::Cocoa_wxNSButtonAction(void)
64 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
65 InitCommandEvent(event); // event.SetEventObject(this);