]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/classic/spinbutt.cpp
*** empty log message ***
[wxWidgets.git] / src / mac / classic / spinbutt.cpp
... / ...
CommitLineData
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#ifdef __GNUG__
13#pragma implementation "spinbutt.h"
14#pragma implementation "spinbuttbase.h"
15#endif
16
17#include "wx/defs.h"
18
19#if wxUSE_SPINBTN
20
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;
51
52 if (!parent)
53 return false;
54
55 Rect bounds ;
56 Str255 title ;
57
58 MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
59
60 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100,
61 kControlLittleArrowsProc , (long) this ) ;
62
63 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
64
65 MacPostControlCreate() ;
66
67 return true;
68}
69
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{
89 return m_value;
90}
91
92void wxSpinButton::SetValue(int val)
93{
94 m_value = val ;
95}
96
97void wxSpinButton::SetRange(int minVal, int maxVal)
98{
99 m_min = minVal;
100 m_max = maxVal;
101 SetControl32BitMaximum( (ControlHandle) m_macControl , maxVal ) ;
102 SetControl32BitMinimum((ControlHandle) m_macControl , minVal ) ;
103}
104
105void wxSpinButton::MacHandleValueChanged( int inc )
106{
107
108 wxEventType scrollEvent = wxEVT_NULL;
109 int oldValue = m_value ;
110
111 m_value = oldValue + inc;
112
113 if (m_value < m_min)
114 {
115 if ( m_windowStyle & wxSP_WRAP )
116 m_value = m_max;
117 else
118 m_value = m_min;
119 }
120
121 if (m_value > m_max)
122 {
123 if ( m_windowStyle & wxSP_WRAP )
124 m_value = m_min;
125 else
126 m_value = m_max;
127 }
128
129 if ( m_value - oldValue == -1 )
130 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
131 else if ( m_value - oldValue == 1 )
132 scrollEvent = wxEVT_SCROLL_LINEUP ;
133 else
134 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
135
136 wxSpinEvent event(scrollEvent, m_windowId);
137
138 event.SetPosition(m_value);
139 event.SetEventObject( this );
140 if ((GetEventHandler()->ProcessEvent( event )) &&
141 !event.IsAllowed() )
142 {
143 m_value = oldValue ;
144 }
145 SetControl32BitValue( (ControlHandle) m_macControl , m_value ) ;
146
147 /* always send a thumbtrack event */
148 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
149 {
150 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
151 wxSpinEvent event2( scrollEvent, GetId());
152 event2.SetPosition( m_value );
153 event2.SetEventObject( this );
154 GetEventHandler()->ProcessEvent( event2 );
155 }
156}
157
158void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
159{
160 if ( (ControlHandle) m_macControl == NULL )
161 return ;
162
163 int nScrollInc = 0;
164
165 switch( controlpart )
166 {
167 case kControlUpButtonPart :
168 nScrollInc = 1;
169 break ;
170 case kControlDownButtonPart :
171 nScrollInc = -1;
172 break ;
173 }
174 MacHandleValueChanged( nScrollInc ) ;
175
176}
177
178// ----------------------------------------------------------------------------
179// size calculation
180// ----------------------------------------------------------------------------
181
182wxSize wxSpinButton::DoGetBestSize() const
183{
184 return wxSize(16,24);
185}
186
187#endif // wxUSE_SPINBTN