]>
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" | |
16c81607 RN |
13 | |
14 | #if wxUSE_BMPBUTTON | |
15 | ||
da0634c1 DE |
16 | #ifndef WX_PRECOMP |
17 | #include "wx/defs.h" | |
18 | #include "wx/bmpbuttn.h" | |
19 | #include "wx/log.h" | |
20 | #endif | |
21 | ||
c36a70f1 DE |
22 | #include "wx/cocoa/autorelease.h" |
23 | ||
da0634c1 DE |
24 | #import <AppKit/NSButton.h> |
25 | #import <Foundation/NSString.h> | |
26 | ||
27 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxControl) | |
28 | BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase) | |
29 | END_EVENT_TABLE() | |
30 | WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView) | |
31 | ||
32 | bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid, | |
33 | const wxBitmap& bitmap, const wxPoint& pos, | |
34 | const wxSize& size, long style, | |
35 | const wxValidator& validator, const wxString& name) | |
36 | { | |
c36a70f1 | 37 | wxAutoNSAutoreleasePool pool; |
48580976 | 38 | wxLogTrace(wxTRACE_COCOA,wxT("Creating control with id=%d"),winid); |
da0634c1 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()); |
da0634c1 | 42 | m_cocoaNSView = NULL; |
8d656ea9 | 43 | SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); |
da0634c1 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 | ||
7b73db07 DE |
48 | [GetNSButton() setBezelStyle: NSRegularSquareBezelStyle]; |
49 | [GetNSButton() setImage:bitmap.GetNSImage(true)]; | |
da0634c1 DE |
50 | [GetNSControl() sizeToFit]; |
51 | ||
52 | if(m_parent) | |
53 | m_parent->CocoaAddChild(this); | |
8d656ea9 | 54 | SetInitialFrameRect(pos,size); |
da0634c1 DE |
55 | |
56 | return true; | |
57 | } | |
58 | ||
59 | wxBitmapButton::~wxBitmapButton() | |
60 | { | |
911e17c6 | 61 | DisassociateNSButton(GetNSButton()); |
da0634c1 DE |
62 | } |
63 | ||
64 | void wxBitmapButton::Cocoa_wxNSButtonAction(void) | |
65 | { | |
48580976 | 66 | wxLogTrace(wxTRACE_COCOA,wxT("YAY!")); |
da0634c1 DE |
67 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); |
68 | InitCommandEvent(event); // event.SetEventObject(this); | |
69 | Command(event); | |
70 | } | |
71 | ||
16c81607 | 72 | #endif |