]>
Commit | Line | Data |
---|---|---|
e53b3d16 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/button_osx.cpp | |
3 | // Purpose: wxButton | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
e53b3d16 SC |
7 | // Copyright: (c) Stefan Csomor |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #include "wx/button.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/panel.h" | |
17 | #include "wx/toplevel.h" | |
18 | #include "wx/dcclient.h" | |
01495abf | 19 | #include "wx/stattext.h" |
e53b3d16 SC |
20 | #endif |
21 | ||
22 | #include "wx/stockitem.h" | |
23 | ||
24 | #include "wx/osx/private.h" | |
25 | ||
01495abf VZ |
26 | namespace |
27 | { | |
28 | ||
29 | // Returns true only if the id is wxID_HELP and the label is "Help" or empty. | |
30 | bool IsHelpButtonWithStandardLabel(wxWindowID id, const wxString& label) | |
31 | { | |
32 | if ( id != wxID_HELP ) | |
33 | return false; | |
34 | ||
35 | if ( label.empty() ) | |
36 | return true; | |
37 | ||
38 | const wxString labelText = wxStaticText::GetLabelText(label); | |
39 | return labelText == "Help" || labelText == _("Help"); | |
40 | } | |
41 | ||
42 | } // anonymous namespace | |
43 | ||
e53b3d16 SC |
44 | bool wxButton::Create(wxWindow *parent, |
45 | wxWindowID id, | |
01495abf | 46 | const wxString& labelOrig, |
e53b3d16 SC |
47 | const wxPoint& pos, |
48 | const wxSize& size, | |
49 | long style, | |
50 | const wxValidator& validator, | |
51 | const wxString& name) | |
52 | { | |
8e4c2912 VZ |
53 | // FIXME: this hack is needed because we're called from |
54 | // wxBitmapButton::Create() with this style and we currently use a | |
55 | // different wxWidgetImpl method (CreateBitmapButton() rather than | |
56 | // CreateButton()) for creating bitmap buttons, but we really ought | |
57 | // to unify the creation of buttons of all kinds and then remove | |
58 | // this check | |
ce63f2e9 | 59 | if ( style & wxBU_NOTEXT && !ShouldCreatePeer() ) |
8e4c2912 | 60 | { |
2ac0ac7c | 61 | return wxControl::Create(parent, id, pos, size, style, |
8e4c2912 VZ |
62 | validator, name); |
63 | } | |
64 | ||
ce63f2e9 VZ |
65 | DontCreatePeer(); |
66 | ||
67 | m_marginX = | |
68 | m_marginY = 0; | |
69 | ||
01495abf VZ |
70 | wxString label; |
71 | ||
72 | // Ignore the standard label for help buttons if possible, they use "?" | |
73 | // label under Mac which looks better. | |
74 | if ( !IsHelpButtonWithStandardLabel(id, labelOrig) ) | |
75 | { | |
76 | label = labelOrig.empty() && wxIsStockID(id) ? wxGetStockLabel(id) | |
77 | : labelOrig; | |
78 | } | |
e53b3d16 | 79 | |
e53b3d16 SC |
80 | |
81 | if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) ) | |
82 | return false; | |
83 | ||
85284ca4 VZ |
84 | m_labelOrig = |
85 | m_label = label ; | |
4644cfba | 86 | |
22756322 | 87 | SetPeer(wxWidgetImpl::CreateButton( this, parent, id, label, pos, size, style, GetExtraStyle() )); |
e53b3d16 SC |
88 | |
89 | MacPostControlCreate( pos, size ); | |
90 | ||
91 | return true; | |
92 | } | |
93 | ||
85284ca4 VZ |
94 | void wxButton::SetLabel(const wxString& label) |
95 | { | |
01495abf VZ |
96 | if ( IsHelpButtonWithStandardLabel(GetId(), label) ) |
97 | { | |
98 | // ignore the standard label for the help buttons, it's not used | |
99 | return; | |
100 | } | |
101 | ||
b4354db1 | 102 | wxAnyButton::SetLabel(label); |
0afa3752 | 103 | #if wxOSX_USE_COCOA |
5af80d31 | 104 | OSXUpdateAfterLabelChange(label); |
0afa3752 | 105 | #endif |
f672c969 VZ |
106 | } |
107 | ||
e53b3d16 SC |
108 | wxWindow *wxButton::SetDefault() |
109 | { | |
110 | wxWindow *btnOldDefault = wxButtonBase::SetDefault(); | |
111 | ||
112 | if ( btnOldDefault ) | |
113 | { | |
114 | btnOldDefault->GetPeer()->SetDefaultButton( false ); | |
115 | } | |
116 | ||
22756322 | 117 | GetPeer()->SetDefaultButton( true ); |
e53b3d16 SC |
118 | |
119 | return btnOldDefault; | |
120 | } | |
121 | ||
0faf03bf | 122 | void wxButton::Command (wxCommandEvent & WXUNUSED(event)) |
e53b3d16 | 123 | { |
22756322 | 124 | GetPeer()->PerformClick() ; |
e53b3d16 SC |
125 | // ProcessCommand(event); |
126 | } | |
127 | ||
0faf03bf | 128 | bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec) ) |
e53b3d16 | 129 | { |
ce7fe42e | 130 | wxCommandEvent event(wxEVT_BUTTON, m_windowId); |
e53b3d16 SC |
131 | event.SetEventObject(this); |
132 | ProcessCommand(event); | |
133 | return true; | |
134 | } | |
135 | ||
888cd683 RD |
136 | /* static */ |
137 | wxSize wxButtonBase::GetDefaultSize() | |
138 | { | |
139 | return wxAnyButton::GetDefaultSize(); | |
140 | } | |
141 | ||
e53b3d16 SC |
142 | //------------------------------------------------------- |
143 | // wxDisclosureTriangle | |
144 | //------------------------------------------------------- | |
145 | ||
146 | bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxString& label, | |
147 | const wxPoint& pos, const wxSize& size, long style,const wxValidator& validator, const wxString& name ) | |
d15694e8 SC |
148 | { |
149 | DontCreatePeer(); | |
e53b3d16 SC |
150 | if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) |
151 | return false; | |
152 | ||
22756322 | 153 | SetPeer(wxWidgetImpl::CreateDisclosureTriangle(this, parent, id, label, pos, size, style, GetExtraStyle() )); |
e53b3d16 SC |
154 | |
155 | MacPostControlCreate( pos, size ); | |
4c51a665 | 156 | // passing the text in the param doesn't seem to work, so let's do it again |
e53b3d16 | 157 | SetLabel( label ); |
4644cfba | 158 | |
e53b3d16 SC |
159 | return true; |
160 | } | |
161 | ||
162 | void wxDisclosureTriangle::SetOpen( bool open ) | |
163 | { | |
22756322 | 164 | GetPeer()->SetValue( open ? 1 : 0 ); |
e53b3d16 SC |
165 | } |
166 | ||
167 | bool wxDisclosureTriangle::IsOpen() const | |
168 | { | |
22756322 | 169 | return GetPeer()->GetValue() == 1; |
e53b3d16 SC |
170 | } |
171 | ||
0faf03bf | 172 | bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec) ) |
e53b3d16 SC |
173 | { |
174 | // Just emit button event for now | |
ce7fe42e | 175 | wxCommandEvent event(wxEVT_BUTTON, m_windowId); |
e53b3d16 SC |
176 | event.SetEventObject(this); |
177 | ProcessCommand(event); | |
178 | ||
179 | return true; | |
180 | } | |
181 | ||
182 | wxSize wxDisclosureTriangle::DoGetBestSize() const | |
183 | { | |
4644cfba VZ |
184 | wxSize size = wxWindow::DoGetBestSize(); |
185 | ||
186 | // under Carbon the base class GetBestSize() implementation doesn't seem to | |
187 | // take the label into account at all, correct for it here | |
188 | #if wxOSX_USE_CARBON | |
189 | size.x += GetTextExtent(GetLabel()).x; | |
190 | #endif // wxOSX_USE_CARBON | |
191 | ||
192 | return size; | |
e53b3d16 SC |
193 | } |
194 |