]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/spinbutt.cpp
Fixed a "comparison is always false" warning
[wxWidgets.git] / src / mac / carbon / spinbutt.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: spinbutt.cpp
3// Purpose: wxSpinButton
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "spinbutt.h"
03e11df5 14#pragma implementation "spinbuttbase.h"
e9576ca5
SC
15#endif
16
17#include "wx/spinbutt.h"
519cb848 18#include "wx/mac/uma.h"
e9576ca5 19
e7549107
SC
20// ============================================================================
21// implementation
22// ============================================================================
23
24// ----------------------------------------------------------------------------
25// wxWin macros
26// ----------------------------------------------------------------------------
27
2f1ae414 28#if !USE_SHARED_LIBRARY
e7549107 29 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
d84afea9 30 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
2f1ae414 31#endif
e9576ca5 32
03e11df5
GD
33wxSpinButton::wxSpinButton()
34 : wxSpinButtonBase()
35{
36}
37
e9576ca5 38bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
e40298d5 39 long style, const wxString& name)
e9576ca5 40{
b45ed7a2
VZ
41 if ( !wxSpinButtonBase::Create(parent, id, pos, size,
42 style, wxDefaultValidator, name) )
43 return false;
44
e9576ca5
SC
45 m_min = 0;
46 m_max = 100;
519cb848 47
e40298d5
JS
48 if (!parent)
49 return FALSE;
50
51 Rect bounds ;
52 Str255 title ;
53
427ff662 54 MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
e40298d5
JS
55
56 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100,
57 kControlLittleArrowsProc , (long) this ) ;
58
427ff662 59 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
e40298d5
JS
60
61 MacPostControlCreate() ;
62
63 return TRUE;
e9576ca5 64}
e40298d5 65
e9576ca5
SC
66wxSpinButton::~wxSpinButton()
67{
68}
69
70// Attributes
71////////////////////////////////////////////////////////////////////////////
72
03e11df5
GD
73int wxSpinButton::GetMin() const
74{
e40298d5 75 return m_min;
03e11df5
GD
76}
77
78int wxSpinButton::GetMax() const
79{
e40298d5 80 return m_max;
03e11df5
GD
81}
82
e9576ca5
SC
83int wxSpinButton::GetValue() const
84{
519cb848 85 return m_value;
e9576ca5
SC
86}
87
88void wxSpinButton::SetValue(int val)
89{
e40298d5 90 m_value = val ;
e9576ca5
SC
91}
92
93void wxSpinButton::SetRange(int minVal, int maxVal)
94{
e40298d5
JS
95 m_min = minVal;
96 m_max = maxVal;
467e3168
SC
97 SetControl32BitMaximum( (ControlHandle) m_macControl , maxVal ) ;
98 SetControl32BitMinimum((ControlHandle) m_macControl , minVal ) ;
e9576ca5
SC
99}
100
a54b0880 101void wxSpinButton::MacHandleValueChanged( int inc )
519cb848 102{
e40298d5 103
a54b0880 104 wxEventType scrollEvent = wxEVT_NULL;
e40298d5
JS
105 int oldValue = m_value ;
106
a54b0880 107 m_value = oldValue + inc;
e40298d5 108
a54b0880
SC
109 if (m_value < m_min)
110 {
e40298d5
JS
111 if ( m_windowStyle & wxSP_WRAP )
112 m_value = m_max;
113 else
114 m_value = m_min;
a54b0880 115 }
e40298d5 116
a54b0880
SC
117 if (m_value > m_max)
118 {
e40298d5
JS
119 if ( m_windowStyle & wxSP_WRAP )
120 m_value = m_min;
121 else
122 m_value = m_max;
a54b0880 123 }
e40298d5 124
92432aa1 125 if ( m_value - oldValue == -1 )
a54b0880 126 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
92432aa1 127 else if ( m_value - oldValue == 1 )
a54b0880
SC
128 scrollEvent = wxEVT_SCROLL_LINEUP ;
129 else
130 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
e40298d5 131
a54b0880 132 wxSpinEvent event(scrollEvent, m_windowId);
e40298d5 133
a54b0880
SC
134 event.SetPosition(m_value);
135 event.SetEventObject( this );
136 if ((GetEventHandler()->ProcessEvent( event )) &&
72d750d4 137 !event.IsAllowed() )
a54b0880
SC
138 {
139 m_value = oldValue ;
140 }
467e3168 141 SetControl32BitValue( (ControlHandle) m_macControl , m_value ) ;
e40298d5 142
72d750d4
SC
143 /* always send a thumbtrack event */
144 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
145 {
146 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
147 wxSpinEvent event2( scrollEvent, GetId());
148 event2.SetPosition( m_value );
149 event2.SetEventObject( this );
150 GetEventHandler()->ProcessEvent( event2 );
151 }
519cb848
SC
152}
153
4b26b60f 154void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
a54b0880 155{
e40298d5
JS
156 if ( (ControlHandle) m_macControl == NULL )
157 return ;
158
159 int nScrollInc = 0;
160
161 switch( controlpart )
162 {
163 case kControlUpButtonPart :
164 nScrollInc = 1;
165 break ;
166 case kControlDownButtonPart :
167 nScrollInc = -1;
168 break ;
169 }
170 MacHandleValueChanged( nScrollInc ) ;
171
a54b0880
SC
172}
173
51abe921
SC
174// ----------------------------------------------------------------------------
175// size calculation
176// ----------------------------------------------------------------------------
177
37e2cb08 178wxSize wxSpinButton::DoGetBestSize() const
51abe921 179{
e40298d5 180 return wxSize(16,24);
51abe921 181}
519cb848 182