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