]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "spinbutt.h"
14 #pragma implementation "spinbuttbase.h"
17 #include "wx/spinbutt.h"
18 #include "wx/mac/uma.h"
20 // ============================================================================
22 // ============================================================================
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
30 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
33 wxSpinButton::wxSpinButton()
38 bool wxSpinButton::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
39 long style
, const wxString
& name
)
41 m_macIsUserPane
= FALSE
;
43 if ( !wxSpinButtonBase::Create(parent
, id
, pos
, size
,
44 style
, wxDefaultValidator
, name
) )
53 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
55 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, "\p" , true , 0 , 0 , 100,
56 kControlLittleArrowsProc
, (long) this ) ;
58 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
60 MacPostControlCreate(pos
,size
) ;
65 wxSpinButton::~wxSpinButton()
70 ////////////////////////////////////////////////////////////////////////////
72 int wxSpinButton::GetMin() const
77 int wxSpinButton::GetMax() const
82 int wxSpinButton::GetValue() const
87 void wxSpinButton::SetValue(int val
)
92 void wxSpinButton::SetRange(int minVal
, int maxVal
)
96 SetControl32BitMaximum( (ControlRef
) m_macControl
, maxVal
) ;
97 SetControl32BitMinimum((ControlRef
) m_macControl
, minVal
) ;
100 void wxSpinButton::MacHandleValueChanged( int inc
)
103 wxEventType scrollEvent
= wxEVT_NULL
;
104 int oldValue
= m_value
;
106 m_value
= oldValue
+ inc
;
110 if ( m_windowStyle
& wxSP_WRAP
)
118 if ( m_windowStyle
& wxSP_WRAP
)
124 if ( m_value
- oldValue
== -1 )
125 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
126 else if ( m_value
- oldValue
== 1 )
127 scrollEvent
= wxEVT_SCROLL_LINEUP
;
129 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
131 wxSpinEvent
event(scrollEvent
, m_windowId
);
133 event
.SetPosition(m_value
);
134 event
.SetEventObject( this );
135 if ((GetEventHandler()->ProcessEvent( event
)) &&
140 SetControl32BitValue( (ControlRef
) m_macControl
, m_value
) ;
142 /* always send a thumbtrack event */
143 if (scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
145 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
146 wxSpinEvent
event2( scrollEvent
, GetId());
147 event2
.SetPosition( m_value
);
148 event2
.SetEventObject( this );
149 GetEventHandler()->ProcessEvent( event2
);
153 void wxSpinButton::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
155 if ( (ControlRef
) m_macControl
== NULL
)
160 switch( controlpart
)
162 case kControlUpButtonPart
:
165 case kControlDownButtonPart
:
169 MacHandleValueChanged( nScrollInc
) ;
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 wxSize
wxSpinButton::DoGetBestSize() const
179 return wxSize(16,24);