]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/bmpbuttn.mm
Minor corrections to XRC format description.
[wxWidgets.git] / src / cocoa / bmpbuttn.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/bmpbuttn.mm
3 // Purpose: wxBitmapButton
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/03/16
7 // Copyright: (c) 2003 David Elliott
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #if wxUSE_BMPBUTTON
14
15 #include "wx/bmpbuttn.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/log.h"
19 #endif
20
21 #include "wx/cocoa/autorelease.h"
22
23 #import <AppKit/NSButton.h>
24 #import <Foundation/NSString.h>
25
26 BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase)
27 END_EVENT_TABLE()
28 WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView)
29
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)
34 {
35 wxAutoNSAutoreleasePool pool;
36 wxLogTrace(wxTRACE_COCOA,wxT("Creating control with id=%d"),winid);
37 if(!CreateControl(parent,winid,pos,size,style,validator,name))
38 return false;
39 wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId());
40 m_cocoaNSView = NULL;
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];
45
46 [GetNSButton() setBezelStyle: NSRegularSquareBezelStyle];
47 [GetNSButton() setImage:bitmap.GetNSImage(true)];
48 [GetNSControl() sizeToFit];
49
50 if(m_parent)
51 m_parent->CocoaAddChild(this);
52 SetInitialFrameRect(pos,size);
53
54 return true;
55 }
56
57 wxBitmapButton::~wxBitmapButton()
58 {
59 DisassociateNSButton(GetNSButton());
60 }
61
62 void wxBitmapButton::Cocoa_wxNSButtonAction(void)
63 {
64 wxLogTrace(wxTRACE_COCOA,wxT("YAY!"));
65 wxCommandEvent event(wxEVT_BUTTON, GetId());
66 InitCommandEvent(event); // event.SetEventObject(this);
67 Command(event);
68 }
69
70 #endif