1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/bmpbuttn.mm
3 // Purpose: wxBitmapButton
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows 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 BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase)
29 WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView)
31 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid,
32 const wxBitmap& bitmap, const wxPoint& pos,
33 const wxSize& size, long style,
34 const wxValidator& validator, const wxString& name)
36 wxAutoNSAutoreleasePool pool;
37 wxLogTrace(wxTRACE_COCOA,wxT("Creating control with id=%d"),winid);
38 if(!CreateControl(parent,winid,pos,size,style,validator,name))
40 wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId());
42 SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
43 // NOTE: YES we want to release this (to match the alloc).
44 // DoAddChild(this) will retain us again since addSubView doesn't.
45 [m_cocoaNSView release];
47 [GetNSButton() setBezelStyle: NSRegularSquareBezelStyle];
48 [GetNSButton() setImage:bitmap.GetNSImage(true)];
49 [GetNSControl() sizeToFit];
52 m_parent->CocoaAddChild(this);
53 SetInitialFrameRect(pos,size);
58 wxBitmapButton::~wxBitmapButton()
60 DisassociateNSButton(GetNSButton());
63 void wxBitmapButton::Cocoa_wxNSButtonAction(void)
65 wxLogTrace(wxTRACE_COCOA,wxT("YAY!"));
66 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
67 InitCommandEvent(event); // event.SetEventObject(this);