1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/bmpbuttn.mm
3 // Purpose: wxBitmapButton
4 // Author: David Elliott
7 // Copyright: (c) 2003 David Elliott
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
15 #include "wx/bmpbuttn.h"
21 #include "wx/cocoa/autorelease.h"
23 #import <AppKit/NSButton.h>
24 #import <Foundation/NSString.h>
26 BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase)
28 WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView)
30 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid,
31 const wxBitmap& bitmap, const wxPoint& pos,
32 const wxSize& size, long style,
33 const wxValidator& validator, const wxString& name)
35 wxAutoNSAutoreleasePool pool;
36 wxLogTrace(wxTRACE_COCOA,wxT("Creating control with id=%d"),winid);
37 if(!CreateControl(parent,winid,pos,size,style,validator,name))
39 wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId());
41 SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
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: NSRegularSquareBezelStyle];
47 [GetNSButton() setImage:bitmap.GetNSImage(true)];
48 [GetNSControl() sizeToFit];
51 m_parent->CocoaAddChild(this);
52 SetInitialFrameRect(pos,size);
57 wxBitmapButton::~wxBitmapButton()
59 DisassociateNSButton(GetNSButton());
62 void wxBitmapButton::Cocoa_wxNSButtonAction(void)
64 wxLogTrace(wxTRACE_COCOA,wxT("YAY!"));
65 wxCommandEvent event(wxEVT_BUTTON, GetId());
66 InitCommandEvent(event); // event.SetEventObject(this);