1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/bmpbuttn.mm
3 // Purpose: wxBitmapButton
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/bmpbuttn.h"
22 #include "wx/cocoa/autorelease.h"
24 #import <AppKit/NSButton.h>
25 #import <Foundation/NSString.h>
27 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxControl)
28 BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase)
30 WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView)
32 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid,
33 const wxBitmap& bitmap, const wxPoint& pos,
34 const wxSize& size, long style,
35 const wxValidator& validator, const wxString& name)
37 wxAutoNSAutoreleasePool pool;
38 wxLogTrace(wxTRACE_COCOA,wxT("Creating control with id=%d"),winid);
39 if(!CreateControl(parent,winid,pos,size,style,validator,name))
41 wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId());
43 SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
44 // NOTE: YES we want to release this (to match the alloc).
45 // DoAddChild(this) will retain us again since addSubView doesn't.
46 [m_cocoaNSView release];
48 [GetNSButton() setBezelStyle: NSRegularSquareBezelStyle];
49 [GetNSButton() setImage:bitmap.GetNSImage(true)];
50 [GetNSControl() sizeToFit];
53 m_parent->CocoaAddChild(this);
54 SetInitialFrameRect(pos,size);
59 wxBitmapButton::~wxBitmapButton()
61 DisassociateNSButton(GetNSButton());
64 void wxBitmapButton::Cocoa_wxNSButtonAction(void)
66 wxLogTrace(wxTRACE_COCOA,wxT("YAY!"));
67 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
68 InitCommandEvent(event); // event.SetEventObject(this);