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