]>
Commit | Line | Data |
---|---|---|
fb896a32 DE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: cocoa/button.mm | |
3 | // Purpose: wxButton | |
4 | // Author: David Elliott | |
5 | // Modified by: | |
6 | // Created: 2002/12/30 | |
7 | // RCS-ID: $Id: | |
8 | // Copyright: (c) 2002 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/button.h" | |
16 | #include "wx/log.h" | |
17 | #endif | |
18 | ||
19 | #import <AppKit/NSButton.h> | |
c8cae94c | 20 | #include "wx/cocoa/string.h" |
fb896a32 DE |
21 | |
22 | IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) | |
23 | BEGIN_EVENT_TABLE(wxButton, wxButtonBase) | |
24 | END_EVENT_TABLE() | |
25 | WX_IMPLEMENT_COCOA_OWNER(wxButton,NSButton,NSControl,NSView) | |
26 | ||
27 | bool wxButton::Create(wxWindow *parent, wxWindowID winid, | |
28 | const wxString& label, const wxPoint& pos, | |
29 | const wxSize& size, long style, | |
30 | const wxValidator& validator, const wxString& name) | |
31 | { | |
32 | wxLogDebug("Creating control with id=%d",winid); | |
33 | if(!CreateControl(parent,winid,pos,size,style,validator,name)) | |
34 | return false; | |
35 | wxLogDebug("Created control with id=%d",GetId()); | |
36 | NSRect cocoaRect = NSMakeRect(10,10,20,20); | |
37 | m_cocoaNSView = NULL; | |
38 | SetNSButton([[NSButton alloc] initWithFrame: cocoaRect]); | |
39 | // NOTE: YES we want to release this (to match the alloc). | |
40 | // DoAddChild(this) will retain us again since addSubView doesn't. | |
41 | [m_cocoaNSView release]; | |
42 | ||
43 | [GetNSButton() setBezelStyle:NSRoundedBezelStyle]; | |
c8cae94c | 44 | [GetNSButton() setTitle:wxNSStringWithWxString(label)]; |
fb896a32 DE |
45 | [GetNSControl() sizeToFit]; |
46 | ||
47 | if(m_parent) | |
48 | m_parent->CocoaAddChild(this); | |
49 | ||
50 | return true; | |
51 | } | |
52 | ||
53 | wxButton::~wxButton() | |
54 | { | |
570aaadf | 55 | DisassociateNSButton(m_cocoaNSView); |
fb896a32 DE |
56 | } |
57 | ||
58 | void wxButton::Cocoa_wxNSButtonAction(void) | |
59 | { | |
60 | wxLogDebug("YAY!"); | |
61 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); | |
62 | InitCommandEvent(event); // event.SetEventObject(this); | |
63 | Command(event); | |
64 | } | |
65 |