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