]> git.saurik.com Git - wxWidgets.git/blob - src/osx/spinbutt_osx.cpp
Fix install_name_tool calls in OS X "make install".
[wxWidgets.git] / src / osx / spinbutt_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/spinbutt_osx.cpp
3 // Purpose: wxSpinButton
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
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
19 wxSpinButton::wxSpinButton()
20 : wxSpinButtonBase()
21 {
22 }
23
24 bool wxSpinButton::Create( wxWindow *parent,
25 wxWindowID id, const wxPoint& pos, const wxSize& size,
26 long style, const wxString& name )
27 {
28 DontCreatePeer();
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;
37
38 SetPeer(wxWidgetImpl::CreateSpinButton( this , parent, id, 0, m_min, m_max, pos, size,
39 style, GetExtraStyle() ));
40
41 MacPostControlCreate( pos, size );
42
43 return true;
44 }
45
46 wxSpinButton::~wxSpinButton()
47 {
48 }
49
50 void wxSpinButton::SetValue( int val )
51 {
52 GetPeer()->SetValue( val );
53 }
54
55 int wxSpinButton::GetValue() const
56 {
57 return GetPeer()->GetValue();
58 }
59
60 void wxSpinButton::SetRange(int minVal, int maxVal)
61 {
62 m_min = minVal;
63 m_max = maxVal;
64 GetPeer()->SetMaximum( maxVal );
65 GetPeer()->SetMinimum( minVal );
66 }
67
68 void wxSpinButton::SendThumbTrackEvent()
69 {
70 wxSpinEvent event( wxEVT_SCROLL_THUMBTRACK, GetId() );
71 event.SetPosition( GetValue() );
72 event.SetEventObject( this );
73 HandleWindowEvent( event );
74 }
75
76 bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
77 {
78 // all events have already been processed
79 return true;
80 }
81
82 wxSize wxSpinButton::DoGetBestSize() const
83 {
84 return wxSize( 16, 24 );
85 }
86
87 void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent)
88 {
89 int inc = 0;
90
91 if ( scrollEvent == wxEVT_SCROLL_LINEUP )
92 {
93 inc = 1;
94 }
95 else if ( scrollEvent == wxEVT_SCROLL_LINEDOWN )
96 {
97 inc = -1;
98 }
99
100 // trigger scroll events
101
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
144 GetPeer()->SetValue( newValue );
145
146 // always send a thumbtrack event
147 SendThumbTrackEvent() ;
148 }
149
150 #endif // wxUSE_SPINBTN