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