]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/scrolbar.cpp
added const for Mac OS X compilation
[wxWidgets.git] / src / mac / carbon / scrolbar.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: scrolbar.cpp
3// Purpose: wxScrollBar
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "scrolbar.h"
14#endif
15
16#include "wx/scrolbar.h"
519cb848 17#include "wx/mac/uma.h"
e9576ca5 18
2f1ae414 19#if !USE_SHARED_LIBRARY
e9576ca5
SC
20IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
21
169935ad
SC
22BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
23END_EVENT_TABLE()
24
2f1ae414 25#endif
e9576ca5 26
519cb848
SC
27extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
28
e9576ca5
SC
29// Scrollbar
30bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
31 const wxPoint& pos,
32 const wxSize& size, long style,
33 const wxValidator& validator,
34 const wxString& name)
35{
519cb848
SC
36 if (!parent)
37 return FALSE;
e9576ca5 38
519cb848
SC
39 Rect bounds ;
40 Str255 title ;
41
42 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
43
44 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 100,
45 kControlScrollBarLiveProc , (long) this ) ;
46
47 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
48
49 ::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ;
e9576ca5 50
519cb848 51 MacPostControlCreate() ;
e9576ca5 52
519cb848 53 return TRUE;
e9576ca5
SC
54}
55
56wxScrollBar::~wxScrollBar()
57{
58}
59
60void wxScrollBar::SetThumbPosition(int viewStart)
61{
519cb848 62 ::SetControlValue( m_macControl , viewStart ) ;
e9576ca5
SC
63}
64
65int wxScrollBar::GetThumbPosition() const
66{
519cb848 67 return ::GetControlValue( m_macControl ) ;
e9576ca5
SC
68}
69
70void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
71 bool refresh)
72{
73 m_viewSize = pageSize;
74 m_pageSize = thumbSize;
75 m_objectSize = range;
76
519cb848
SC
77 int range1 = wxMax((m_objectSize - m_pageSize), 0) ;
78
79 SetControlMaximum( m_macControl , range1 ) ;
80 SetControlMinimum( m_macControl , 0 ) ;
81 SetControlValue( m_macControl , position ) ;
82
83 if ( UMAGetAppearanceVersion() >= 0x0110 )
84 {
85#if UMA_USE_8_6
86 SetControlViewSize( m_macControl , m_pageSize ) ;
87#endif
88 }
89 Refresh() ;
e9576ca5
SC
90}
91
92
93void wxScrollBar::Command(wxCommandEvent& event)
94{
95 SetThumbPosition(event.m_commandInt);
96 ProcessCommand(event);
97}
98
519cb848
SC
99void wxScrollBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
100{
101 if ( m_macControl == NULL )
102 return ;
103
104 int position = GetControlValue( m_macControl) ;
105 int minPos = GetControlMinimum( m_macControl) ;
106 int maxPos = GetControlMaximum( m_macControl) ;
107
108 wxEventType scrollEvent = wxEVT_NULL;
109 int nScrollInc;
110
111 switch( controlpart )
112 {
113 case kControlUpButtonPart :
114 nScrollInc = -1;
115 scrollEvent = wxEVT_SCROLL_LINEUP;
116 break ;
117 case kControlDownButtonPart :
118 nScrollInc = 1;
119 scrollEvent = wxEVT_SCROLL_LINEDOWN;
120 break ;
121 case kControlPageUpPart :
122 nScrollInc = -m_pageSize;
123 scrollEvent = wxEVT_SCROLL_PAGEUP;
124 break ;
125 case kControlPageDownPart :
126 nScrollInc = m_pageSize;
127 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
128 break ;
129 case kControlIndicatorPart :
130 nScrollInc = 0 ;
131 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
132 break ;
133 }
134
135 int new_pos = position + nScrollInc;
136
137 if (new_pos < 0)
138 new_pos = 0;
139 if (new_pos > maxPos)
140 new_pos = maxPos;
141 if ( nScrollInc )
142 SetThumbPosition(new_pos);
143
144 wxScrollEvent event(scrollEvent, m_windowId);
145 if ( m_windowStyle & wxHORIZONTAL )
146 {
147 event.SetOrientation( wxHORIZONTAL ) ;
148 }
149 else
150 {
151 event.SetOrientation( wxVERTICAL ) ;
152 }
153 event.SetPosition(new_pos);
154 event.SetEventObject( this );
7c74e7fe
SC
155 wxWindow* window = GetParent() ;
156 if (window && window->MacIsWindowScrollbar(this) )
157 {
158 // this is hardcoded
159 window->MacOnScroll(event);
160 }
161 else
162 GetEventHandler()->ProcessEvent(event);
519cb848
SC
163}
164