1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
20 #include "wx/scrolbar.h"
21 #include "wx/os2/private.h"
23 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
26 bool wxScrollBar::Create (
33 , const wxValidator
& rValidator
35 , const wxString
& rsName
41 int nHeight
= rSize
.y
;
45 pParent
->AddChild(this);
48 SetValidator(rValidator
);
50 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
51 SetForegroundColour(pParent
->GetForegroundColour()) ;
54 m_windowId
= (int)NewControlId();
60 if (lStyle
& wxHORIZONTAL
)
67 if (lStyle
& wxVERTICAL
)
73 DWORD dwStyle
= WS_VISIBLE
;
75 if (GetWindowStyleFlag() & wxCLIP_SIBLINGS
)
76 dwStyle
|= WS_CLIPSIBLINGS
;
78 DWORD dwDirection
= (lStyle
& wxHORIZONTAL
) ? SBS_HORZ
: SBS_VERT
;
80 HWND hScrollBar
= ::WinCreateWindow( (HWND
)GetHwndOf(pParent
)
83 ,dwDirection
| dwStyle
85 ,(HWND
)GetHwndOf(pParent
)
95 ::WinSendMsg( hScrollBar
100 ::WinShowWindow( hScrollBar
103 SetFont(*wxSMALL_FONT
);
108 // Subclass again for purposes of dialog editing mode
110 SubclassWin((WXHWND
)hScrollBar
);
117 } // end of wxScrollBar::Create
119 wxScrollBar::~wxScrollBar()
123 bool wxScrollBar::OS2OnScroll (
132 int nTrackPos
= wPos
;
135 wxEventType vScrollEvent
= wxEVT_NULL
;
140 // When we're dragging the scrollbar we can't use pos parameter because it
141 // is limited to 16 bits
143 if (wParam
== SB_SLIDERPOSITION
|| wParam
== SB_SLIDERTRACK
)
147 vScrollInfo
.sHilite
= SB_SLIDERTRACK
;
149 ::WinSendMsg((HWND
)GetHwnd(), WM_QUERYWINDOWPARAMS
, (PVOID
)&vScrollInfo
, NULL
);
151 nTrackPos
= vScrollInfo
.posThumb
;
152 nPosition
= vScrollInfo
.posFirst
;
153 nMaxPos
= vScrollInfo
.posLast
;
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
);
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
168 nMaxPos
-= (m_nPageSize
- 1);
173 vScrollEvent
= wxEVT_SCROLL_LINEUP
;
178 vScrollEvent
= wxEVT_SCROLL_LINEDOWN
;
182 nScrollInc
= -GetPageSize();
183 vScrollEvent
= wxEVT_SCROLL_PAGEUP
;
187 nScrollInc
= GetPageSize();
188 vScrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
192 nScrollInc
= nTrackPos
- nPosition
;
193 vScrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
198 vScrollEvent
= wxEVT_SCROLL_ENDSCROLL
;
206 nPosition
+= nScrollInc
;
210 if (nPosition
> nMaxPos
)
212 SetThumbPosition(nPosition
);
214 else if ( vScrollEvent
!= wxEVT_SCROLL_THUMBRELEASE
&&
215 vScrollEvent
!= wxEVT_SCROLL_ENDSCROLL
219 // Don't process the event if there is no displacement,
220 // unless this is a thumb release or end scroll event.
225 wxScrollEvent
vEvent( vScrollEvent
229 vEvent
.SetPosition(nPosition
);
230 vEvent
.SetEventObject(this);
231 return GetEventHandler()->ProcessEvent(vEvent
);
232 } // end of wxScrollBar::OS2OnScroll
234 void wxScrollBar::SetThumbPosition (
240 memset(&vInfo
, '\0', sizeof(SBCDATA
));
241 vInfo
.cb
= sizeof(SBCDATA
);
242 vInfo
.posThumb
= nViewStart
;
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
248 int wxScrollBar::GetThumbPosition() const
250 return((int)(MRESULT
)::WinSendMsg((HWND
)GetHwnd(), SBM_QUERYPOS
, (MPARAM
)NULL
, (MPARAM
)NULL
));
251 } // end of wxScrollBar::GetThumbPosition
253 void wxScrollBar::SetScrollbar (
263 // The lRange (number of scroll steps) is the
264 // object length minus the page size.
266 int nRange1
= wxMax((m_nObjectSize
- m_nPageSize
), 0);
268 m_nViewSize
= nPageSize
;
269 m_nPageSize
= nThumbSize
;
270 m_nObjectSize
= nRange
;
274 // Try to adjust the lRange to cope with page size > 1
275 // (see comment for SetPageLength)
277 if (m_nPageSize
> 1 )
279 nRange1
+= (m_nPageSize
- 1);
281 vInfo
.cb
= sizeof(SBCDATA
);
282 vInfo
.cVisible
= m_nPageSize
;
284 vInfo
.posLast
= nRange1
;
285 vInfo
.posThumb
= nPosition
;
287 ::WinSendMsg((HWND
)GetHwnd(), WM_SETWINDOWPARAMS
, (MPARAM
)&vInfo
, (MPARAM
)NULL
);
288 } // end of wxScrollBar::SetScrollbar
290 WXHBRUSH
wxScrollBar::OnCtlColor (
300 // Does nothing under OS/2
303 } // end of wxScrollBar::OnCtlColor
305 void wxScrollBar::Command (
306 wxCommandEvent
& rEvent
309 SetThumbPosition(rEvent
.m_commandInt
);
310 ProcessCommand(rEvent
);
311 } // end of wxScrollBar::Command