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"
15 #include "wx/scrolbar.h"
21 #include "wx/os2/private.h"
23 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
26 bool wxScrollBar::Create(wxWindow
* pParent
,
32 const wxValidator
& rValidator
,
34 const wxString
& rsName
40 int nHeight
= rSize
.y
;
45 pParent
->AddChild(this);
48 SetValidator(rValidator
);
50 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
51 SetForegroundColour(pParent
->GetForegroundColour()) ;
54 m_windowId
= (int)NewControlId();
58 if (nWidth
== wxDefaultCoord
)
60 if (lStyle
& wxHORIZONTAL
)
65 if (nHeight
== wxDefaultCoord
)
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
, TRUE
);
101 SetFont(*wxSMALL_FONT
);
106 // Subclass again for purposes of dialog editing mode
108 SubclassWin((WXHWND
)hScrollBar
);
115 } // end of wxScrollBar::Create
117 wxScrollBar::~wxScrollBar()
121 bool wxScrollBar::OS2OnScroll ( int WXUNUSED(nOrientation
),
124 WXHWND
WXUNUSED(hControl
) )
128 int nTrackPos
= wPos
;
131 wxEventType vScrollEvent
= wxEVT_NULL
;
136 // When we're dragging the scrollbar we can't use pos parameter because it
137 // is limited to 16 bits
139 if (wParam
== SB_SLIDERPOSITION
|| wParam
== SB_SLIDERTRACK
)
143 vScrollInfo
.sHilite
= SB_SLIDERTRACK
;
145 ::WinSendMsg((HWND
)GetHwnd(), WM_QUERYWINDOWPARAMS
, (PVOID
)&vScrollInfo
, NULL
);
147 nTrackPos
= vScrollInfo
.posThumb
;
148 nPosition
= vScrollInfo
.posFirst
;
149 nMaxPos
= vScrollInfo
.posLast
;
153 nPosition
= (int)(MRESULT
)::WinSendMsg((HWND
)GetHwnd(), SBM_QUERYPOS
, (MPARAM
)NULL
, (MPARAM
)NULL
);
154 vRange
= ::WinSendMsg((HWND
)GetHwnd(), SBM_QUERYRANGE
, (MPARAM
)NULL
, (MPARAM
)NULL
);
155 nMinPos
= SHORT1FROMMR(vRange
);
156 nMaxPos
= SHORT2FROMMR(vRange
);
159 // A page size greater than one has the effect of reducing the effective
160 // range, therefore the range has already been boosted artificially - so
164 nMaxPos
-= (m_nPageSize
- 1);
169 vScrollEvent
= wxEVT_SCROLL_LINEUP
;
174 vScrollEvent
= wxEVT_SCROLL_LINEDOWN
;
178 nScrollInc
= -GetPageSize();
179 vScrollEvent
= wxEVT_SCROLL_PAGEUP
;
183 nScrollInc
= GetPageSize();
184 vScrollEvent
= wxEVT_SCROLL_PAGEDOWN
;
188 nScrollInc
= nTrackPos
- nPosition
;
189 vScrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
194 vScrollEvent
= wxEVT_SCROLL_CHANGED
;
202 nPosition
+= nScrollInc
;
206 if (nPosition
> nMaxPos
)
208 SetThumbPosition(nPosition
);
210 else if ( vScrollEvent
!= wxEVT_SCROLL_THUMBRELEASE
&&
211 vScrollEvent
!= wxEVT_SCROLL_CHANGED
215 // Don't process the event if there is no displacement,
216 // unless this is a thumb release or end scroll event.
221 wxScrollEvent
vEvent( vScrollEvent
225 vEvent
.SetOrientation(IsVertical() ? wxVERTICAL
: wxHORIZONTAL
);
226 vEvent
.SetPosition(nPosition
);
227 vEvent
.SetEventObject(this);
228 return GetEventHandler()->ProcessEvent(vEvent
);
229 } // end of wxScrollBar::OS2OnScroll
231 void wxScrollBar::SetThumbPosition ( int nViewStart
)
235 memset(&vInfo
, '\0', sizeof(SBCDATA
));
236 vInfo
.cb
= sizeof(SBCDATA
);
237 vInfo
.posThumb
= (SHORT
)nViewStart
;
239 ::WinSendMsg((HWND
)GetHwnd(), WM_SETWINDOWPARAMS
, (MPARAM
)&vInfo
, (MPARAM
)NULL
);
240 ::WinSendMsg((HWND
)GetHwnd(), SBM_SETPOS
, (MPARAM
)nViewStart
, (MPARAM
)NULL
);
241 } // end of wxScrollBar::SetThumbPosition
243 int wxScrollBar::GetThumbPosition() const
245 return((int)(MRESULT
)::WinSendMsg((HWND
)GetHwnd(), SBM_QUERYPOS
, (MPARAM
)NULL
, (MPARAM
)NULL
));
246 } // end of wxScrollBar::GetThumbPosition
248 void wxScrollBar::SetScrollbar ( int nPosition
,
252 bool WXUNUSED(bRefresh
) )
256 // The lRange (number of scroll steps) is the
257 // object length minus the page size.
259 int nRange1
= wxMax((m_nObjectSize
- m_nPageSize
), 0);
261 m_nViewSize
= nPageSize
;
262 m_nPageSize
= nThumbSize
;
263 m_nObjectSize
= nRange
;
267 // Try to adjust the lRange to cope with page size > 1
268 // (see comment for SetPageLength)
270 if (m_nPageSize
> 1 )
272 nRange1
+= (m_nPageSize
- 1);
274 vInfo
.cb
= sizeof(SBCDATA
);
275 vInfo
.cVisible
= (SHORT
)m_nPageSize
;
277 vInfo
.posLast
= (SHORT
)nRange1
;
278 vInfo
.posThumb
= (SHORT
)nPosition
;
280 ::WinSendMsg((HWND
)GetHwnd(), WM_SETWINDOWPARAMS
, (MPARAM
)&vInfo
, (MPARAM
)NULL
);
281 } // end of wxScrollBar::SetScrollbar
283 WXHBRUSH
wxScrollBar::OnCtlColor ( WXHDC
WXUNUSED(hDC
),
284 WXHWND
WXUNUSED(hWnd
),
285 WXUINT
WXUNUSED(uCtlColor
),
286 WXUINT
WXUNUSED(uMessage
),
287 WXWPARAM
WXUNUSED(wParam
),
288 WXLPARAM
WXUNUSED(lParam
) )
291 // Does nothing under OS/2
294 } // end of wxScrollBar::OnCtlColor
296 void wxScrollBar::Command ( wxCommandEvent
& rEvent
)
298 SetThumbPosition(rEvent
.GetInt());
299 ProcessCommand(rEvent
);
300 } // end of wxScrollBar::Command