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