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
.SetOrientation(IsVertical() ? wxVERTICAL
: wxHORIZONTAL
);
230 vEvent
.SetPosition(nPosition
);
231 vEvent
.SetEventObject(this);
232 return GetEventHandler()->ProcessEvent(vEvent
);
233 } // end of wxScrollBar::OS2OnScroll
235 void wxScrollBar::SetThumbPosition (
241 memset(&vInfo
, '\0', sizeof(SBCDATA
));
242 vInfo
.cb
= sizeof(SBCDATA
);
243 vInfo
.posThumb
= nViewStart
;
245 ::WinSendMsg((HWND
)GetHwnd(), WM_SETWINDOWPARAMS
, (MPARAM
)&vInfo
, (MPARAM
)NULL
);
246 ::WinSendMsg((HWND
)GetHwnd(), SBM_SETPOS
, (MPARAM
)nViewStart
, (MPARAM
)NULL
);
247 } // end of wxScrollBar::SetThumbPosition
249 int wxScrollBar::GetThumbPosition() const
251 return((int)(MRESULT
)::WinSendMsg((HWND
)GetHwnd(), SBM_QUERYPOS
, (MPARAM
)NULL
, (MPARAM
)NULL
));
252 } // end of wxScrollBar::GetThumbPosition
254 void wxScrollBar::SetScrollbar (
264 // The lRange (number of scroll steps) is the
265 // object length minus the page size.
267 int nRange1
= wxMax((m_nObjectSize
- m_nPageSize
), 0);
269 m_nViewSize
= nPageSize
;
270 m_nPageSize
= nThumbSize
;
271 m_nObjectSize
= nRange
;
275 // Try to adjust the lRange to cope with page size > 1
276 // (see comment for SetPageLength)
278 if (m_nPageSize
> 1 )
280 nRange1
+= (m_nPageSize
- 1);
282 vInfo
.cb
= sizeof(SBCDATA
);
283 vInfo
.cVisible
= m_nPageSize
;
285 vInfo
.posLast
= nRange1
;
286 vInfo
.posThumb
= nPosition
;
288 ::WinSendMsg((HWND
)GetHwnd(), WM_SETWINDOWPARAMS
, (MPARAM
)&vInfo
, (MPARAM
)NULL
);
289 } // end of wxScrollBar::SetScrollbar
291 WXHBRUSH
wxScrollBar::OnCtlColor (
301 // Does nothing under OS/2
304 } // end of wxScrollBar::OnCtlColor
306 void wxScrollBar::Command (
307 wxCommandEvent
& rEvent
310 SetThumbPosition(rEvent
.m_commandInt
);
311 ProcessCommand(rEvent
);
312 } // end of wxScrollBar::Command