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