]>
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 ///////////////////////////////////////////////////////////////////////////// 
  12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  13 #pragma implementation "spinbutt.h" 
  14 #pragma implementation "spinbuttbase.h" 
  17 #include "wx/wxprec.h" 
  21 #include "wx/spinbutt.h" 
  22 #include "wx/mac/uma.h" 
  24 // ============================================================================ 
  26 // ============================================================================ 
  28 // ---------------------------------------------------------------------------- 
  30 // ---------------------------------------------------------------------------- 
  32 #if !USE_SHARED_LIBRARY 
  33     IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
) 
  34     IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
) 
  37 wxSpinButton::wxSpinButton() 
  42 bool wxSpinButton::Create(wxWindow 
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, 
  43         long style
, const wxString
& name
) 
  45     m_macIsUserPane 
= false ; 
  47     if ( !wxSpinButtonBase::Create(parent
, id
, pos
, size
, 
  48                                    style
, wxDefaultValidator
, name
) ) 
  57     Rect bounds 
= wxMacGetBoundsForControl( this , pos 
, size 
) ; 
  59     m_peer 
= new wxMacControl(this) ; 
  60     verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds 
, 0 , m_min 
, m_max 
, 1 , 
  61      m_peer
->GetControlRefAddr() ) ); 
  63     m_peer
->SetActionProc( GetwxMacLiveScrollbarActionProc() ) ; 
  64     MacPostControlCreate(pos
,size
) ; 
  69 wxSpinButton::~wxSpinButton() 
  74 //////////////////////////////////////////////////////////////////////////// 
  76 int wxSpinButton::GetMin() const 
  81 int wxSpinButton::GetMax() const 
  86 int wxSpinButton::GetValue() const 
  90     if (n 
< m_min
) n 
= m_min
; 
  91     if (n 
> m_max
) n 
= m_max
; 
  96 void wxSpinButton::SetValue(int val
) 
 101 void wxSpinButton::SetRange(int minVal
, int maxVal
) 
 105     m_peer
->SetMaximum( maxVal 
) ; 
 106     m_peer
->SetMinimum( minVal 
) ; 
 109 void wxSpinButton::MacHandleValueChanged( int inc 
) 
 112     wxEventType scrollEvent 
= wxEVT_NULL
; 
 113     int oldValue 
= m_value 
; 
 115     m_value 
= oldValue 
+ inc
; 
 119         if ( m_windowStyle 
& wxSP_WRAP 
) 
 127         if ( m_windowStyle 
& wxSP_WRAP 
) 
 133     if ( m_value 
- oldValue 
== -1 ) 
 134         scrollEvent 
= wxEVT_SCROLL_LINEDOWN 
; 
 135     else if ( m_value 
- oldValue 
== 1 ) 
 136         scrollEvent 
= wxEVT_SCROLL_LINEUP 
; 
 138         scrollEvent 
= wxEVT_SCROLL_THUMBTRACK 
; 
 140     wxSpinEvent 
event(scrollEvent
, m_windowId
); 
 142     event
.SetPosition(m_value
); 
 143     event
.SetEventObject( this ); 
 144     if ((GetEventHandler()->ProcessEvent( event 
)) && 
 149     m_peer
->SetValue( m_value 
) ; 
 151     /* always send a thumbtrack event */ 
 152     if (scrollEvent 
!= wxEVT_SCROLL_THUMBTRACK
) 
 154         scrollEvent 
= wxEVT_SCROLL_THUMBTRACK
; 
 155         wxSpinEvent 
event2( scrollEvent
, GetId()); 
 156         event2
.SetPosition( m_value 
); 
 157         event2
.SetEventObject( this ); 
 158         GetEventHandler()->ProcessEvent( event2 
); 
 162 void wxSpinButton::MacHandleControlClick( WXWidget control 
, wxInt16 controlpart 
, bool mouseStillDown 
) 
 166     switch( controlpart 
) 
 168     case kControlUpButtonPart 
: 
 171     case kControlDownButtonPart 
: 
 175     MacHandleValueChanged( nScrollInc 
) ; 
 178 wxInt32 
wxSpinButton::MacControlHit(WXEVENTHANDLERREF 
WXUNUSED(handler
) , WXEVENTREF event 
) 
 181     // these have been handled by the live action proc already 
 183     wxMacCarbonEvent cEvent( (EventRef) event ) ; 
 185     switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) ) 
 187     case kControlUpButtonPart : 
 190     case kControlDownButtonPart : 
 194     MacHandleValueChanged( nScrollInc ) ; 
 199 // ---------------------------------------------------------------------------- 
 201 // ---------------------------------------------------------------------------- 
 203 wxSize 
wxSpinButton::DoGetBestSize() const 
 205     return wxSize(16,24); 
 208 #endif // wxUSE_SPINBTN