]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/spinbutt.cpp
avoiding warning for unused var in cocoa build
[wxWidgets.git] / src / osx / 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 #include "wx/wxprec.h"
13
14 #if wxUSE_SPINBTN
15
16 #include "wx/spinbutt.h"
17 #include "wx/osx/private.h"
18
19
20 wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
21 wxWindowMac* parent,
22 wxWindowID id,
23 wxInt32 value,
24 wxInt32 minimum,
25 wxInt32 maximum,
26 const wxPoint& pos,
27 const wxSize& size,
28 long style,
29 long extraStyle)
30 {
31 Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size );
32
33 wxMacControl* peer = new wxMacControl( wxpeer );
34 OSStatus err = CreateLittleArrowsControl(
35 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, value,
36 minimum, maximum, 1, peer->GetControlRefAddr() );
37 verify_noerr( err );
38
39 peer->SetActionProc( GetwxMacLiveScrollbarActionProc() );
40 return peer ;
41 }
42
43 void wxSpinButton::MacHandleControlClick(WXWidget WXUNUSED(control),
44 wxInt16 controlpart,
45 bool WXUNUSED(mouseStillDown))
46 {
47 int inc = 0;
48
49 switch ( controlpart )
50 {
51 case kControlUpButtonPart :
52 inc = 1;
53 break;
54
55 case kControlDownButtonPart :
56 inc = -1;
57 break;
58
59 default:
60 break;
61 }
62
63 // trigger scroll events
64
65 wxEventType scrollEvent = wxEVT_NULL;
66 int oldValue = GetValue() ;
67
68 int newValue = oldValue + inc;
69
70 if (newValue < m_min)
71 {
72 if ( m_windowStyle & wxSP_WRAP )
73 newValue = m_max;
74 else
75 newValue = m_min;
76 }
77
78 if (newValue > m_max)
79 {
80 if ( m_windowStyle & wxSP_WRAP )
81 newValue = m_min;
82 else
83 newValue = m_max;
84 }
85
86 if ( newValue - oldValue == -1 )
87 scrollEvent = wxEVT_SCROLL_LINEDOWN;
88 else if ( newValue - oldValue == 1 )
89 scrollEvent = wxEVT_SCROLL_LINEUP;
90 else
91 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
92
93 // Do not send an event if the value has not actually changed
94 // (Also works for wxSpinCtrl)
95 if ( newValue == oldValue )
96 return;
97
98 if ( scrollEvent != wxEVT_SCROLL_THUMBTRACK )
99 {
100 wxSpinEvent event( scrollEvent, m_windowId );
101
102 event.SetPosition( newValue );
103 event.SetEventObject( this );
104 if ((HandleWindowEvent( event )) && !event.IsAllowed())
105 newValue = oldValue;
106 }
107
108 m_peer->SetValue( newValue );
109
110 // always send a thumbtrack event
111 SendThumbTrackEvent() ;
112 }
113
114 #endif // wxUSE_SPINBTN