]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
Fixed GetIcon to keep up with return type change on all other platforms.
[wxWidgets.git] / src / mac / carbon / button.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: button.cpp
3// Purpose: wxButton
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
a8e9860d 12#include "wx/wxprec.h"
d8c736e5 13
e9576ca5 14#include "wx/button.h"
03e11df5 15#include "wx/panel.h"
5f7bcb48 16#include "wx/stockitem.h"
e9576ca5 17
e9576ca5 18IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
e9576ca5 19
d497dca4 20#include "wx/mac/uma.h"
e9576ca5
SC
21// Button
22
5f7bcb48 23bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& lbl,
e9576ca5
SC
24 const wxPoint& pos,
25 const wxSize& size, long style,
26 const wxValidator& validator,
27 const wxString& name)
28{
5f7bcb48
VS
29 wxString label(lbl);
30 if (label.empty() && wxIsStockID(id))
31 label = wxGetStockLabel(id);
32
facd6764
SC
33 m_macIsUserPane = FALSE ;
34
b45ed7a2
VZ
35 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
36 return false;
e40298d5 37
facd6764 38 m_label = label ;
e40298d5 39
facd6764 40 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
b905d6cc 41 m_peer = new wxMacControl(this) ;
49e3e2c2
SC
42 if ( id == wxID_HELP )
43 {
44 ControlButtonContentInfo info ;
45 info.contentType = kControlContentIconRef ;
46 GetIconRef(kOnSystemDisk, kSystemIconsCreator, kHelpIcon, &info.u.iconRef);
47 verify_noerr ( CreateRoundButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , kControlRoundButtonNormalSize ,
48 &info , m_peer->GetControlRefAddr() ) );
49 }
50 else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
eed9e479 51 {
2a4c6734
SC
52#if TARGET_API_MAC_OSX
53 //Button height is static in Mac, can't be changed, so we need to force it here
54 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
55 {
56 bounds.bottom = bounds.top + 20 ;
57 m_maxHeight = 20 ;
58 }
59 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
60 {
61 bounds.bottom = bounds.top + 17 ;
62 m_maxHeight = 17 ;
63 }
64 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
65 {
66 bounds.bottom = bounds.top + 15 ;
67 m_maxHeight = 15 ;
68 }
69#endif
5ca0d812 70 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , m_peer->GetControlRefAddr() ) );
eed9e479
SC
71 }
72 else
73 {
74 ControlButtonContentInfo info ;
75 info.contentType = kControlNoContent ;
76 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,CFSTR(""),
5ca0d812 77 kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
eed9e479 78 }
21fd5529
SC
79
80 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
e40298d5 81
facd6764 82 MacPostControlCreate(pos,size) ;
e40298d5 83
519cb848 84 return TRUE;
e9576ca5
SC
85}
86
87void wxButton::SetDefault()
88{
e7549107
SC
89 wxWindow *parent = GetParent();
90 wxButton *btnOldDefault = NULL;
eddd3a9d 91 if ( parent )
e7549107 92 {
eddd3a9d 93 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
c1fb8167 94 wxButton);
eddd3a9d 95 parent->SetDefaultItem(this);
e7549107 96 }
03e11df5 97
21fd5529
SC
98 if ( btnOldDefault )
99 btnOldDefault->m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ;
100 m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 1 ) ;
e9576ca5
SC
101}
102
37e2cb08 103wxSize wxButton::DoGetBestSize() const
51abe921 104{
49e3e2c2
SC
105 if ( GetId() == wxID_HELP )
106 return wxSize( 20 , 20 ) ;
107
6d325d81
SC
108 wxSize sz = GetDefaultSize() ;
109
110 int charspace = 8 ;
111 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
112 {
113 sz.y = 20 ;
114 charspace = 10 ;
115 }
116 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
117 {
118 sz.y = 17 ;
119 charspace = 8 ;
120 }
121 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
122 {
123 sz.y = 15 ;
124 charspace = 8 ;
125 }
facd6764 126
6d325d81 127 Rect bestsize = { 0 , 0 , 0 , 0 } ;
5ca0d812 128 m_peer->GetBestRect( &bestsize ) ;
0a67a93b 129
23866d59 130 int wBtn;
6d325d81
SC
131 if ( EmptyRect( &bestsize ) )
132 {
23866d59 133 wBtn = m_label.Length() * charspace + 12 ;
6d325d81
SC
134 }
135 else
136 {
5ca0d812 137 wBtn = bestsize.right - bestsize.left ;
6d325d81
SC
138 sz.y = bestsize.bottom - bestsize.top ;
139 }
140
141 if (wBtn > sz.x || ( GetWindowStyle() & wxBU_EXACTFIT) )
142 sz.x = wBtn;
143
144 return sz ;
51abe921
SC
145}
146
7c74e7fe
SC
147wxSize wxButton::GetDefaultSize()
148{
0150a5b8 149 int wBtn = 70 ;
e40298d5 150 int hBtn = 20 ;
facd6764 151
7c74e7fe
SC
152 return wxSize(wBtn, hBtn);
153}
154
519cb848 155void wxButton::Command (wxCommandEvent & event)
e9576ca5 156{
21fd5529 157 m_peer->Flash(kControlButtonPart) ;
519cb848 158 ProcessCommand (event);
e9576ca5
SC
159}
160
4c37f124 161wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
e9576ca5 162{
4c37f124
SC
163 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
164 event.SetEventObject(this);
165 ProcessCommand(event);
166 return noErr ;
e9576ca5
SC
167}
168