]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/spinbutt.cpp
removed flags for wxOK etc that interfere with miniframe style
[wxWidgets.git] / src / mac / carbon / spinbutt.cpp
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
33 wxSpinButton::wxSpinButton()
34 : wxSpinButtonBase()
35 {
36 }
37
38 bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
39 long style, const wxString& name)
40 {
41 m_macIsUserPane = FALSE ;
42
43 if ( !wxSpinButtonBase::Create(parent, id, pos, size,
44 style, wxDefaultValidator, name) )
45 return false;
46
47 m_min = 0;
48 m_max = 100;
49
50 if (!parent)
51 return FALSE;
52
53 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
54
55 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 100,
56 kControlLittleArrowsProc , (long) this ) ;
57
58 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
59
60 MacPostControlCreate(pos,size) ;
61
62 return TRUE;
63 }
64
65 wxSpinButton::~wxSpinButton()
66 {
67 }
68
69 // Attributes
70 ////////////////////////////////////////////////////////////////////////////
71
72 int wxSpinButton::GetMin() const
73 {
74 return m_min;
75 }
76
77 int wxSpinButton::GetMax() const
78 {
79 return m_max;
80 }
81
82 int wxSpinButton::GetValue() const
83 {
84 return m_value;
85 }
86
87 void wxSpinButton::SetValue(int val)
88 {
89 m_value = val ;
90 }
91
92 void wxSpinButton::SetRange(int minVal, int maxVal)
93 {
94 m_min = minVal;
95 m_max = maxVal;
96 SetControl32BitMaximum( (ControlRef) m_macControl , maxVal ) ;
97 SetControl32BitMinimum((ControlRef) m_macControl , minVal ) ;
98 }
99
100 void wxSpinButton::MacHandleValueChanged( int inc )
101 {
102
103 wxEventType scrollEvent = wxEVT_NULL;
104 int oldValue = m_value ;
105
106 m_value = oldValue + inc;
107
108 if (m_value < m_min)
109 {
110 if ( m_windowStyle & wxSP_WRAP )
111 m_value = m_max;
112 else
113 m_value = m_min;
114 }
115
116 if (m_value > m_max)
117 {
118 if ( m_windowStyle & wxSP_WRAP )
119 m_value = m_min;
120 else
121 m_value = m_max;
122 }
123
124 if ( m_value - oldValue == -1 )
125 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
126 else if ( m_value - oldValue == 1 )
127 scrollEvent = wxEVT_SCROLL_LINEUP ;
128 else
129 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
130
131 wxSpinEvent event(scrollEvent, m_windowId);
132
133 event.SetPosition(m_value);
134 event.SetEventObject( this );
135 if ((GetEventHandler()->ProcessEvent( event )) &&
136 !event.IsAllowed() )
137 {
138 m_value = oldValue ;
139 }
140 SetControl32BitValue( (ControlRef) m_macControl , m_value ) ;
141
142 /* always send a thumbtrack event */
143 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
144 {
145 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
146 wxSpinEvent event2( scrollEvent, GetId());
147 event2.SetPosition( m_value );
148 event2.SetEventObject( this );
149 GetEventHandler()->ProcessEvent( event2 );
150 }
151 }
152
153 void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
154 {
155 if ( (ControlRef) m_macControl == NULL )
156 return ;
157
158 int nScrollInc = 0;
159
160 switch( controlpart )
161 {
162 case kControlUpButtonPart :
163 nScrollInc = 1;
164 break ;
165 case kControlDownButtonPart :
166 nScrollInc = -1;
167 break ;
168 }
169 MacHandleValueChanged( nScrollInc ) ;
170
171 }
172
173 // ----------------------------------------------------------------------------
174 // size calculation
175 // ----------------------------------------------------------------------------
176
177 wxSize wxSpinButton::DoGetBestSize() const
178 {
179 return wxSize(16,24);
180 }
181