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