1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxScrollBar 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:       wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "scrolbar.h" 
  23 #include "wx/scrolbar.h" 
  24 #include "wx/mac/uma.h" 
  26 #if !USE_SHARED_LIBRARY 
  27 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
) 
  29 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
) 
  34 extern ControlActionUPP wxMacLiveScrollbarActionUPP 
; 
  37 bool wxScrollBar::Create(wxWindow 
*parent
, wxWindowID id
, 
  39            const wxSize
& size
, long style
, 
  40            const wxValidator
& validator
, 
  43     if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) ) 
  49     MacPreControlCreate( parent 
, id 
,  wxEmptyString 
, pos 
, size 
,style
, validator 
, name 
, &bounds 
, title 
) ; 
  51     m_macControl 
= ::NewControl(MAC_WXHWND(parent
->MacGetRootWindow()) , 
  52                                 &bounds 
, title 
, false , 0 , 0 , 100,  
  53                                 kControlScrollBarLiveProc 
, (long) this) ; 
  55     wxASSERT_MSG( (ControlHandle
) m_macControl 
!= NULL 
, wxT("No valid mac control") ) ; 
  57     ::SetControlAction( (ControlHandle
) m_macControl 
, wxMacLiveScrollbarActionUPP 
) ; 
  59     MacPostControlCreate() ; 
  64 wxScrollBar::~wxScrollBar() 
  68 void wxScrollBar::SetThumbPosition(int viewStart
) 
  70     ::SetControl32BitValue( (ControlHandle
) m_macControl 
, viewStart 
) ; 
  73 int wxScrollBar::GetThumbPosition() const 
  75     return ::GetControl32BitValue( (ControlHandle
) m_macControl 
) ; 
  78 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
, 
  81     m_pageSize 
= pageSize
; 
  82     m_viewSize 
= thumbSize
; 
  85       int range1 
= wxMax((m_objectSize 
- m_viewSize
), 0) ; 
  87     SetControl32BitMaximum( (ControlHandle
) m_macControl 
, range1 
) ; 
  88     SetControl32BitMinimum( (ControlHandle
) m_macControl 
, 0 ) ; 
  89     SetControl32BitValue( (ControlHandle
) m_macControl 
, position 
) ; 
  91     if ( UMAGetAppearanceVersion() >= 0x0110  ) 
  93         if ( SetControlViewSize 
!= (void*) kUnresolvedCFragSymbolAddress 
) 
  95                 SetControlViewSize( (ControlHandle
) m_macControl 
, m_viewSize 
) ; 
 103 void wxScrollBar::Command(wxCommandEvent
& event
) 
 105     SetThumbPosition(event
.m_commandInt
); 
 106     ProcessCommand(event
); 
 109 void wxScrollBar::MacHandleControlClick( WXWidget control 
, wxInt16 controlpart 
, bool mouseStillDown 
)  
 111     if ( (ControlHandle
) m_macControl 
== NULL 
) 
 114     int position 
= GetControl32BitValue( (ControlHandle
) m_macControl
) ; 
 115     int minPos 
= GetControl32BitMinimum( (ControlHandle
) m_macControl
) ; 
 116     int maxPos 
= GetControl32BitMaximum( (ControlHandle
) m_macControl
) ; 
 118     wxEventType scrollEvent 
= wxEVT_NULL
; 
 121     // all events have already been reported during mouse down, except for THUMBRELEASE 
 122     if ( !mouseStillDown 
&& controlpart 
!=kControlIndicatorPart 
) 
 125     switch( controlpart 
) 
 127     case kControlUpButtonPart 
: 
 129         scrollEvent 
= wxEVT_SCROLL_LINEUP
; 
 131     case kControlDownButtonPart 
: 
 133         scrollEvent 
= wxEVT_SCROLL_LINEDOWN
; 
 135     case kControlPageUpPart 
: 
 136         nScrollInc 
= -m_pageSize
; 
 137         scrollEvent 
= wxEVT_SCROLL_PAGEUP
; 
 139     case kControlPageDownPart 
: 
 140         nScrollInc 
= m_pageSize
; 
 141         scrollEvent 
= wxEVT_SCROLL_PAGEDOWN
; 
 143     case kControlIndicatorPart 
: 
 145         if ( mouseStillDown 
) 
 146             scrollEvent 
= wxEVT_SCROLL_THUMBTRACK
; 
 148             scrollEvent 
= wxEVT_SCROLL_THUMBRELEASE
; 
 151         wxFAIL_MSG(wxT("illegal scrollbar selector")); 
 155     int new_pos 
= position 
+ nScrollInc
; 
 157     if (new_pos 
< minPos
) 
 159     if (new_pos 
> maxPos
) 
 162         SetThumbPosition(new_pos
); 
 164     wxScrollEvent 
event(scrollEvent
, m_windowId
); 
 165     if ( m_windowStyle 
& wxHORIZONTAL 
) 
 167         event
.SetOrientation( wxHORIZONTAL 
) ; 
 171         event
.SetOrientation( wxVERTICAL 
) ; 
 173     event
.SetPosition(new_pos
); 
 174     event
.SetEventObject( this ); 
 175     wxWindow
* window 
= GetParent() ; 
 176     if (window 
&& window
->MacIsWindowScrollbar(this) ) 
 179         window
->MacOnScroll(event
); 
 182         GetEventHandler()->ProcessEvent(event
);