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