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