]>
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 | 23 | |
096a5624 DE |
24 | wxButtonBase::wxButtonBase() |
25 | { | |
26 | } | |
27 | ||
fb896a32 DE |
28 | IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) |
29 | BEGIN_EVENT_TABLE(wxButton, wxButtonBase) | |
30 | END_EVENT_TABLE() | |
31 | WX_IMPLEMENT_COCOA_OWNER(wxButton,NSButton,NSControl,NSView) | |
32 | ||
33 | bool wxButton::Create(wxWindow *parent, wxWindowID winid, | |
34 | const wxString& label, const wxPoint& pos, | |
35 | const wxSize& size, long style, | |
36 | const wxValidator& validator, const wxString& name) | |
37 | { | |
7fc77f30 | 38 | wxAutoNSAutoreleasePool pool; |
fb896a32 DE |
39 | wxLogDebug("Creating control with id=%d",winid); |
40 | if(!CreateControl(parent,winid,pos,size,style,validator,name)) | |
41 | return false; | |
42 | wxLogDebug("Created control with id=%d",GetId()); | |
fb896a32 | 43 | m_cocoaNSView = NULL; |
8d656ea9 | 44 | SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); |
fb896a32 DE |
45 | // NOTE: YES we want to release this (to match the alloc). |
46 | // DoAddChild(this) will retain us again since addSubView doesn't. | |
47 | [m_cocoaNSView release]; | |
48 | ||
49 | [GetNSButton() setBezelStyle:NSRoundedBezelStyle]; | |
677d7f24 | 50 | [GetNSButton() setTitle:wxNSStringWithWxString(wxStripMenuCodes(label))]; |
fb896a32 DE |
51 | [GetNSControl() sizeToFit]; |
52 | ||
53 | if(m_parent) | |
54 | m_parent->CocoaAddChild(this); | |
8d656ea9 | 55 | SetInitialFrameRect(pos,size); |
fb896a32 DE |
56 | |
57 | return true; | |
58 | } | |
59 | ||
60 | wxButton::~wxButton() | |
61 | { | |
911e17c6 | 62 | DisassociateNSButton(GetNSButton()); |
fb896a32 DE |
63 | } |
64 | ||
65 | void wxButton::Cocoa_wxNSButtonAction(void) | |
66 | { | |
67 | wxLogDebug("YAY!"); | |
68 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); | |
69 | InitCommandEvent(event); // event.SetEventObject(this); | |
70 | Command(event); | |
71 | } | |
72 | ||
ce319b6d DE |
73 | wxString wxButton::GetLabel() const |
74 | { | |
75 | return wxString([[GetNSButton() title] lossyCString]); | |
76 | } | |
77 | ||
78 | void wxButton::SetLabel(const wxString& label) | |
79 | { | |
677d7f24 | 80 | [GetNSButton() setTitle:wxNSStringWithWxString(wxStripMenuCodes(label))]; |
ce319b6d DE |
81 | } |
82 | ||
83437648 DE |
83 | wxSize wxButtonBase::GetDefaultSize() |
84 | { | |
85 | // FIXME: stub | |
86 | return wxDefaultSize; | |
87 | } | |
88 |