]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/classic/spinbutt.cpp
get keys support
[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/spinbutt.h"
18#include "wx/mac/uma.h"
19
20// ============================================================================
21// implementation
22// ============================================================================
23
24// ----------------------------------------------------------------------------
25// wxWin macros
26// ----------------------------------------------------------------------------
27
28#if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
30 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
31#endif
32
33wxSpinButton::wxSpinButton()
34 : wxSpinButtonBase()
35{
36}
37
38bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
39 long style, const wxString& name)
40{
41 if ( !wxSpinButtonBase::Create(parent, id, pos, size,
42 style, wxDefaultValidator, name) )
43 return false;
44
45 m_min = 0;
46 m_max = 100;
47
48 if (!parent)
49 return FALSE;
50
51 Rect bounds ;
52 Str255 title ;
53
54 MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
55
56 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100,
57 kControlLittleArrowsProc , (long) this ) ;
58
59 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
60
61 MacPostControlCreate() ;
62
63 return TRUE;
64}
65
66wxSpinButton::~wxSpinButton()
67{
68}
69
70// Attributes
71////////////////////////////////////////////////////////////////////////////
72
73int wxSpinButton::GetMin() const
74{
75 return m_min;
76}
77
78int wxSpinButton::GetMax() const
79{
80 return m_max;
81}
82
83int wxSpinButton::GetValue() const
84{
85 return m_value;
86}
87
88void wxSpinButton::SetValue(int val)
89{
90 m_value = val ;
91}
92
93void wxSpinButton::SetRange(int minVal, int maxVal)
94{
95 m_min = minVal;
96 m_max = maxVal;
97 SetControl32BitMaximum( (ControlHandle) m_macControl , maxVal ) ;
98 SetControl32BitMinimum((ControlHandle) m_macControl , minVal ) ;
99}
100
101void wxSpinButton::MacHandleValueChanged( int inc )
102{
103
104 wxEventType scrollEvent = wxEVT_NULL;
105 int oldValue = m_value ;
106
107 m_value = oldValue + inc;
108
109 if (m_value < m_min)
110 {
111 if ( m_windowStyle & wxSP_WRAP )
112 m_value = m_max;
113 else
114 m_value = m_min;
115 }
116
117 if (m_value > m_max)
118 {
119 if ( m_windowStyle & wxSP_WRAP )
120 m_value = m_min;
121 else
122 m_value = m_max;
123 }
124
125 if ( m_value - oldValue == -1 )
126 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
127 else if ( m_value - oldValue == 1 )
128 scrollEvent = wxEVT_SCROLL_LINEUP ;
129 else
130 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
131
132 wxSpinEvent event(scrollEvent, m_windowId);
133
134 event.SetPosition(m_value);
135 event.SetEventObject( this );
136 if ((GetEventHandler()->ProcessEvent( event )) &&
137 !event.IsAllowed() )
138 {
139 m_value = oldValue ;
140 }
141 SetControl32BitValue( (ControlHandle) m_macControl , m_value ) ;
142
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 }
152}
153
154void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
155{
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
172}
173
174// ----------------------------------------------------------------------------
175// size calculation
176// ----------------------------------------------------------------------------
177
178wxSize wxSpinButton::DoGetBestSize() const
179{
180 return wxSize(16,24);
181}
182