]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/spinbutt.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/classic/spinbutt.cpp 
   3 // Purpose:     wxSpinButton 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  20 #include "wx/spinbutt.h" 
  21 #include "wx/mac/uma.h" 
  23 // ============================================================================ 
  25 // ============================================================================ 
  27 // ---------------------------------------------------------------------------- 
  29 // ---------------------------------------------------------------------------- 
  31 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
) 
  32 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
) 
  34 wxSpinButton::wxSpinButton() 
  39 bool wxSpinButton::Create(wxWindow 
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, 
  40         long style
, const wxString
& name
) 
  42     if ( !wxSpinButtonBase::Create(parent
, id
, pos
, size
, 
  43                                    style
, wxDefaultValidator
, name
) ) 
  55     MacPreControlCreate( parent 
, id 
,  wxEmptyString 
, pos 
, size 
,style
,*( (wxValidator
*) NULL 
) , name 
, &bounds 
, title 
) ; 
  57     m_macControl 
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds 
, title 
, false , 0 , 0 , 100, 
  58         kControlLittleArrowsProc 
, (long) this ) ; 
  60     wxASSERT_MSG( (ControlHandle
) m_macControl 
!= NULL 
, wxT("No valid mac control") ) ; 
  62     MacPostControlCreate() ; 
  67 wxSpinButton::~wxSpinButton() 
  72 //////////////////////////////////////////////////////////////////////////// 
  74 int wxSpinButton::GetMin() const 
  79 int wxSpinButton::GetMax() const 
  84 int wxSpinButton::GetValue() const 
  88     if (n 
< m_min
) n 
= m_min
; 
  89     if (n 
> m_max
) n 
= m_max
; 
  94 void wxSpinButton::SetValue(int val
) 
  99 void wxSpinButton::SetRange(int minVal
, int maxVal
) 
 103     SetControl32BitMaximum( (ControlHandle
) m_macControl 
, maxVal 
) ; 
 104     SetControl32BitMinimum((ControlHandle
) m_macControl 
, minVal 
) ; 
 107 void wxSpinButton::MacHandleValueChanged( int inc 
) 
 110     wxEventType scrollEvent 
= wxEVT_NULL
; 
 111     int oldValue 
= m_value 
; 
 113     m_value 
= oldValue 
+ inc
; 
 117         if ( m_windowStyle 
& wxSP_WRAP 
) 
 125         if ( m_windowStyle 
& wxSP_WRAP 
) 
 131     if ( m_value 
- oldValue 
== -1 ) 
 132         scrollEvent 
= wxEVT_SCROLL_LINEDOWN 
; 
 133     else if ( m_value 
- oldValue 
== 1 ) 
 134         scrollEvent 
= wxEVT_SCROLL_LINEUP 
; 
 136         scrollEvent 
= wxEVT_SCROLL_THUMBTRACK 
; 
 138     wxSpinEvent 
event(scrollEvent
, m_windowId
); 
 140     event
.SetPosition(m_value
); 
 141     event
.SetEventObject( this ); 
 142     if ((GetEventHandler()->ProcessEvent( event 
)) && 
 147     SetControl32BitValue( (ControlHandle
) m_macControl 
, m_value 
) ; 
 149     /* always send a thumbtrack event */ 
 150     if (scrollEvent 
!= wxEVT_SCROLL_THUMBTRACK
) 
 152         scrollEvent 
= wxEVT_SCROLL_THUMBTRACK
; 
 153         wxSpinEvent 
event2( scrollEvent
, GetId()); 
 154         event2
.SetPosition( m_value 
); 
 155         event2
.SetEventObject( this ); 
 156         GetEventHandler()->ProcessEvent( event2 
); 
 160 void wxSpinButton::MacHandleControlClick( WXWidget control 
, wxInt16 controlpart 
, bool WXUNUSED(mouseStillDown
)) 
 162     if ( (ControlHandle
) m_macControl 
== NULL 
) 
 167     switch( controlpart 
) 
 169     case kControlUpButtonPart 
: 
 172     case kControlDownButtonPart 
: 
 176     MacHandleValueChanged( nScrollInc 
) ; 
 180 // ---------------------------------------------------------------------------- 
 182 // ---------------------------------------------------------------------------- 
 184 wxSize 
wxSpinButton::DoGetBestSize() const 
 186     return wxSize(16,24); 
 189 #endif // wxUSE_SPINBTN