1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/scrolbar.h"
20 #include "wx/os2/private.h"
23 bool wxScrollBar::Create(wxWindow
* pParent
,
29 const wxValidator
& rValidator
,
31 const wxString
& rsName
37 int nHeight
= rSize
.y
;
42 pParent
->AddChild(this);
45 SetValidator(rValidator
);
47 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
48 SetForegroundColour(pParent
->GetForegroundColour()) ;
51 m_windowId
= (int)NewControlId();
55 if (nWidth
== wxDefaultCoord
)
57 if (lStyle
& wxHORIZONTAL
)
62 if (nHeight
== wxDefaultCoord
)
64 if (lStyle
& wxVERTICAL
)
70 DWORD dwStyle
= WS_VISIBLE
;
72 if (GetWindowStyleFlag() & wxCLIP_SIBLINGS
)
73 dwStyle
|= WS_CLIPSIBLINGS
;
75 DWORD dwDirection
= (lStyle
& wxHORIZONTAL
) ? SBS_HORZ
: SBS_VERT
;
77 HWND hScrollBar
= ::WinCreateWindow( (HWND
)GetHwndOf(pParent
)
80 ,dwDirection
| dwStyle
82 ,(HWND
)GetHwndOf(pParent
)
92 ::WinSendMsg( hScrollBar
97 ::WinShowWindow( hScrollBar
, TRUE
);
98 SetFont(*wxSMALL_FONT
);
103 // Subclass again for purposes of dialog editing mode
105 SubclassWin((WXHWND
)hScrollBar
);
112 } // end of wxScrollBar::Create
114 wxScrollBar::~wxScrollBar()
118 bool wxScrollBar::OS2OnScroll ( int WXUNUSED(nOrientation
),
121 WXHWND
WXUNUSED(hControl
) )
125 int nTrackPos
= wPos
;
128 wxEventType vScrollEvent
= wxEVT_NULL
;
133 // When we're dragging the scrollbar we can't use pos parameter because it
134 // is limited to 16 bits
136 if (wParam
== SB_SLIDERPOSITION
|| wParam
== SB_SLIDERTRACK
)
140 vScrollInfo
.sHilite
= SB_SLIDERTRACK
;
142 ::WinSendMsg((HWND
)GetHwnd(), WM_QUERYWINDOWPARAMS
, (PVOID
)&vScrollInfo
, NULL
);
144 nTrackPos
= vScrollInfo
.posThumb
;
145 nPosition
= vScrollInfo
.posFirst
;
146 nMaxPos
= vScrollInfo
.posLast
;
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
);
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
161 nMaxPos
-= (m_nPageSize
- 1);
166 vScrollEvent
= wxEVT_SCROLL_LINEUP
;
171 vScrollEvent
= wxEVT_SCROLL_LINEDOWN
;
175 nScrollInc
= -GetPageSize();
176 vScrollEvent
= wxEVT_SCROLL_PAGEUP
;
180 nScrollInc
= GetPageSize();
181 vScrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
185 nScrollInc
= nTrackPos
- nPosition
;
186 vScrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
191 vScrollEvent
= wxEVT_SCROLL_CHANGED
;
199 nPosition
+= nScrollInc
;
203 if (nPosition
> nMaxPos
)
205 SetThumbPosition(nPosition
);
207 else if ( vScrollEvent
!= wxEVT_SCROLL_THUMBRELEASE
&&
208 vScrollEvent
!= wxEVT_SCROLL_CHANGED
212 // Don't process the event if there is no displacement,
213 // unless this is a thumb release or end scroll event.
218 wxScrollEvent
vEvent( vScrollEvent
222 vEvent
.SetOrientation(IsVertical() ? wxVERTICAL
: wxHORIZONTAL
);
223 vEvent
.SetPosition(nPosition
);
224 vEvent
.SetEventObject(this);
225 return HandleWindowEvent(vEvent
);
226 } // end of wxScrollBar::OS2OnScroll
228 void wxScrollBar::SetThumbPosition ( int nViewStart
)
232 memset(&vInfo
, '\0', sizeof(SBCDATA
));
233 vInfo
.cb
= sizeof(SBCDATA
);
234 vInfo
.posThumb
= (SHORT
)nViewStart
;
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
240 int wxScrollBar::GetThumbPosition() const
242 return((int)(MRESULT
)::WinSendMsg((HWND
)GetHwnd(), SBM_QUERYPOS
, (MPARAM
)NULL
, (MPARAM
)NULL
));
243 } // end of wxScrollBar::GetThumbPosition
245 void wxScrollBar::SetScrollbar ( int nPosition
,
249 bool WXUNUSED(bRefresh
) )
253 // The lRange (number of scroll steps) is the
254 // object length minus the page size.
256 int nRange1
= wxMax((m_nObjectSize
- m_nPageSize
), 0);
258 m_nViewSize
= nPageSize
;
259 m_nPageSize
= nThumbSize
;
260 m_nObjectSize
= nRange
;
264 // Try to adjust the lRange to cope with page size > 1
265 // (see comment for SetPageLength)
267 if (m_nPageSize
> 1 )
269 nRange1
+= (m_nPageSize
- 1);
271 vInfo
.cb
= sizeof(SBCDATA
);
272 vInfo
.cVisible
= (SHORT
)m_nPageSize
;
274 vInfo
.posLast
= (SHORT
)nRange1
;
275 vInfo
.posThumb
= (SHORT
)nPosition
;
277 ::WinSendMsg((HWND
)GetHwnd(), WM_SETWINDOWPARAMS
, (MPARAM
)&vInfo
, (MPARAM
)NULL
);
278 } // end of wxScrollBar::SetScrollbar
280 WXHBRUSH
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
) )
288 // Does nothing under OS/2
291 } // end of wxScrollBar::OnCtlColor
293 void wxScrollBar::Command ( wxCommandEvent
& rEvent
)
295 SetThumbPosition(rEvent
.GetInt());
296 ProcessCommand(rEvent
);
297 } // end of wxScrollBar::Command