]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/button.mm
preliminary implementation of wxEVT_MENU_OPEN/CLOSE for Mac
[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 #import <AppKit/NSButton.h>
20 #include "wx/cocoa/string.h"
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];
44 [GetNSButton() setTitle:wxNSStringWithWxString(label)];
45 [GetNSControl() sizeToFit];
46
47 if(m_parent)
48 m_parent->CocoaAddChild(this);
49
50 return true;
51 }
52
53 wxButton::~wxButton()
54 {
55 CocoaRemoveFromParent();
56 SetNSButton(NULL);
57 }
58
59 void wxButton::Cocoa_wxNSButtonAction(void)
60 {
61 wxLogDebug("YAY!");
62 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
63 InitCommandEvent(event); // event.SetEventObject(this);
64 Command(event);
65 }
66