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