]> git.saurik.com Git - wxWidgets.git/blame - src/osx/button_osx.cpp
don't include wx/msw/winundef.h when including wx/defs.h from C code (closes #10910)
[wxWidgets.git] / src / osx / button_osx.cpp
CommitLineData
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
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
26IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
27
28bool 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{
8e4c2912
VZ
37 // FIXME: this hack is needed because we're called from
38 // wxBitmapButton::Create() with this style and we currently use a
39 // different wxWidgetImpl method (CreateBitmapButton() rather than
40 // CreateButton()) for creating bitmap buttons, but we really ought
41 // to unify the creation of buttons of all kinds and then remove
42 // this check
43 if ( style & wxBU_NOTEXT )
44 {
45 return wxControl::Create(parent, id, lbl, pos, size, style,
46 validator, name);
47 }
48
e53b3d16 49 wxString label(lbl);
423939b2 50 if (label.empty() && wxIsStockID(id) && !(id == wxID_HELP))
e53b3d16
SC
51 label = wxGetStockLabel(id);
52
53 m_macIsUserPane = false ;
54
55 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
56 return false;
57
85284ca4
VZ
58 m_labelOrig =
59 m_label = label ;
4644cfba 60
e53b3d16
SC
61 m_peer = wxWidgetImpl::CreateButton( this, parent, id, label, pos, size, style, GetExtraStyle() );
62
63 MacPostControlCreate( pos, size );
64
65 return true;
66}
67
85284ca4
VZ
68void wxButton::SetLabel(const wxString& label)
69{
70 if ( GetId() == wxID_HELP || HasFlag(wxBU_NOTEXT) )
71 {
72 // just store the label internally but don't really use it for the
73 // button
74 m_labelOrig =
75 m_label = label;
76 return;
77 }
78
79 wxButtonBase::SetLabel(label);
80}
81
e5d05b90
VZ
82// there is no support for button bitmaps in wxOSX/Carbon so there is no need
83// for these methods there
84#if wxOSX_USE_COCOA
85
86wxBitmap wxButton::DoGetBitmap(State which) const
87{
88 return which == State_Normal ? m_peer->GetBitmap() : wxBitmap();
89}
90
91void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
92{
93 if ( which == State_Normal )
94 m_peer->SetBitmap(bitmap);
95}
96
97void wxButton::DoSetBitmapPosition(wxDirection dir)
98{
99 m_peer->SetBitmapPosition(dir);
100}
101
102#endif // wxOSX_USE_COCOA
103
e53b3d16
SC
104wxWindow *wxButton::SetDefault()
105{
106 wxWindow *btnOldDefault = wxButtonBase::SetDefault();
107
108 if ( btnOldDefault )
109 {
110 btnOldDefault->GetPeer()->SetDefaultButton( false );
111 }
112
113 m_peer->SetDefaultButton( true );
114
115 return btnOldDefault;
116}
117
0faf03bf 118void wxButton::Command (wxCommandEvent & WXUNUSED(event))
e53b3d16
SC
119{
120 m_peer->PerformClick() ;
121 // ProcessCommand(event);
122}
123
0faf03bf 124bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16
SC
125{
126 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
127 event.SetEventObject(this);
128 ProcessCommand(event);
129 return true;
130}
131
132//-------------------------------------------------------
133// wxDisclosureTriangle
134//-------------------------------------------------------
135
136bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxString& label,
137 const wxPoint& pos, const wxSize& size, long style,const wxValidator& validator, const wxString& name )
138{
139 m_macIsUserPane = false ;
140
141 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
142 return false;
143
524c47aa 144 m_peer = wxWidgetImpl::CreateDisclosureTriangle(this, parent, id, label, pos, size, style, GetExtraStyle() );
e53b3d16
SC
145
146 MacPostControlCreate( pos, size );
4644cfba 147 // passing the text in the param doesn't seem to work, so lets do it again
e53b3d16 148 SetLabel( label );
4644cfba 149
e53b3d16
SC
150 return true;
151}
152
153void wxDisclosureTriangle::SetOpen( bool open )
154{
e53b3d16 155 m_peer->SetValue( open ? 1 : 0 );
e53b3d16
SC
156}
157
158bool wxDisclosureTriangle::IsOpen() const
159{
e53b3d16 160 return m_peer->GetValue() == 1;
e53b3d16
SC
161}
162
0faf03bf 163bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16
SC
164{
165 // Just emit button event for now
166 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
167 event.SetEventObject(this);
168 ProcessCommand(event);
169
170 return true;
171}
172
173wxSize wxDisclosureTriangle::DoGetBestSize() const
174{
4644cfba
VZ
175 wxSize size = wxWindow::DoGetBestSize();
176
177 // under Carbon the base class GetBestSize() implementation doesn't seem to
178 // take the label into account at all, correct for it here
179#if wxOSX_USE_CARBON
180 size.x += GetTextExtent(GetLabel()).x;
181#endif // wxOSX_USE_CARBON
182
183 return size;
e53b3d16
SC
184}
185