]> git.saurik.com Git - wxWidgets.git/blame - src/osx/spinbutt_osx.cpp
implementing turning off of default button as well
[wxWidgets.git] / src / osx / spinbutt_osx.cpp
CommitLineData
524c47aa
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: spinbutt.cpp
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
20IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
21IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
22
23
24wxSpinButton::wxSpinButton()
25 : wxSpinButtonBase()
26{
27}
28
29bool wxSpinButton::Create( wxWindow *parent,
30 wxWindowID id, const wxPoint& pos, const wxSize& size,
31 long style, const wxString& name )
32{
33 m_macIsUserPane = false;
34
35 if ( !wxSpinButtonBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
36 return false;
37
38 m_min = 0;
39 m_max = 100;
40
41 if (!parent)
42 return false;
03647350 43
524c47aa
SC
44 m_peer = wxWidgetImpl::CreateSpinButton( this , parent, id, 0, m_min, m_max, pos, size,
45 style, GetExtraStyle() );
03647350 46
524c47aa
SC
47 MacPostControlCreate( pos, size );
48
49 return true;
50}
51
52wxSpinButton::~wxSpinButton()
53{
54}
55
56void wxSpinButton::SetValue( int val )
57{
58 m_peer->SetValue( val );
59}
60
61int wxSpinButton::GetValue() const
62{
63 return m_peer->GetValue();
64}
65
66void wxSpinButton::SetRange(int minVal, int maxVal)
67{
68 m_min = minVal;
69 m_max = maxVal;
70 m_peer->SetMaximum( maxVal );
71 m_peer->SetMinimum( minVal );
03647350
VZ
72}
73
74void wxSpinButton::SendThumbTrackEvent()
524c47aa
SC
75{
76 wxSpinEvent event( wxEVT_SCROLL_THUMBTRACK, GetId() );
77 event.SetPosition( GetValue() );
78 event.SetEventObject( this );
79 HandleWindowEvent( event );
80}
81
0faf03bf 82bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
524c47aa 83{
19c7ac3d 84 // all events have already been processed
524c47aa
SC
85 return true;
86}
87
88wxSize wxSpinButton::DoGetBestSize() const
89{
90 return wxSize( 16, 24 );
91}
92
19c7ac3d
SC
93void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent)
94{
95 int inc = 0;
96
03647350 97 if ( scrollEvent == wxEVT_SCROLL_LINEUP )
19c7ac3d
SC
98 {
99 inc = 1;
100 }
101 else if ( scrollEvent == wxEVT_SCROLL_LINEDOWN )
102 {
103 inc = -1;
104 }
03647350 105
19c7ac3d 106 // trigger scroll events
03647350 107
19c7ac3d
SC
108 int oldValue = GetValue() ;
109
110 int newValue = oldValue + inc;
111
112 if (newValue < m_min)
113 {
114 if ( m_windowStyle & wxSP_WRAP )
115 newValue = m_max;
116 else
117 newValue = m_min;
118 }
119
120 if (newValue > m_max)
121 {
122 if ( m_windowStyle & wxSP_WRAP )
123 newValue = m_min;
124 else
125 newValue = m_max;
126 }
127
128 if ( newValue - oldValue == -1 )
129 scrollEvent = wxEVT_SCROLL_LINEDOWN;
130 else if ( newValue - oldValue == 1 )
131 scrollEvent = wxEVT_SCROLL_LINEUP;
132 else
133 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
134
135 // Do not send an event if the value has not actually changed
136 // (Also works for wxSpinCtrl)
137 if ( newValue == oldValue )
138 return;
139
140 if ( scrollEvent != wxEVT_SCROLL_THUMBTRACK )
141 {
142 wxSpinEvent event( scrollEvent, m_windowId );
143
144 event.SetPosition( newValue );
145 event.SetEventObject( this );
146 if ((HandleWindowEvent( event )) && !event.IsAllowed())
147 newValue = oldValue;
148 }
149
150 m_peer->SetValue( newValue );
151
152 // always send a thumbtrack event
153 SendThumbTrackEvent() ;
154}
155
524c47aa 156#endif // wxUSE_SPINBTN