]> git.saurik.com Git - wxWidgets.git/blob - src/osx/button_osx.cpp
Don't use DDEExec registry key in wxMSW wxExecute() if it's empty.
[wxWidgets.git] / src / osx / button_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/button_osx.cpp
3 // Purpose: wxButton
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
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"
19 #include "wx/stattext.h"
20 #endif
21
22 #include "wx/stockitem.h"
23
24 #include "wx/osx/private.h"
25
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
44 bool wxButton::Create(wxWindow *parent,
45 wxWindowID id,
46 const wxString& labelOrig,
47 const wxPoint& pos,
48 const wxSize& size,
49 long style,
50 const wxValidator& validator,
51 const wxString& name)
52 {
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
59 if ( style & wxBU_NOTEXT && !ShouldCreatePeer() )
60 {
61 return wxControl::Create(parent, id, pos, size, style,
62 validator, name);
63 }
64
65 DontCreatePeer();
66
67 m_marginX =
68 m_marginY = 0;
69
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 }
79
80
81 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
82 return false;
83
84 m_labelOrig =
85 m_label = label ;
86
87 SetPeer(wxWidgetImpl::CreateButton( this, parent, id, label, pos, size, style, GetExtraStyle() ));
88
89 MacPostControlCreate( pos, size );
90
91 return true;
92 }
93
94 void wxButton::SetLabel(const wxString& label)
95 {
96 if ( IsHelpButtonWithStandardLabel(GetId(), label) )
97 {
98 // ignore the standard label for the help buttons, it's not used
99 return;
100 }
101
102 wxAnyButton::SetLabel(label);
103 #if wxOSX_USE_COCOA
104 OSXUpdateAfterLabelChange(label);
105 #endif
106 }
107
108 wxWindow *wxButton::SetDefault()
109 {
110 wxWindow *btnOldDefault = wxButtonBase::SetDefault();
111
112 if ( btnOldDefault )
113 {
114 btnOldDefault->GetPeer()->SetDefaultButton( false );
115 }
116
117 GetPeer()->SetDefaultButton( true );
118
119 return btnOldDefault;
120 }
121
122 void wxButton::Command (wxCommandEvent & WXUNUSED(event))
123 {
124 GetPeer()->PerformClick() ;
125 // ProcessCommand(event);
126 }
127
128 bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
129 {
130 wxCommandEvent event(wxEVT_BUTTON, m_windowId);
131 event.SetEventObject(this);
132 ProcessCommand(event);
133 return true;
134 }
135
136 /* static */
137 wxSize wxButtonBase::GetDefaultSize()
138 {
139 return wxAnyButton::GetDefaultSize();
140 }
141
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 )
148 {
149 DontCreatePeer();
150 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
151 return false;
152
153 SetPeer(wxWidgetImpl::CreateDisclosureTriangle(this, parent, id, label, pos, size, style, GetExtraStyle() ));
154
155 MacPostControlCreate( pos, size );
156 // passing the text in the param doesn't seem to work, so let's do it again
157 SetLabel( label );
158
159 return true;
160 }
161
162 void wxDisclosureTriangle::SetOpen( bool open )
163 {
164 GetPeer()->SetValue( open ? 1 : 0 );
165 }
166
167 bool wxDisclosureTriangle::IsOpen() const
168 {
169 return GetPeer()->GetValue() == 1;
170 }
171
172 bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec) )
173 {
174 // Just emit button event for now
175 wxCommandEvent event(wxEVT_BUTTON, m_windowId);
176 event.SetEventObject(this);
177 ProcessCommand(event);
178
179 return true;
180 }
181
182 wxSize wxDisclosureTriangle::DoGetBestSize() const
183 {
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;
193 }
194