]>
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 | ||
7fc77f30 DE |
19 | #include "wx/cocoa/autorelease.h" |
20 | ||
fb896a32 | 21 | #import <AppKit/NSButton.h> |
c8cae94c | 22 | #include "wx/cocoa/string.h" |
fb896a32 DE |
23 | |
24 | IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) | |
25 | BEGIN_EVENT_TABLE(wxButton, wxButtonBase) | |
26 | END_EVENT_TABLE() | |
27 | WX_IMPLEMENT_COCOA_OWNER(wxButton,NSButton,NSControl,NSView) | |
28 | ||
29 | bool wxButton::Create(wxWindow *parent, wxWindowID winid, | |
30 | const wxString& label, const wxPoint& pos, | |
31 | const wxSize& size, long style, | |
32 | const wxValidator& validator, const wxString& name) | |
33 | { | |
7fc77f30 | 34 | wxAutoNSAutoreleasePool pool; |
fb896a32 DE |
35 | wxLogDebug("Creating control with id=%d",winid); |
36 | if(!CreateControl(parent,winid,pos,size,style,validator,name)) | |
37 | return false; | |
38 | wxLogDebug("Created control with id=%d",GetId()); | |
39 | NSRect cocoaRect = NSMakeRect(10,10,20,20); | |
40 | m_cocoaNSView = NULL; | |
41 | SetNSButton([[NSButton alloc] initWithFrame: cocoaRect]); | |
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:NSRoundedBezelStyle]; | |
c8cae94c | 47 | [GetNSButton() setTitle:wxNSStringWithWxString(label)]; |
fb896a32 DE |
48 | [GetNSControl() sizeToFit]; |
49 | ||
50 | if(m_parent) | |
51 | m_parent->CocoaAddChild(this); | |
52 | ||
53 | return true; | |
54 | } | |
55 | ||
56 | wxButton::~wxButton() | |
57 | { | |
570aaadf | 58 | DisassociateNSButton(m_cocoaNSView); |
fb896a32 DE |
59 | } |
60 | ||
61 | void wxButton::Cocoa_wxNSButtonAction(void) | |
62 | { | |
63 | wxLogDebug("YAY!"); | |
64 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); | |
65 | InitCommandEvent(event); // event.SetEventObject(this); | |
66 | Command(event); | |
67 | } | |
68 | ||
ce319b6d DE |
69 | wxString wxButton::GetLabel() const |
70 | { | |
71 | return wxString([[GetNSButton() title] lossyCString]); | |
72 | } | |
73 | ||
74 | void wxButton::SetLabel(const wxString& label) | |
75 | { | |
76 | [GetNSButton() setTitle:wxNSStringWithWxString(label)]; | |
77 | } | |
78 | ||
83437648 DE |
79 | wxSize wxButtonBase::GetDefaultSize() |
80 | { | |
81 | // FIXME: stub | |
82 | return wxDefaultSize; | |
83 | } | |
84 |