]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/spinbutt.cpp
make sure we don't have two associations pointing to the same control
[wxWidgets.git] / src / mac / classic / spinbutt.cpp
CommitLineData
2646f485
SC
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
65571936 9// Licence: wxWindows licence
2646f485
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "spinbutt.h"
14#pragma implementation "spinbuttbase.h"
15#endif
16
312ebad4
WS
17#include "wx/defs.h"
18
19#if wxUSE_SPINBTN
20
2646f485
SC
21#include "wx/spinbutt.h"
22#include "wx/mac/uma.h"
23
24// ============================================================================
25// implementation
26// ============================================================================
27
28// ----------------------------------------------------------------------------
29// wxWin macros
30// ----------------------------------------------------------------------------
31
32#if !USE_SHARED_LIBRARY
33 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
34 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
35#endif
36
37wxSpinButton::wxSpinButton()
38 : wxSpinButtonBase()
39{
40}
41
42bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
43 long style, const wxString& name)
44{
45 if ( !wxSpinButtonBase::Create(parent, id, pos, size,
46 style, wxDefaultValidator, name) )
47 return false;
48
49 m_min = 0;
50 m_max = 100;
312ebad4 51
2646f485 52 if (!parent)
312ebad4
WS
53 return false;
54
2646f485
SC
55 Rect bounds ;
56 Str255 title ;
312ebad4 57
2646f485 58 MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
312ebad4
WS
59
60 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100,
2646f485 61 kControlLittleArrowsProc , (long) this ) ;
312ebad4 62
2646f485 63 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
312ebad4 64
2646f485 65 MacPostControlCreate() ;
312ebad4
WS
66
67 return true;
2646f485 68}
312ebad4 69
2646f485
SC
70wxSpinButton::~wxSpinButton()
71{
72}
73
74// Attributes
75////////////////////////////////////////////////////////////////////////////
76
77int wxSpinButton::GetMin() const
78{
79 return m_min;
80}
81
82int wxSpinButton::GetMax() const
83{
84 return m_max;
85}
86
87int wxSpinButton::GetValue() const
88{
6511d307
RR
89 int n = m_value;
90
91 if (n < m_min) n = m_min;
92 if (n > m_max) n = m_max;
93
94 return n;
2646f485
SC
95}
96
97void wxSpinButton::SetValue(int val)
98{
99 m_value = val ;
100}
101
102void wxSpinButton::SetRange(int minVal, int maxVal)
103{
104 m_min = minVal;
105 m_max = maxVal;
106 SetControl32BitMaximum( (ControlHandle) m_macControl , maxVal ) ;
107 SetControl32BitMinimum((ControlHandle) m_macControl , minVal ) ;
108}
109
110void wxSpinButton::MacHandleValueChanged( int inc )
111{
312ebad4 112
2646f485
SC
113 wxEventType scrollEvent = wxEVT_NULL;
114 int oldValue = m_value ;
312ebad4 115
2646f485 116 m_value = oldValue + inc;
312ebad4 117
2646f485
SC
118 if (m_value < m_min)
119 {
120 if ( m_windowStyle & wxSP_WRAP )
121 m_value = m_max;
122 else
123 m_value = m_min;
124 }
312ebad4 125
2646f485
SC
126 if (m_value > m_max)
127 {
128 if ( m_windowStyle & wxSP_WRAP )
129 m_value = m_min;
130 else
131 m_value = m_max;
132 }
312ebad4 133
2646f485
SC
134 if ( m_value - oldValue == -1 )
135 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
136 else if ( m_value - oldValue == 1 )
137 scrollEvent = wxEVT_SCROLL_LINEUP ;
138 else
139 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
312ebad4 140
2646f485 141 wxSpinEvent event(scrollEvent, m_windowId);
312ebad4 142
2646f485
SC
143 event.SetPosition(m_value);
144 event.SetEventObject( this );
145 if ((GetEventHandler()->ProcessEvent( event )) &&
146 !event.IsAllowed() )
147 {
148 m_value = oldValue ;
149 }
150 SetControl32BitValue( (ControlHandle) m_macControl , m_value ) ;
312ebad4 151
2646f485
SC
152 /* always send a thumbtrack event */
153 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
154 {
155 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
156 wxSpinEvent event2( scrollEvent, GetId());
157 event2.SetPosition( m_value );
158 event2.SetEventObject( this );
159 GetEventHandler()->ProcessEvent( event2 );
160 }
161}
162
312ebad4 163void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
2646f485
SC
164{
165 if ( (ControlHandle) m_macControl == NULL )
166 return ;
312ebad4 167
2646f485 168 int nScrollInc = 0;
312ebad4 169
2646f485
SC
170 switch( controlpart )
171 {
172 case kControlUpButtonPart :
173 nScrollInc = 1;
174 break ;
175 case kControlDownButtonPart :
176 nScrollInc = -1;
177 break ;
178 }
179 MacHandleValueChanged( nScrollInc ) ;
312ebad4 180
2646f485
SC
181}
182
183// ----------------------------------------------------------------------------
184// size calculation
185// ----------------------------------------------------------------------------
186
187wxSize wxSpinButton::DoGetBestSize() const
188{
189 return wxSize(16,24);
190}
191
312ebad4 192#endif // wxUSE_SPINBTN