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