]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: scrolbar.cpp | |
3 | // Purpose: wxScrollBar | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
e9576ca5 SC |
13 | #pragma implementation "scrolbar.h" |
14 | #endif | |
15 | ||
3d1a4878 | 16 | #include "wx/wxprec.h" |
d8c736e5 | 17 | |
8140eec9 SC |
18 | #ifndef WX_PRECOMP |
19 | #include "wx/intl.h" | |
20 | #include "wx/log.h" | |
21 | #endif // WX_PRECOMP | |
22 | ||
e9576ca5 | 23 | #include "wx/scrolbar.h" |
519cb848 | 24 | #include "wx/mac/uma.h" |
e9576ca5 | 25 | |
e9576ca5 SC |
26 | IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) |
27 | ||
169935ad SC |
28 | BEGIN_EVENT_TABLE(wxScrollBar, wxControl) |
29 | END_EVENT_TABLE() | |
30 | ||
e9576ca5 SC |
31 | // Scrollbar |
32 | bool 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 | { | |
facd6764 SC |
38 | m_macIsUserPane = FALSE ; |
39 | ||
b45ed7a2 VZ |
40 | if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) |
41 | return FALSE; | |
42 | ||
facd6764 | 43 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
b45ed7a2 | 44 | |
b905d6cc | 45 | m_peer = new wxMacControl(this) ; |
4c37f124 | 46 | verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , |
cd780027 | 47 | 0 , 0 , 100 , 1 , true /* liveTracking */ , GetwxMacLiveScrollbarActionProc() , m_peer->GetControlRefAddr() ) ); |
21fd5529 | 48 | |
e9576ca5 | 49 | |
facd6764 | 50 | MacPostControlCreate(pos,size) ; |
e9576ca5 | 51 | |
b45ed7a2 | 52 | return TRUE; |
e9576ca5 SC |
53 | } |
54 | ||
55 | wxScrollBar::~wxScrollBar() | |
56 | { | |
57 | } | |
58 | ||
59 | void wxScrollBar::SetThumbPosition(int viewStart) | |
60 | { | |
5ca0d812 | 61 | m_peer->SetValue( viewStart ) ; |
e9576ca5 SC |
62 | } |
63 | ||
64 | int wxScrollBar::GetThumbPosition() const | |
65 | { | |
5ca0d812 | 66 | return m_peer->GetValue() ; |
e9576ca5 SC |
67 | } |
68 | ||
69 | void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, | |
70 | bool refresh) | |
71 | { | |
4b1c4c21 SC |
72 | m_pageSize = pageSize; |
73 | m_viewSize = thumbSize; | |
e9576ca5 SC |
74 | m_objectSize = range; |
75 | ||
4c37f124 | 76 | int range1 = wxMax((m_objectSize - m_viewSize), 0) ; |
519cb848 | 77 | |
5ca0d812 SC |
78 | m_peer->SetMaximum( range1 ) ; |
79 | m_peer->SetMinimum( 0 ) ; | |
80 | m_peer->SetValue( position ) ; | |
81 | m_peer->SetViewSize( m_viewSize ) ; | |
e9576ca5 SC |
82 | } |
83 | ||
84 | ||
85 | void wxScrollBar::Command(wxCommandEvent& event) | |
86 | { | |
687706f5 | 87 | SetThumbPosition(event.GetInt()); |
e9576ca5 SC |
88 | ProcessCommand(event); |
89 | } | |
90 | ||
4b26b60f | 91 | void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) |
519cb848 | 92 | { |
5ca0d812 SC |
93 | int position = m_peer->GetValue() ; |
94 | int minPos = m_peer->GetMinimum() ; | |
95 | int maxPos = m_peer->GetMaximum() ; | |
e40298d5 JS |
96 | |
97 | wxEventType scrollEvent = wxEVT_NULL; | |
56fc3fa5 | 98 | int nScrollInc = 0; |
e40298d5 | 99 | |
4b26b60f SC |
100 | // all events have already been reported during mouse down, except for THUMBRELEASE |
101 | if ( !mouseStillDown && controlpart !=kControlIndicatorPart ) | |
102 | return ; | |
103 | ||
e40298d5 JS |
104 | switch( controlpart ) |
105 | { | |
106 | case kControlUpButtonPart : | |
4b1c4c21 | 107 | nScrollInc = -1; |
519cb848 | 108 | scrollEvent = wxEVT_SCROLL_LINEUP; |
e40298d5 JS |
109 | break ; |
110 | case kControlDownButtonPart : | |
4b1c4c21 | 111 | nScrollInc = 1; |
519cb848 | 112 | scrollEvent = wxEVT_SCROLL_LINEDOWN; |
e40298d5 JS |
113 | break ; |
114 | case kControlPageUpPart : | |
4b1c4c21 | 115 | nScrollInc = -m_pageSize; |
519cb848 | 116 | scrollEvent = wxEVT_SCROLL_PAGEUP; |
e40298d5 JS |
117 | break ; |
118 | case kControlPageDownPart : | |
4b1c4c21 | 119 | nScrollInc = m_pageSize; |
519cb848 | 120 | scrollEvent = wxEVT_SCROLL_PAGEDOWN; |
e40298d5 JS |
121 | break ; |
122 | case kControlIndicatorPart : | |
519cb848 | 123 | nScrollInc = 0 ; |
4b26b60f SC |
124 | if ( mouseStillDown ) |
125 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
126 | else | |
127 | scrollEvent = wxEVT_SCROLL_THUMBRELEASE; | |
e40298d5 JS |
128 | break ; |
129 | default : | |
130 | wxFAIL_MSG(wxT("illegal scrollbar selector")); | |
131 | break ; | |
132 | } | |
133 | ||
134 | int new_pos = position + nScrollInc; | |
135 | ||
136 | if (new_pos < minPos) | |
137 | new_pos = minPos; | |
138 | if (new_pos > maxPos) | |
139 | new_pos = maxPos; | |
140 | if ( nScrollInc ) | |
141 | SetThumbPosition(new_pos); | |
142 | ||
143 | wxScrollEvent event(scrollEvent, m_windowId); | |
144 | if ( m_windowStyle & wxHORIZONTAL ) | |
145 | { | |
146 | event.SetOrientation( wxHORIZONTAL ) ; | |
147 | } | |
148 | else | |
149 | { | |
150 | event.SetOrientation( wxVERTICAL ) ; | |
151 | } | |
152 | event.SetPosition(new_pos); | |
153 | event.SetEventObject( this ); | |
154 | wxWindow* window = GetParent() ; | |
155 | if (window && window->MacIsWindowScrollbar(this) ) | |
156 | { | |
157 | // this is hardcoded | |
158 | window->MacOnScroll(event); | |
159 | } | |
160 | else | |
161 | GetEventHandler()->ProcessEvent(event); | |
519cb848 SC |
162 | } |
163 | ||
4c37f124 SC |
164 | wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent ) |
165 | { | |
5ca0d812 SC |
166 | int position = m_peer->GetValue() ; |
167 | int minPos = m_peer->GetMinimum() ; | |
168 | int maxPos = m_peer->GetMaximum() ; | |
4c37f124 SC |
169 | |
170 | wxEventType scrollEvent = wxEVT_NULL; | |
171 | int nScrollInc = 0; | |
172 | ||
173 | wxMacCarbonEvent cEvent( (EventRef) mevent ) ; | |
174 | ControlPartCode controlpart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) ; | |
175 | ||
176 | // all events have already been reported during mouse down, except for THUMBRELEASE | |
177 | if ( controlpart !=kControlIndicatorPart ) | |
178 | return eventNotHandledErr ; | |
179 | ||
180 | switch( controlpart ) | |
181 | { | |
182 | case kControlIndicatorPart : | |
183 | nScrollInc = 0 ; | |
184 | scrollEvent = wxEVT_SCROLL_THUMBRELEASE; | |
185 | break ; | |
186 | default : | |
187 | wxFAIL_MSG(wxT("illegal scrollbar selector")); | |
188 | break ; | |
189 | } | |
190 | ||
191 | int new_pos = position + nScrollInc; | |
192 | ||
193 | if (new_pos < minPos) | |
194 | new_pos = minPos; | |
195 | if (new_pos > maxPos) | |
196 | new_pos = maxPos; | |
197 | if ( nScrollInc ) | |
198 | SetThumbPosition(new_pos); | |
199 | ||
200 | wxScrollEvent event(scrollEvent, m_windowId); | |
201 | if ( m_windowStyle & wxHORIZONTAL ) | |
202 | { | |
203 | event.SetOrientation( wxHORIZONTAL ) ; | |
204 | } | |
205 | else | |
206 | { | |
207 | event.SetOrientation( wxVERTICAL ) ; | |
208 | } | |
209 | event.SetPosition(new_pos); | |
210 | event.SetEventObject( this ); | |
211 | wxWindow* window = GetParent() ; | |
212 | if (window && window->MacIsWindowScrollbar(this) ) | |
213 | { | |
214 | // this is hardcoded | |
215 | window->MacOnScroll(event); | |
216 | } | |
217 | else | |
218 | GetEventHandler()->ProcessEvent(event); | |
219 | return noErr ; | |
220 | } | |
221 | ||
222 |