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