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