]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/button_osx.cpp
Never overflow the output buffer in wxBase64Decode().
[wxWidgets.git] / src / osx / button_osx.cpp
... / ...
CommitLineData
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{
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, pos, size, style,
46 validator, name);
47 }
48
49 wxString label(lbl);
50 if (label.empty() && wxIsStockID(id) && !(id == wxID_HELP))
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
58 m_labelOrig =
59 m_label = label ;
60
61 m_peer = wxWidgetImpl::CreateButton( this, parent, id, label, pos, size, style, GetExtraStyle() );
62
63 MacPostControlCreate( pos, size );
64
65 return true;
66}
67
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
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
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
118void wxButton::Command (wxCommandEvent & WXUNUSED(event))
119{
120 m_peer->PerformClick() ;
121 // ProcessCommand(event);
122}
123
124bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
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
144 m_peer = wxWidgetImpl::CreateDisclosureTriangle(this, parent, id, label, pos, size, style, GetExtraStyle() );
145
146 MacPostControlCreate( pos, size );
147 // passing the text in the param doesn't seem to work, so lets do it again
148 SetLabel( label );
149
150 return true;
151}
152
153void wxDisclosureTriangle::SetOpen( bool open )
154{
155 m_peer->SetValue( open ? 1 : 0 );
156}
157
158bool wxDisclosureTriangle::IsOpen() const
159{
160 return m_peer->GetValue() == 1;
161}
162
163bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec) )
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{
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;
184}
185