]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/bmpbuttn.mm
Applied patch [ 735304 ] wxDisplay::ChangeMode - does not resize full-screen windows
[wxWidgets.git] / src / cocoa / bmpbuttn.mm
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
9 // Licence: wxWindows license
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
19 #import <AppKit/NSButton.h>
20 #import <Foundation/NSString.h>
21
22 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxControl)
23 BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase)
24 END_EVENT_TABLE()
25 WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView)
26
27 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid,
28 const wxBitmap& bitmap, 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:@"Bitmap Button"];
45 [GetNSControl() sizeToFit];
46
47 if(m_parent)
48 m_parent->CocoaAddChild(this);
49
50 return true;
51 }
52
53 wxBitmapButton::~wxBitmapButton()
54 {
55 CocoaRemoveFromParent();
56 SetNSButton(NULL);
57 }
58
59 void wxBitmapButton::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