]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: scrolbar.cpp | |
3 | // Purpose: wxScrollBar | |
409c9842 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
409c9842 | 6 | // Created: 10/15/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
409c9842 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
409c9842 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/defs.h" | |
17 | #include "wx/utils.h" | |
0e320a79 DW |
18 | #endif |
19 | ||
20 | #include "wx/scrolbar.h" | |
409c9842 | 21 | #include "wx/os2/private.h" |
0e320a79 | 22 | |
0e320a79 DW |
23 | IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) |
24 | ||
0e320a79 | 25 | // Scrollbar |
57ff8a87 DW |
26 | bool wxScrollBar::Create ( |
27 | wxWindow* pParent | |
28 | , wxWindowID vId | |
29 | , const wxPoint& rPos | |
30 | , const wxSize& rSize | |
31 | , long lStyle | |
32 | #if wxUSE_VALIDATORS | |
33 | , const wxValidator& rValidator | |
34 | #endif | |
35 | , const wxString& rsName | |
36 | ) | |
0e320a79 | 37 | { |
57ff8a87 DW |
38 | int nX = rPos.x; |
39 | int nY = rPos.y; | |
40 | int nWidth = rSize.x; | |
41 | int nHeight = rSize.y; | |
42 | ||
2f60dbe2 | 43 | if (!pParent) |
0e320a79 | 44 | return FALSE; |
57ff8a87 DW |
45 | pParent->AddChild(this); |
46 | SetName(rsName); | |
5d4b632b | 47 | #if wxUSE_VALIDATORS |
57ff8a87 | 48 | SetValidator(rValidator); |
5d4b632b | 49 | #endif |
57ff8a87 DW |
50 | SetBackgroundColour(pParent->GetBackgroundColour()) ; |
51 | SetForegroundColour(pParent->GetForegroundColour()) ; | |
04701dd9 | 52 | |
57ff8a87 | 53 | if (vId == -1L) |
409c9842 | 54 | m_windowId = (int)NewControlId(); |
0e320a79 | 55 | else |
57ff8a87 | 56 | m_windowId = vId; |
409c9842 | 57 | |
57ff8a87 | 58 | if (nWidth == -1) |
409c9842 | 59 | { |
57ff8a87 DW |
60 | if (lStyle & wxHORIZONTAL) |
61 | nWidth = 140; | |
409c9842 | 62 | else |
57ff8a87 | 63 | nWidth = 14; |
409c9842 | 64 | } |
57ff8a87 | 65 | if (nHeight == -1) |
409c9842 | 66 | { |
57ff8a87 DW |
67 | if (lStyle & wxVERTICAL) |
68 | nHeight = 140; | |
409c9842 | 69 | else |
57ff8a87 | 70 | nHeight = 14; |
409c9842 | 71 | } |
0e320a79 | 72 | |
57ff8a87 DW |
73 | DWORD dwStyle = WS_VISIBLE; |
74 | ||
75 | if (GetWindowStyleFlag() & wxCLIP_SIBLINGS) | |
76 | dwStyle |= WS_CLIPSIBLINGS; | |
77 | ||
78 | DWORD dwDirection = (lStyle & wxHORIZONTAL) ? SBS_HORZ: SBS_VERT; | |
79 | ||
80 | HWND hScrollBar = ::WinCreateWindow( (HWND)GetHwndOf(pParent) | |
81 | ,WC_SCROLLBAR | |
82 | ,(PSZ)NULL | |
83 | ,dwDirection | dwStyle | |
84 | ,0, 0, 0, 0 | |
85 | ,(HWND)GetHwndOf(pParent) | |
86 | ,HWND_TOP | |
87 | ,(HMENU)m_windowId | |
88 | ,NULL | |
89 | ,NULL | |
90 | ); | |
91 | ||
92 | m_nPageSize = 1; | |
93 | m_nViewSize = 1; | |
94 | m_nObjectSize = 1; | |
95 | ::WinSendMsg( hScrollBar | |
96 | ,SBM_SETSCROLLBAR | |
97 | ,(MPARAM)0 | |
98 | ,MPFROM2SHORT(0,1) | |
99 | ); | |
100 | ::WinShowWindow( hScrollBar | |
101 | ,TRUE | |
102 | ); | |
103 | SetFont(*wxSMALL_FONT); | |
104 | ||
105 | m_hWnd = hScrollBar; | |
106 | ||
107 | // | |
409c9842 | 108 | // Subclass again for purposes of dialog editing mode |
57ff8a87 DW |
109 | // |
110 | SubclassWin((WXHWND)hScrollBar); | |
111 | SetSize( nX | |
112 | ,nY | |
113 | ,nWidth | |
114 | ,nHeight | |
115 | ); | |
0e320a79 | 116 | return TRUE; |
57ff8a87 | 117 | } // end of wxScrollBar::Create |
0e320a79 DW |
118 | |
119 | wxScrollBar::~wxScrollBar() | |
120 | { | |
121 | } | |
122 | ||
57ff8a87 DW |
123 | bool wxScrollBar::OS2OnScroll ( |
124 | int nOrientation | |
125 | , WXWORD wParam | |
126 | , WXWORD wPos | |
127 | , WXHWND hControl | |
128 | ) | |
409c9842 | 129 | { |
57ff8a87 DW |
130 | int nPosition; |
131 | int nMaxPos; | |
132 | int nTrackPos = wPos; | |
133 | int nMinPos; | |
134 | int nScrollInc; | |
135 | wxEventType vScrollEvent = wxEVT_NULL; | |
136 | ||
137 | MRESULT vRange; | |
138 | ||
139 | // | |
140 | // When we're dragging the scrollbar we can't use pos parameter because it | |
141 | // is limited to 16 bits | |
142 | // | |
143 | if (wParam == SB_SLIDERPOSITION || wParam == SB_SLIDERTRACK) | |
144 | { | |
145 | SBCDATA vScrollInfo; | |
146 | ||
147 | vScrollInfo.sHilite = SB_SLIDERTRACK; | |
409c9842 | 148 | |
57ff8a87 DW |
149 | ::WinSendMsg((HWND)GetHwnd(), WM_QUERYWINDOWPARAMS, (PVOID)&vScrollInfo, NULL); |
150 | ||
151 | nTrackPos = vScrollInfo.posThumb; | |
152 | nPosition = vScrollInfo.posFirst; | |
153 | nMaxPos = vScrollInfo.posLast; | |
154 | } | |
155 | else | |
156 | { | |
157 | nPosition = (int)(MRESULT)::WinSendMsg((HWND)GetHwnd(), SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL); | |
158 | vRange = ::WinSendMsg((HWND)GetHwnd(), SBM_QUERYRANGE, (MPARAM)NULL, (MPARAM)NULL); | |
159 | nMinPos = SHORT1FROMMR(vRange); | |
160 | nMaxPos = SHORT2FROMMR(vRange); | |
161 | } | |
162 | // | |
409c9842 DW |
163 | // A page size greater than one has the effect of reducing the effective |
164 | // range, therefore the range has already been boosted artificially - so | |
165 | // reduce it again. | |
57ff8a87 DW |
166 | // |
167 | if (m_nPageSize > 1) | |
168 | nMaxPos -= (m_nPageSize - 1); | |
169 | switch (wParam) | |
409c9842 | 170 | { |
409c9842 | 171 | case SB_LINEUP: |
57ff8a87 DW |
172 | nScrollInc = -1; |
173 | vScrollEvent = wxEVT_SCROLL_LINEUP; | |
409c9842 DW |
174 | break; |
175 | ||
176 | case SB_LINEDOWN: | |
57ff8a87 DW |
177 | nScrollInc = 1; |
178 | vScrollEvent = wxEVT_SCROLL_LINEDOWN; | |
409c9842 DW |
179 | break; |
180 | ||
181 | case SB_PAGEUP: | |
57ff8a87 DW |
182 | nScrollInc = -GetPageSize(); |
183 | vScrollEvent = wxEVT_SCROLL_PAGEUP; | |
409c9842 DW |
184 | break; |
185 | ||
186 | case SB_PAGEDOWN: | |
57ff8a87 DW |
187 | nScrollInc = GetPageSize(); |
188 | vScrollEvent = wxEVT_SCROLL_PAGEDOWN; | |
189 | break; | |
190 | ||
191 | case SB_SLIDERTRACK: | |
192 | nScrollInc = nTrackPos - nPosition; | |
193 | vScrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
409c9842 DW |
194 | break; |
195 | ||
57ff8a87 DW |
196 | case SB_ENDSCROLL: |
197 | nScrollInc = 0; | |
198 | vScrollEvent = wxEVT_SCROLL_ENDSCROLL; | |
409c9842 DW |
199 | break; |
200 | ||
201 | default: | |
202 | nScrollInc = 0; | |
203 | } | |
57ff8a87 DW |
204 | if (nScrollInc) |
205 | { | |
206 | nPosition += nScrollInc; | |
409c9842 | 207 | |
57ff8a87 DW |
208 | if (nPosition < 0) |
209 | nPosition = 0; | |
210 | if (nPosition > nMaxPos) | |
211 | nPosition = nMaxPos; | |
212 | SetThumbPosition(nPosition); | |
213 | } | |
214 | else if ( vScrollEvent != wxEVT_SCROLL_THUMBRELEASE && | |
215 | vScrollEvent != wxEVT_SCROLL_ENDSCROLL | |
216 | ) | |
409c9842 | 217 | { |
57ff8a87 DW |
218 | // |
219 | // Don't process the event if there is no displacement, | |
220 | // unless this is a thumb release or end scroll event. | |
221 | // | |
409c9842 DW |
222 | return FALSE; |
223 | } | |
224 | ||
57ff8a87 DW |
225 | wxScrollEvent vEvent( vScrollEvent |
226 | ,m_windowId | |
227 | ); | |
409c9842 | 228 | |
57ff8a87 DW |
229 | vEvent.SetPosition(nPosition); |
230 | vEvent.SetEventObject(this); | |
231 | return GetEventHandler()->ProcessEvent(vEvent); | |
232 | } // end of wxScrollBar::OS2OnScroll | |
409c9842 | 233 | |
57ff8a87 DW |
234 | void wxScrollBar::SetThumbPosition ( |
235 | int nViewStart | |
236 | ) | |
409c9842 | 237 | { |
57ff8a87 | 238 | SBCDATA vInfo; |
409c9842 | 239 | |
57ff8a87 DW |
240 | memset(&vInfo, '\0', sizeof(SBCDATA)); |
241 | vInfo.cb = sizeof(SBCDATA); | |
242 | vInfo.posThumb = nViewStart; | |
409c9842 | 243 | |
57ff8a87 DW |
244 | ::WinSendMsg((HWND)GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vInfo, (MPARAM)NULL); |
245 | ::WinSendMsg((HWND)GetHwnd(), SBM_SETPOS, (MPARAM)nViewStart, (MPARAM)NULL); | |
246 | } // end of wxScrollBar::SetThumbPosition | |
409c9842 | 247 | |
57ff8a87 | 248 | int wxScrollBar::GetThumbPosition() const |
409c9842 | 249 | { |
57ff8a87 DW |
250 | return((int)(MRESULT)::WinSendMsg((HWND)GetHwnd(), SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL)); |
251 | } // end of wxScrollBar::GetThumbPosition | |
252 | ||
253 | void wxScrollBar::SetScrollbar ( | |
254 | int nPosition | |
255 | , int nThumbSize | |
256 | , int nRange | |
257 | , int nPageSize | |
258 | , bool bRefresh | |
259 | ) | |
409c9842 | 260 | { |
57ff8a87 DW |
261 | SBCDATA vInfo; |
262 | // | |
263 | // The lRange (number of scroll steps) is the | |
264 | // object length minus the page size. | |
265 | // | |
266 | int nRange1 = wxMax((m_nObjectSize - m_nPageSize), 0); | |
267 | ||
268 | m_nViewSize = nPageSize; | |
269 | m_nPageSize = nThumbSize; | |
270 | m_nObjectSize = nRange; | |
271 | ||
272 | ||
273 | // | |
274 | // Try to adjust the lRange to cope with page size > 1 | |
275 | // (see comment for SetPageLength) | |
276 | // | |
277 | if (m_nPageSize > 1 ) | |
278 | { | |
279 | nRange1 += (m_nPageSize - 1); | |
280 | } | |
281 | vInfo.cb = sizeof(SBCDATA); | |
282 | vInfo.cVisible = m_nPageSize; | |
283 | vInfo.posFirst = 0; | |
284 | vInfo.posLast = nRange1; | |
285 | vInfo.posThumb = nPosition; | |
286 | ||
287 | ::WinSendMsg((HWND)GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vInfo, (MPARAM)NULL); | |
288 | } // end of wxScrollBar::SetScrollbar | |
289 | ||
290 | WXHBRUSH wxScrollBar::OnCtlColor ( | |
291 | WXHDC hDC | |
292 | , WXHWND hWnd | |
293 | , WXUINT uCtlColor | |
294 | , WXUINT uMessage | |
295 | , WXWPARAM wParam | |
296 | , WXLPARAM lParam | |
297 | ) | |
409c9842 | 298 | { |
57ff8a87 DW |
299 | // |
300 | // Does nothing under OS/2 | |
301 | // | |
302 | return 0; | |
303 | } // end of wxScrollBar::OnCtlColor | |
0e320a79 | 304 | |
57ff8a87 DW |
305 | void wxScrollBar::Command ( |
306 | wxCommandEvent& rEvent | |
307 | ) | |
0e320a79 | 308 | { |
57ff8a87 DW |
309 | SetThumbPosition(rEvent.m_commandInt); |
310 | ProcessCommand(rEvent); | |
311 | } // end of wxScrollBar::Command | |
0e320a79 | 312 |