]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/spinbutt.h"
17 #include "wx/mac/uma.h"
19 // ============================================================================
21 // ============================================================================
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
28 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
30 wxSpinButton::wxSpinButton()
35 bool wxSpinButton::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
36 long style
, const wxString
& name
)
38 if ( !wxSpinButtonBase::Create(parent
, id
, pos
, size
,
39 style
, wxDefaultValidator
, name
) )
51 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
,*( (wxValidator
*) NULL
) , name
, &bounds
, title
) ;
53 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 , 0 , 100,
54 kControlLittleArrowsProc
, (long) this ) ;
56 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
58 MacPostControlCreate() ;
63 wxSpinButton::~wxSpinButton()
68 ////////////////////////////////////////////////////////////////////////////
70 int wxSpinButton::GetMin() const
75 int wxSpinButton::GetMax() const
80 int wxSpinButton::GetValue() const
84 if (n
< m_min
) n
= m_min
;
85 if (n
> m_max
) n
= m_max
;
90 void wxSpinButton::SetValue(int val
)
95 void wxSpinButton::SetRange(int minVal
, int maxVal
)
99 SetControl32BitMaximum( (ControlHandle
) m_macControl
, maxVal
) ;
100 SetControl32BitMinimum((ControlHandle
) m_macControl
, minVal
) ;
103 void wxSpinButton::MacHandleValueChanged( int inc
)
106 wxEventType scrollEvent
= wxEVT_NULL
;
107 int oldValue
= m_value
;
109 m_value
= oldValue
+ inc
;
113 if ( m_windowStyle
& wxSP_WRAP
)
121 if ( m_windowStyle
& wxSP_WRAP
)
127 if ( m_value
- oldValue
== -1 )
128 scrollEvent
= wxEVT_SCROLL_LINEDOWN
;
129 else if ( m_value
- oldValue
== 1 )
130 scrollEvent
= wxEVT_SCROLL_LINEUP
;
132 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
134 wxSpinEvent
event(scrollEvent
, m_windowId
);
136 event
.SetPosition(m_value
);
137 event
.SetEventObject( this );
138 if ((GetEventHandler()->ProcessEvent( event
)) &&
143 SetControl32BitValue( (ControlHandle
) m_macControl
, m_value
) ;
145 /* always send a thumbtrack event */
146 if (scrollEvent
!= wxEVT_SCROLL_THUMBTRACK
)
148 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
149 wxSpinEvent
event2( scrollEvent
, GetId());
150 event2
.SetPosition( m_value
);
151 event2
.SetEventObject( this );
152 GetEventHandler()->ProcessEvent( event2
);
156 void wxSpinButton::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
158 if ( (ControlHandle
) m_macControl
== NULL
)
163 switch( controlpart
)
165 case kControlUpButtonPart
:
168 case kControlDownButtonPart
:
172 MacHandleValueChanged( nScrollInc
) ;
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 wxSize
wxSpinButton::DoGetBestSize() const
182 return wxSize(16,24);
185 #endif // wxUSE_SPINBTN