respect wxBU_NOTEXT style in wxButton
[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 // RCS-ID: $Id: button.cpp 54845 2008-07-30 14:52:41Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/button.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/panel.h"
18 #include "wx/toplevel.h"
19 #include "wx/dcclient.h"
20 #endif
21
22 #include "wx/stockitem.h"
23
24 #include "wx/osx/private.h"
25
26 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
27
28 bool wxButton::Create(wxWindow *parent,
29 wxWindowID id,
30 const wxString& lbl,
31 const wxPoint& pos,
32 const wxSize& size,
33 long style,
34 const wxValidator& validator,
35 const wxString& name)
36 {
37 wxString label(lbl);
38 if (label.empty() && wxIsStockID(id) && !(id == wxID_HELP))
39 label = wxGetStockLabel(id);
40
41 m_macIsUserPane = false ;
42
43 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
44 return false;
45
46 m_labelOrig =
47 m_label = label ;
48
49 m_peer = wxWidgetImpl::CreateButton( this, parent, id, label, pos, size, style, GetExtraStyle() );
50
51 MacPostControlCreate( pos, size );
52
53 return true;
54 }
55
56 void wxButton::SetLabel(const wxString& label)
57 {
58 if ( GetId() == wxID_HELP || HasFlag(wxBU_NOTEXT) )
59 {
60 // just store the label internally but don't really use it for the
61 // button
62 m_labelOrig =
63 m_label = label;
64 return;
65 }
66
67 wxButtonBase::SetLabel(label);
68 }
69
70 wxWindow *wxButton::SetDefault()
71 {
72 wxWindow *btnOldDefault = wxButtonBase::SetDefault();
73
74 if ( btnOldDefault )
75 {
76 btnOldDefault->GetPeer()->SetDefaultButton( false );
77 }
78
79 m_peer->SetDefaultButton( true );
80
81 return btnOldDefault;
82 }
83
84 void wxButton::Command (wxCommandEvent & WXUNUSED(event))
85 {
86 m_peer->PerformClick() ;
87 // ProcessCommand(event);
88 }
89
90 bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
91 {
92 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
93 event.SetEventObject(this);
94 ProcessCommand(event);
95 return true;
96 }
97
98 //-------------------------------------------------------
99 // wxDisclosureTriangle
100 //-------------------------------------------------------
101
102 bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxString& label,
103 const wxPoint& pos, const wxSize& size, long style,const wxValidator& validator, const wxString& name )
104 {
105 m_macIsUserPane = false ;
106
107 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
108 return false;
109
110 m_peer = wxWidgetImpl::CreateDisclosureTriangle(this, parent, id, label, pos, size, style, GetExtraStyle() );
111
112 MacPostControlCreate( pos, size );
113 // passing the text in the param doesn't seem to work, so lets do it again
114 SetLabel( label );
115
116 return true;
117 }
118
119 void wxDisclosureTriangle::SetOpen( bool open )
120 {
121 m_peer->SetValue( open ? 1 : 0 );
122 }
123
124 bool wxDisclosureTriangle::IsOpen() const
125 {
126 return m_peer->GetValue() == 1;
127 }
128
129 bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec) )
130 {
131 // Just emit button event for now
132 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
133 event.SetEventObject(this);
134 ProcessCommand(event);
135
136 return true;
137 }
138
139 wxSize wxDisclosureTriangle::DoGetBestSize() const
140 {
141 wxSize size = wxWindow::DoGetBestSize();
142
143 // under Carbon the base class GetBestSize() implementation doesn't seem to
144 // take the label into account at all, correct for it here
145 #if wxOSX_USE_CARBON
146 size.x += GetTextExtent(GetLabel()).x;
147 #endif // wxOSX_USE_CARBON
148
149 return size;
150 }
151