]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: spinbutt.cpp | |
3 | // Purpose: wxSpinButton | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
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 | ||
20 | wxSpinButton::wxSpinButton() | |
21 | : wxSpinButtonBase() | |
22 | { | |
23 | } | |
24 | ||
25 | bool 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; | |
39 | ||
40 | m_peer = wxWidgetImpl::CreateSpinButton( this , parent, id, 0, m_min, m_max, pos, size, | |
41 | style, GetExtraStyle() ); | |
42 | ||
43 | MacPostControlCreate( pos, size ); | |
44 | ||
45 | return true; | |
46 | } | |
47 | ||
48 | wxSpinButton::~wxSpinButton() | |
49 | { | |
50 | } | |
51 | ||
52 | void wxSpinButton::SetValue( int val ) | |
53 | { | |
54 | m_peer->SetValue( val ); | |
55 | } | |
56 | ||
57 | int wxSpinButton::GetValue() const | |
58 | { | |
59 | return m_peer->GetValue(); | |
60 | } | |
61 | ||
62 | void 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 ); | |
68 | } | |
69 | ||
70 | void wxSpinButton::SendThumbTrackEvent() | |
71 | { | |
72 | wxSpinEvent event( wxEVT_SCROLL_THUMBTRACK, GetId() ); | |
73 | event.SetPosition( GetValue() ); | |
74 | event.SetEventObject( this ); | |
75 | HandleWindowEvent( event ); | |
76 | } | |
77 | ||
78 | bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec) ) | |
79 | { | |
80 | // all events have already been processed | |
81 | return true; | |
82 | } | |
83 | ||
84 | wxSize wxSpinButton::DoGetBestSize() const | |
85 | { | |
86 | return wxSize( 16, 24 ); | |
87 | } | |
88 | ||
89 | void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent) | |
90 | { | |
91 | int inc = 0; | |
92 | ||
93 | if ( scrollEvent == wxEVT_SCROLL_LINEUP ) | |
94 | { | |
95 | inc = 1; | |
96 | } | |
97 | else if ( scrollEvent == wxEVT_SCROLL_LINEDOWN ) | |
98 | { | |
99 | inc = -1; | |
100 | } | |
101 | ||
102 | // trigger scroll events | |
103 | ||
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 | ||
152 | #endif // wxUSE_SPINBTN |