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