]> git.saurik.com Git - wxWidgets.git/blame - src/os2/scrolbar.cpp
Added wxAddGrab, wxRemoveGrab for use by popup window implementations
[wxWidgets.git] / src / os2 / scrolbar.cpp
CommitLineData
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 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
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
23IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
24
0e320a79 25// Scrollbar
57ff8a87
DW
26bool 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 );
6670f564 100 ::WinShowWindow( hScrollBar, TRUE );
57ff8a87
DW
101 SetFont(*wxSMALL_FONT);
102
103 m_hWnd = hScrollBar;
104
105 //
409c9842 106 // Subclass again for purposes of dialog editing mode
57ff8a87
DW
107 //
108 SubclassWin((WXHWND)hScrollBar);
109 SetSize( nX
110 ,nY
111 ,nWidth
112 ,nHeight
113 );
0e320a79 114 return TRUE;
57ff8a87 115} // end of wxScrollBar::Create
0e320a79
DW
116
117wxScrollBar::~wxScrollBar()
118{
119}
120
6670f564
WS
121bool wxScrollBar::OS2OnScroll ( int WXUNUSED(nOrientation),
122 WXWORD wParam,
123 WXWORD wPos,
124 WXHWND WXUNUSED(hControl) )
409c9842 125{
6670f564
WS
126 int nPosition;
127 int nMaxPos;
128 int nTrackPos = wPos;
129 int nMinPos;
130 int nScrollInc;
131 wxEventType vScrollEvent = wxEVT_NULL;
57ff8a87 132
6670f564 133 MRESULT vRange;
57ff8a87
DW
134
135 //
136 // When we're dragging the scrollbar we can't use pos parameter because it
137 // is limited to 16 bits
138 //
139 if (wParam == SB_SLIDERPOSITION || wParam == SB_SLIDERTRACK)
140 {
141 SBCDATA vScrollInfo;
142
143 vScrollInfo.sHilite = SB_SLIDERTRACK;
409c9842 144
57ff8a87
DW
145 ::WinSendMsg((HWND)GetHwnd(), WM_QUERYWINDOWPARAMS, (PVOID)&vScrollInfo, NULL);
146
147 nTrackPos = vScrollInfo.posThumb;
148 nPosition = vScrollInfo.posFirst;
149 nMaxPos = vScrollInfo.posLast;
150 }
151 else
152 {
153 nPosition = (int)(MRESULT)::WinSendMsg((HWND)GetHwnd(), SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL);
154 vRange = ::WinSendMsg((HWND)GetHwnd(), SBM_QUERYRANGE, (MPARAM)NULL, (MPARAM)NULL);
155 nMinPos = SHORT1FROMMR(vRange);
156 nMaxPos = SHORT2FROMMR(vRange);
157 }
158 //
409c9842
DW
159 // A page size greater than one has the effect of reducing the effective
160 // range, therefore the range has already been boosted artificially - so
161 // reduce it again.
57ff8a87
DW
162 //
163 if (m_nPageSize > 1)
164 nMaxPos -= (m_nPageSize - 1);
165 switch (wParam)
409c9842 166 {
409c9842 167 case SB_LINEUP:
57ff8a87
DW
168 nScrollInc = -1;
169 vScrollEvent = wxEVT_SCROLL_LINEUP;
409c9842
DW
170 break;
171
172 case SB_LINEDOWN:
57ff8a87
DW
173 nScrollInc = 1;
174 vScrollEvent = wxEVT_SCROLL_LINEDOWN;
409c9842
DW
175 break;
176
177 case SB_PAGEUP:
57ff8a87
DW
178 nScrollInc = -GetPageSize();
179 vScrollEvent = wxEVT_SCROLL_PAGEUP;
409c9842
DW
180 break;
181
182 case SB_PAGEDOWN:
57ff8a87
DW
183 nScrollInc = GetPageSize();
184 vScrollEvent = wxEVT_SCROLL_PAGEDOWN;
185 break;
186
187 case SB_SLIDERTRACK:
188 nScrollInc = nTrackPos - nPosition;
189 vScrollEvent = wxEVT_SCROLL_THUMBTRACK;
409c9842
DW
190 break;
191
57ff8a87
DW
192 case SB_ENDSCROLL:
193 nScrollInc = 0;
194 vScrollEvent = wxEVT_SCROLL_ENDSCROLL;
409c9842
DW
195 break;
196
197 default:
198 nScrollInc = 0;
199 }
57ff8a87
DW
200 if (nScrollInc)
201 {
202 nPosition += nScrollInc;
409c9842 203
57ff8a87
DW
204 if (nPosition < 0)
205 nPosition = 0;
206 if (nPosition > nMaxPos)
207 nPosition = nMaxPos;
208 SetThumbPosition(nPosition);
209 }
210 else if ( vScrollEvent != wxEVT_SCROLL_THUMBRELEASE &&
211 vScrollEvent != wxEVT_SCROLL_ENDSCROLL
212 )
409c9842 213 {
57ff8a87
DW
214 //
215 // Don't process the event if there is no displacement,
216 // unless this is a thumb release or end scroll event.
217 //
6670f564 218 return false;
409c9842
DW
219 }
220
57ff8a87
DW
221 wxScrollEvent vEvent( vScrollEvent
222 ,m_windowId
223 );
409c9842 224
6e348b12 225 vEvent.SetOrientation(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
57ff8a87
DW
226 vEvent.SetPosition(nPosition);
227 vEvent.SetEventObject(this);
228 return GetEventHandler()->ProcessEvent(vEvent);
229} // end of wxScrollBar::OS2OnScroll
409c9842 230
6670f564 231void wxScrollBar::SetThumbPosition ( int nViewStart )
409c9842 232{
57ff8a87 233 SBCDATA vInfo;
409c9842 234
57ff8a87
DW
235 memset(&vInfo, '\0', sizeof(SBCDATA));
236 vInfo.cb = sizeof(SBCDATA);
6670f564 237 vInfo.posThumb = (SHORT)nViewStart;
409c9842 238
57ff8a87
DW
239 ::WinSendMsg((HWND)GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vInfo, (MPARAM)NULL);
240 ::WinSendMsg((HWND)GetHwnd(), SBM_SETPOS, (MPARAM)nViewStart, (MPARAM)NULL);
241} // end of wxScrollBar::SetThumbPosition
409c9842 242
57ff8a87 243int wxScrollBar::GetThumbPosition() const
409c9842 244{
57ff8a87
DW
245 return((int)(MRESULT)::WinSendMsg((HWND)GetHwnd(), SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL));
246} // end of wxScrollBar::GetThumbPosition
247
6670f564
WS
248void wxScrollBar::SetScrollbar ( int nPosition,
249 int nThumbSize,
250 int nRange,
251 int nPageSize,
252 bool WXUNUSED(bRefresh) )
409c9842 253{
57ff8a87
DW
254 SBCDATA vInfo;
255 //
256 // The lRange (number of scroll steps) is the
257 // object length minus the page size.
258 //
259 int nRange1 = wxMax((m_nObjectSize - m_nPageSize), 0);
260
261 m_nViewSize = nPageSize;
262 m_nPageSize = nThumbSize;
263 m_nObjectSize = nRange;
264
265
266 //
267 // Try to adjust the lRange to cope with page size > 1
268 // (see comment for SetPageLength)
269 //
270 if (m_nPageSize > 1 )
271 {
272 nRange1 += (m_nPageSize - 1);
273 }
274 vInfo.cb = sizeof(SBCDATA);
6670f564 275 vInfo.cVisible = (SHORT)m_nPageSize;
57ff8a87 276 vInfo.posFirst = 0;
6670f564
WS
277 vInfo.posLast = (SHORT)nRange1;
278 vInfo.posThumb = (SHORT)nPosition;
57ff8a87
DW
279
280 ::WinSendMsg((HWND)GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vInfo, (MPARAM)NULL);
281} // end of wxScrollBar::SetScrollbar
282
6670f564
WS
283WXHBRUSH wxScrollBar::OnCtlColor ( WXHDC WXUNUSED(hDC),
284 WXHWND WXUNUSED(hWnd),
285 WXUINT WXUNUSED(uCtlColor),
286 WXUINT WXUNUSED(uMessage),
287 WXWPARAM WXUNUSED(wParam),
288 WXLPARAM WXUNUSED(lParam) )
409c9842 289{
57ff8a87
DW
290 //
291 // Does nothing under OS/2
292 //
293 return 0;
294} // end of wxScrollBar::OnCtlColor
0e320a79 295
6670f564 296void wxScrollBar::Command ( wxCommandEvent& rEvent )
0e320a79 297{
687706f5 298 SetThumbPosition(rEvent.GetInt());
57ff8a87
DW
299 ProcessCommand(rEvent);
300} // end of wxScrollBar::Command