]>
Commit | Line | Data |
---|---|---|
da0634c1 DE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: cocoa/bmpbuttn.mm | |
3 | // Purpose: wxBitmapButton | |
4 | // Author: David Elliott | |
5 | // Modified by: | |
6 | // Created: 2003/03/16 | |
7 | // RCS-ID: $Id: | |
8 | // Copyright: (c) 2003 David Elliott | |
065e208e | 9 | // Licence: wxWidgets licence |
da0634c1 DE |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | #ifndef WX_PRECOMP | |
14 | #include "wx/defs.h" | |
15 | #include "wx/bmpbuttn.h" | |
16 | #include "wx/log.h" | |
17 | #endif | |
18 | ||
c36a70f1 DE |
19 | #include "wx/cocoa/autorelease.h" |
20 | ||
da0634c1 DE |
21 | #import <AppKit/NSButton.h> |
22 | #import <Foundation/NSString.h> | |
23 | ||
24 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxControl) | |
25 | BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase) | |
26 | END_EVENT_TABLE() | |
27 | WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView) | |
28 | ||
29 | bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid, | |
30 | const wxBitmap& bitmap, const wxPoint& pos, | |
31 | const wxSize& size, long style, | |
32 | const wxValidator& validator, const wxString& name) | |
33 | { | |
c36a70f1 | 34 | wxAutoNSAutoreleasePool pool; |
48580976 | 35 | wxLogTrace(wxTRACE_COCOA,wxT("Creating control with id=%d"),winid); |
da0634c1 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()); |
da0634c1 | 39 | m_cocoaNSView = NULL; |
8d656ea9 | 40 | SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); |
da0634c1 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 | ||
7b73db07 DE |
45 | [GetNSButton() setBezelStyle: NSRegularSquareBezelStyle]; |
46 | [GetNSButton() setImage:bitmap.GetNSImage(true)]; | |
da0634c1 DE |
47 | [GetNSControl() sizeToFit]; |
48 | ||
49 | if(m_parent) | |
50 | m_parent->CocoaAddChild(this); | |
8d656ea9 | 51 | SetInitialFrameRect(pos,size); |
da0634c1 DE |
52 | |
53 | return true; | |
54 | } | |
55 | ||
56 | wxBitmapButton::~wxBitmapButton() | |
57 | { | |
911e17c6 | 58 | DisassociateNSButton(GetNSButton()); |
da0634c1 DE |
59 | } |
60 | ||
61 | void wxBitmapButton::Cocoa_wxNSButtonAction(void) | |
62 | { | |
48580976 | 63 | wxLogTrace(wxTRACE_COCOA,wxT("YAY!")); |
da0634c1 DE |
64 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); |
65 | InitCommandEvent(event); // event.SetEventObject(this); | |
66 | Command(event); | |
67 | } | |
68 |