Added empty base class constructors. This will still be broken for anything
[wxWidgets.git] / src / cocoa / button.mm
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 #include "wx/cocoa/autorelease.h"
20
21 #import <AppKit/NSButton.h>
22 #include "wx/cocoa/string.h"
23
24 wxButtonBase::wxButtonBase()
25 {
26 }
27
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 {
38     wxAutoNSAutoreleasePool pool;
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());
43     m_cocoaNSView = NULL;
44     SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
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];
50     [GetNSButton() setTitle:wxNSStringWithWxString(wxStripMenuCodes(label))];
51     [GetNSControl() sizeToFit];
52
53     if(m_parent)
54         m_parent->CocoaAddChild(this);
55     SetInitialFrameRect(pos,size);
56
57     return true;
58 }
59
60 wxButton::~wxButton()
61 {
62     DisassociateNSButton(GetNSButton());
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
73 wxString wxButton::GetLabel() const
74 {
75     return wxString([[GetNSButton() title] lossyCString]);
76 }
77
78 void wxButton::SetLabel(const wxString& label)
79 {
80     [GetNSButton() setTitle:wxNSStringWithWxString(wxStripMenuCodes(label))];
81 }
82
83 wxSize wxButtonBase::GetDefaultSize()
84 {
85     // FIXME: stub
86     return wxDefaultSize;
87 }
88