]>
Commit | Line | Data |
---|---|---|
da0634c1 DE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: cocoa/bmpbuttn.mm | |
3 | // Purpose: wxBitmapButton | |
4 | // Author: David Elliott | |
5 | // Modified by: | |
6 | // Created: 2003/03/16 | |
7 | // RCS-ID: $Id: | |
8 | // Copyright: (c) 2003 David Elliott | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | #ifndef WX_PRECOMP | |
14 | #include "wx/defs.h" | |
15 | #include "wx/bmpbuttn.h" | |
16 | #include "wx/log.h" | |
17 | #endif | |
18 | ||
c36a70f1 DE |
19 | #include "wx/cocoa/autorelease.h" |
20 | ||
da0634c1 DE |
21 | #import <AppKit/NSButton.h> |
22 | #import <Foundation/NSString.h> | |
23 | ||
24 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxControl) | |
25 | BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase) | |
26 | END_EVENT_TABLE() | |
27 | WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView) | |
28 | ||
1169a919 JS |
29 | wxBitmapButtonBase::wxBitmapButtonBase() |
30 | : m_bmpNormal(), | |
31 | m_bmpSelected(), | |
32 | m_bmpFocus(), | |
33 | m_bmpDisabled(), | |
34 | m_marginX(0), | |
35 | m_marginY(0) | |
36 | { | |
37 | } | |
38 | ||
da0634c1 DE |
39 | bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid, |
40 | const wxBitmap& bitmap, const wxPoint& pos, | |
41 | const wxSize& size, long style, | |
42 | const wxValidator& validator, const wxString& name) | |
43 | { | |
c36a70f1 | 44 | wxAutoNSAutoreleasePool pool; |
da0634c1 DE |
45 | wxLogDebug("Creating control with id=%d",winid); |
46 | if(!CreateControl(parent,winid,pos,size,style,validator,name)) | |
47 | return false; | |
48 | wxLogDebug("Created control with id=%d",GetId()); | |
da0634c1 | 49 | m_cocoaNSView = NULL; |
8d656ea9 | 50 | SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); |
da0634c1 DE |
51 | // NOTE: YES we want to release this (to match the alloc). |
52 | // DoAddChild(this) will retain us again since addSubView doesn't. | |
53 | [m_cocoaNSView release]; | |
54 | ||
55 | [GetNSButton() setBezelStyle:NSRoundedBezelStyle]; | |
56 | [GetNSButton() setTitle:@"Bitmap Button"]; | |
57 | [GetNSControl() sizeToFit]; | |
58 | ||
59 | if(m_parent) | |
60 | m_parent->CocoaAddChild(this); | |
8d656ea9 | 61 | SetInitialFrameRect(pos,size); |
da0634c1 DE |
62 | |
63 | return true; | |
64 | } | |
65 | ||
66 | wxBitmapButton::~wxBitmapButton() | |
67 | { | |
911e17c6 | 68 | DisassociateNSButton(GetNSButton()); |
da0634c1 DE |
69 | } |
70 | ||
71 | void wxBitmapButton::Cocoa_wxNSButtonAction(void) | |
72 | { | |
73 | wxLogDebug("YAY!"); | |
74 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); | |
75 | InitCommandEvent(event); // event.SetEventObject(this); | |
76 | Command(event); | |
77 | } | |
78 |