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