]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/bmpbuttn.mm
Add wxActivateEvent::GetActivationReason().
[wxWidgets.git] / src / cocoa / bmpbuttn.mm
CommitLineData
da0634c1 1/////////////////////////////////////////////////////////////////////////////
8898456d 2// Name: src/cocoa/bmpbuttn.mm
da0634c1
DE
3// Purpose: wxBitmapButton
4// Author: David Elliott
5// Modified by:
6// Created: 2003/03/16
da0634c1 7// Copyright: (c) 2003 David Elliott
526954c5 8// Licence: wxWindows licence
da0634c1
DE
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
16c81607
RN
12
13#if wxUSE_BMPBUTTON
14
910b0053
WS
15#include "wx/bmpbuttn.h"
16
da0634c1 17#ifndef WX_PRECOMP
da0634c1
DE
18 #include "wx/log.h"
19#endif
20
c36a70f1
DE
21#include "wx/cocoa/autorelease.h"
22
da0634c1
DE
23#import <AppKit/NSButton.h>
24#import <Foundation/NSString.h>
25
da0634c1
DE
26BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase)
27END_EVENT_TABLE()
28WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView)
29
30bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid,
31 const wxBitmap& bitmap, const wxPoint& pos,
32 const wxSize& size, long style,
33 const wxValidator& validator, const wxString& name)
34{
c36a70f1 35 wxAutoNSAutoreleasePool pool;
48580976 36 wxLogTrace(wxTRACE_COCOA,wxT("Creating control with id=%d"),winid);
da0634c1
DE
37 if(!CreateControl(parent,winid,pos,size,style,validator,name))
38 return false;
48580976 39 wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId());
da0634c1 40 m_cocoaNSView = NULL;
8d656ea9 41 SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
da0634c1
DE
42 // NOTE: YES we want to release this (to match the alloc).
43 // DoAddChild(this) will retain us again since addSubView doesn't.
44 [m_cocoaNSView release];
45
7b73db07
DE
46 [GetNSButton() setBezelStyle: NSRegularSquareBezelStyle];
47 [GetNSButton() setImage:bitmap.GetNSImage(true)];
da0634c1
DE
48 [GetNSControl() sizeToFit];
49
50 if(m_parent)
51 m_parent->CocoaAddChild(this);
8d656ea9 52 SetInitialFrameRect(pos,size);
da0634c1
DE
53
54 return true;
55}
56
57wxBitmapButton::~wxBitmapButton()
58{
911e17c6 59 DisassociateNSButton(GetNSButton());
da0634c1
DE
60}
61
62void wxBitmapButton::Cocoa_wxNSButtonAction(void)
63{
48580976 64 wxLogTrace(wxTRACE_COCOA,wxT("YAY!"));
ce7fe42e 65 wxCommandEvent event(wxEVT_BUTTON, GetId());
da0634c1
DE
66 InitCommandEvent(event); // event.SetEventObject(this);
67 Command(event);
68}
69
16c81607 70#endif