1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/scrolbar.cpp
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"
19 #include "wx/scrolbar.h"
20 #include "wx/os2/private.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
25 bool wxScrollBar::Create(wxWindow
* pParent
,
31 const wxValidator
& rValidator
,
33 const wxString
& rsName
39 int nHeight
= rSize
.y
;
44 pParent
->AddChild(this);
47 SetValidator(rValidator
);
49 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
50 SetForegroundColour(pParent
->GetForegroundColour()) ;
53 m_windowId
= (int)NewControlId();
57 if (nWidth
== wxDefaultCoord
)
59 if (lStyle
& wxHORIZONTAL
)
64 if (nHeight
== wxDefaultCoord
)
66 if (lStyle
& wxVERTICAL
)
72 DWORD dwStyle
= WS_VISIBLE
;
74 if (GetWindowStyleFlag() & wxCLIP_SIBLINGS
)
75 dwStyle
|= WS_CLIPSIBLINGS
;
77 DWORD dwDirection
= (lStyle
& wxHORIZONTAL
) ? SBS_HORZ
: SBS_VERT
;
79 HWND hScrollBar
= ::WinCreateWindow( (HWND
)GetHwndOf(pParent
)
82 ,dwDirection
| dwStyle
84 ,(HWND
)GetHwndOf(pParent
)
94 ::WinSendMsg( hScrollBar
99 ::WinShowWindow( hScrollBar
, TRUE
);
100 SetFont(*wxSMALL_FONT
);
105 // Subclass again for purposes of dialog editing mode
107 SubclassWin((WXHWND
)hScrollBar
);
114 } // end of wxScrollBar::Create
116 wxScrollBar::~wxScrollBar()
120 bool wxScrollBar::OS2OnScroll ( int WXUNUSED(nOrientation
),
123 WXHWND
WXUNUSED(hControl
) )
127 int nTrackPos
= wPos
;
130 wxEventType vScrollEvent
= wxEVT_NULL
;
135 // When we're dragging the scrollbar we can't use pos parameter because it
136 // is limited to 16 bits
138 if (wParam
== SB_SLIDERPOSITION
|| wParam
== SB_SLIDERTRACK
)
142 vScrollInfo
.sHilite
= SB_SLIDERTRACK
;
144 ::WinSendMsg((HWND
)GetHwnd(), WM_QUERYWINDOWPARAMS
, (PVOID
)&vScrollInfo
, NULL
);
146 nTrackPos
= vScrollInfo
.posThumb
;
147 nPosition
= vScrollInfo
.posFirst
;
148 nMaxPos
= vScrollInfo
.posLast
;
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
);
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
163 nMaxPos
-= (m_nPageSize
- 1);
168 vScrollEvent
= wxEVT_SCROLL_LINEUP
;
173 vScrollEvent
= wxEVT_SCROLL_LINEDOWN
;
177 nScrollInc
= -GetPageSize();
178 vScrollEvent
= wxEVT_SCROLL_PAGEUP
;
182 nScrollInc
= GetPageSize();
183 vScrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
187 nScrollInc
= nTrackPos
- nPosition
;
188 vScrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
193 vScrollEvent
= wxEVT_SCROLL_CHANGED
;
201 nPosition
+= nScrollInc
;
205 if (nPosition
> nMaxPos
)
207 SetThumbPosition(nPosition
);
209 else if ( vScrollEvent
!= wxEVT_SCROLL_THUMBRELEASE
&&
210 vScrollEvent
!= wxEVT_SCROLL_CHANGED
214 // Don't process the event if there is no displacement,
215 // unless this is a thumb release or end scroll event.
220 wxScrollEvent
vEvent( vScrollEvent
224 vEvent
.SetOrientation(IsVertical() ? wxVERTICAL
: wxHORIZONTAL
);
225 vEvent
.SetPosition(nPosition
);
226 vEvent
.SetEventObject(this);
227 return GetEventHandler()->ProcessEvent(vEvent
);
228 } // end of wxScrollBar::OS2OnScroll
230 void wxScrollBar::SetThumbPosition ( int nViewStart
)
234 memset(&vInfo
, '\0', sizeof(SBCDATA
));
235 vInfo
.cb
= sizeof(SBCDATA
);
236 vInfo
.posThumb
= (SHORT
)nViewStart
;
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
242 int wxScrollBar::GetThumbPosition() const
244 return((int)(MRESULT
)::WinSendMsg((HWND
)GetHwnd(), SBM_QUERYPOS
, (MPARAM
)NULL
, (MPARAM
)NULL
));
245 } // end of wxScrollBar::GetThumbPosition
247 void wxScrollBar::SetScrollbar ( int nPosition
,
251 bool WXUNUSED(bRefresh
) )
255 // The lRange (number of scroll steps) is the
256 // object length minus the page size.
258 int nRange1
= wxMax((m_nObjectSize
- m_nPageSize
), 0);
260 m_nViewSize
= nPageSize
;
261 m_nPageSize
= nThumbSize
;
262 m_nObjectSize
= nRange
;
266 // Try to adjust the lRange to cope with page size > 1
267 // (see comment for SetPageLength)
269 if (m_nPageSize
> 1 )
271 nRange1
+= (m_nPageSize
- 1);
273 vInfo
.cb
= sizeof(SBCDATA
);
274 vInfo
.cVisible
= (SHORT
)m_nPageSize
;
276 vInfo
.posLast
= (SHORT
)nRange1
;
277 vInfo
.posThumb
= (SHORT
)nPosition
;
279 ::WinSendMsg((HWND
)GetHwnd(), WM_SETWINDOWPARAMS
, (MPARAM
)&vInfo
, (MPARAM
)NULL
);
280 } // end of wxScrollBar::SetScrollbar
282 WXHBRUSH
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
) )
290 // Does nothing under OS/2
293 } // end of wxScrollBar::OnCtlColor
295 void wxScrollBar::Command ( wxCommandEvent
& rEvent
)
297 SetThumbPosition(rEvent
.GetInt());
298 ProcessCommand(rEvent
);
299 } // end of wxScrollBar::Command