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 #import <AppKit/NSButton.h>
20 #import <Foundation/NSString.h>
22 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxControl)
23 BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase)
25 WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView)
27 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid,
28 const wxBitmap& bitmap, 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:@"Bitmap Button"];
45 [GetNSControl() sizeToFit];
48 m_parent->CocoaAddChild(this);
53 wxBitmapButton::~wxBitmapButton()
55 CocoaRemoveFromParent();
59 void wxBitmapButton::Cocoa_wxNSButtonAction(void)
62 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
63 InitCommandEvent(event); // event.SetEventObject(this);