]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/spinbutt.cpp
10.4 support for osx-cocoa
[wxWidgets.git] / src / osx / carbon / spinbutt.cpp
CommitLineData
489468fe
SC
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"
524c47aa
SC
17#include "wx/osx/private.h"
18
19
20wxWidgetImplType* 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)
489468fe 30{
524c47aa 31 Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size );
489468fe 32
524c47aa 33 wxMacControl* peer = new wxMacControl( wxpeer );
489468fe 34 OSStatus err = CreateLittleArrowsControl(
524c47aa
SC
35 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, value,
36 minimum, maximum, 1, peer->GetControlRefAddr() );
489468fe
SC
37 verify_noerr( err );
38
524c47aa
SC
39 peer->SetActionProc( GetwxMacLiveScrollbarActionProc() );
40 return peer ;
489468fe
SC
41}
42
524c47aa
SC
43void wxSpinButton::MacHandleControlClick(WXWidget WXUNUSED(control),
44 wxInt16 controlpart,
45 bool WXUNUSED(mouseStillDown))
489468fe 46{
524c47aa 47 int inc = 0;
489468fe 48
524c47aa
SC
49 switch ( controlpart )
50 {
51 case kControlUpButtonPart :
52 inc = 1;
53 break;
489468fe 54
524c47aa
SC
55 case kControlDownButtonPart :
56 inc = -1;
57 break;
489468fe 58
524c47aa
SC
59 default:
60 break;
61 }
62
63 // trigger scroll events
64
489468fe 65 wxEventType scrollEvent = wxEVT_NULL;
524c47aa 66 int oldValue = GetValue() ;
489468fe 67
524c47aa 68 int newValue = oldValue + inc;
489468fe 69
524c47aa 70 if (newValue < m_min)
489468fe
SC
71 {
72 if ( m_windowStyle & wxSP_WRAP )
524c47aa 73 newValue = m_max;
489468fe 74 else
524c47aa 75 newValue = m_min;
489468fe
SC
76 }
77
524c47aa 78 if (newValue > m_max)
489468fe
SC
79 {
80 if ( m_windowStyle & wxSP_WRAP )
524c47aa 81 newValue = m_min;
489468fe 82 else
524c47aa 83 newValue = m_max;
489468fe
SC
84 }
85
524c47aa 86 if ( newValue - oldValue == -1 )
489468fe 87 scrollEvent = wxEVT_SCROLL_LINEDOWN;
524c47aa 88 else if ( newValue - oldValue == 1 )
489468fe
SC
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)
524c47aa 95 if ( newValue == oldValue )
489468fe
SC
96 return;
97
524c47aa 98 if ( scrollEvent != wxEVT_SCROLL_THUMBTRACK )
489468fe 99 {
524c47aa 100 wxSpinEvent event( scrollEvent, m_windowId );
489468fe 101
524c47aa
SC
102 event.SetPosition( newValue );
103 event.SetEventObject( this );
104 if ((HandleWindowEvent( event )) && !event.IsAllowed())
105 newValue = oldValue;
489468fe
SC
106 }
107
524c47aa 108 m_peer->SetValue( newValue );
489468fe 109
524c47aa
SC
110 // always send a thumbtrack event
111 SendThumbTrackEvent() ;
489468fe
SC
112}
113
114#endif // wxUSE_SPINBTN