]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/scrolbar.cpp
wxDC::DrawPolygon correction
[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 {
a49afa93
SC
85 if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
86 {
519cb848 87 SetControlViewSize( m_macControl , m_pageSize ) ;
a49afa93 88 }
519cb848
SC
89 }
90 Refresh() ;
e9576ca5
SC
91}
92
93
94void wxScrollBar::Command(wxCommandEvent& event)
95{
96 SetThumbPosition(event.m_commandInt);
97 ProcessCommand(event);
98}
99
519cb848
SC
100void wxScrollBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
101{
102 if ( m_macControl == NULL )
103 return ;
104
105 int position = GetControlValue( m_macControl) ;
106 int minPos = GetControlMinimum( m_macControl) ;
107 int maxPos = GetControlMaximum( m_macControl) ;
108
109 wxEventType scrollEvent = wxEVT_NULL;
110 int nScrollInc;
111
112 switch( controlpart )
113 {
114 case kControlUpButtonPart :
115 nScrollInc = -1;
116 scrollEvent = wxEVT_SCROLL_LINEUP;
117 break ;
118 case kControlDownButtonPart :
119 nScrollInc = 1;
120 scrollEvent = wxEVT_SCROLL_LINEDOWN;
121 break ;
122 case kControlPageUpPart :
123 nScrollInc = -m_pageSize;
124 scrollEvent = wxEVT_SCROLL_PAGEUP;
125 break ;
126 case kControlPageDownPart :
127 nScrollInc = m_pageSize;
128 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
129 break ;
130 case kControlIndicatorPart :
131 nScrollInc = 0 ;
132 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
133 break ;
134 }
135
136 int new_pos = position + nScrollInc;
137
138 if (new_pos < 0)
139 new_pos = 0;
140 if (new_pos > maxPos)
141 new_pos = maxPos;
142 if ( nScrollInc )
143 SetThumbPosition(new_pos);
144
145 wxScrollEvent event(scrollEvent, m_windowId);
146 if ( m_windowStyle & wxHORIZONTAL )
147 {
148 event.SetOrientation( wxHORIZONTAL ) ;
149 }
150 else
151 {
152 event.SetOrientation( wxVERTICAL ) ;
153 }
154 event.SetPosition(new_pos);
155 event.SetEventObject( this );
7c74e7fe
SC
156 wxWindow* window = GetParent() ;
157 if (window && window->MacIsWindowScrollbar(this) )
158 {
159 // this is hardcoded
160 window->MacOnScroll(event);
161 }
162 else
163 GetEventHandler()->ProcessEvent(event);
519cb848
SC
164}
165