]> git.saurik.com Git - wxWidgets.git/blame - src/osx/spinbutt_osx.cpp
fixes potential crash under gatekeeper
[wxWidgets.git] / src / osx / spinbutt_osx.cpp
CommitLineData
524c47aa 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/osx/spinbutt_osx.cpp
524c47aa
SC
3// Purpose: wxSpinButton
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
b5b208a1 7// RCS-ID: $Id$
524c47aa
SC
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#if wxUSE_SPINBTN
15
16#include "wx/spinbutt.h"
17#include "wx/osx/private.h"
18
19
524c47aa
SC
20wxSpinButton::wxSpinButton()
21 : wxSpinButtonBase()
22{
23}
24
25bool wxSpinButton::Create( wxWindow *parent,
26 wxWindowID id, const wxPoint& pos, const wxSize& size,
27 long style, const wxString& name )
d15694e8
SC
28{
29 DontCreatePeer();
524c47aa
SC
30 if ( !wxSpinButtonBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
31 return false;
32
33 m_min = 0;
34 m_max = 100;
35
36 if (!parent)
37 return false;
03647350 38
22756322
SC
39 SetPeer(wxWidgetImpl::CreateSpinButton( this , parent, id, 0, m_min, m_max, pos, size,
40 style, GetExtraStyle() ));
03647350 41
524c47aa
SC
42 MacPostControlCreate( pos, size );
43
44 return true;
45}
46
47wxSpinButton::~wxSpinButton()
48{
49}
50
51void wxSpinButton::SetValue( int val )
52{
22756322 53 GetPeer()->SetValue( val );
524c47aa
SC
54}
55
56int wxSpinButton::GetValue() const
57{
22756322 58 return GetPeer()->GetValue();
524c47aa
SC
59}
60
61void wxSpinButton::SetRange(int minVal, int maxVal)
62{
63 m_min = minVal;
64 m_max = maxVal;
22756322
SC
65 GetPeer()->SetMaximum( maxVal );
66 GetPeer()->SetMinimum( minVal );
03647350
VZ
67}
68
69void wxSpinButton::SendThumbTrackEvent()
524c47aa
SC
70{
71 wxSpinEvent event( wxEVT_SCROLL_THUMBTRACK, GetId() );
72 event.SetPosition( GetValue() );
73 event.SetEventObject( this );
74 HandleWindowEvent( event );
75}
76
0faf03bf 77bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
524c47aa 78{
19c7ac3d 79 // all events have already been processed
524c47aa
SC
80 return true;
81}
82
83wxSize wxSpinButton::DoGetBestSize() const
84{
85 return wxSize( 16, 24 );
86}
87
19c7ac3d
SC
88void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent)
89{
90 int inc = 0;
91
03647350 92 if ( scrollEvent == wxEVT_SCROLL_LINEUP )
19c7ac3d
SC
93 {
94 inc = 1;
95 }
96 else if ( scrollEvent == wxEVT_SCROLL_LINEDOWN )
97 {
98 inc = -1;
99 }
03647350 100
19c7ac3d 101 // trigger scroll events
03647350 102
19c7ac3d
SC
103 int oldValue = GetValue() ;
104
105 int newValue = oldValue + inc;
106
107 if (newValue < m_min)
108 {
109 if ( m_windowStyle & wxSP_WRAP )
110 newValue = m_max;
111 else
112 newValue = m_min;
113 }
114
115 if (newValue > m_max)
116 {
117 if ( m_windowStyle & wxSP_WRAP )
118 newValue = m_min;
119 else
120 newValue = m_max;
121 }
122
123 if ( newValue - oldValue == -1 )
124 scrollEvent = wxEVT_SCROLL_LINEDOWN;
125 else if ( newValue - oldValue == 1 )
126 scrollEvent = wxEVT_SCROLL_LINEUP;
127 else
128 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
129
130 // Do not send an event if the value has not actually changed
131 // (Also works for wxSpinCtrl)
132 if ( newValue == oldValue )
133 return;
134
135 if ( scrollEvent != wxEVT_SCROLL_THUMBTRACK )
136 {
137 wxSpinEvent event( scrollEvent, m_windowId );
138
139 event.SetPosition( newValue );
140 event.SetEventObject( this );
141 if ((HandleWindowEvent( event )) && !event.IsAllowed())
142 newValue = oldValue;
143 }
144
22756322 145 GetPeer()->SetValue( newValue );
19c7ac3d
SC
146
147 // always send a thumbtrack event
148 SendThumbTrackEvent() ;
149}
150
524c47aa 151#endif // wxUSE_SPINBTN