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