]> git.saurik.com Git - wxWidgets.git/blame - src/os2/scrolbar.cpp
Wrappers for *ToText
[wxWidgets.git] / src / os2 / scrolbar.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: scrolbar.cpp
3// Purpose: wxScrollBar
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
409c9842 6// Created: 10/15/99
0e320a79 7// RCS-ID: $Id$
409c9842 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
409c9842
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifndef WX_PRECOMP
16#include "wx/defs.h"
17#include "wx/utils.h"
0e320a79
DW
18#endif
19
20#include "wx/scrolbar.h"
409c9842 21#include "wx/os2/private.h"
0e320a79 22
0e320a79
DW
23IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
24
0e320a79 25// Scrollbar
57ff8a87
DW
26bool wxScrollBar::Create (
27 wxWindow* pParent
28, wxWindowID vId
29, const wxPoint& rPos
30, const wxSize& rSize
31, long lStyle
32#if wxUSE_VALIDATORS
33, const wxValidator& rValidator
34#endif
35, const wxString& rsName
36)
0e320a79 37{
57ff8a87
DW
38 int nX = rPos.x;
39 int nY = rPos.y;
40 int nWidth = rSize.x;
41 int nHeight = rSize.y;
42
2f60dbe2 43 if (!pParent)
0e320a79 44 return FALSE;
57ff8a87
DW
45 pParent->AddChild(this);
46 SetName(rsName);
5d4b632b 47#if wxUSE_VALIDATORS
57ff8a87 48 SetValidator(rValidator);
5d4b632b 49#endif
57ff8a87
DW
50 SetBackgroundColour(pParent->GetBackgroundColour()) ;
51 SetForegroundColour(pParent->GetForegroundColour()) ;
04701dd9 52
57ff8a87 53 if (vId == -1L)
409c9842 54 m_windowId = (int)NewControlId();
0e320a79 55 else
57ff8a87 56 m_windowId = vId;
409c9842 57
57ff8a87 58 if (nWidth == -1)
409c9842 59 {
57ff8a87
DW
60 if (lStyle & wxHORIZONTAL)
61 nWidth = 140;
409c9842 62 else
57ff8a87 63 nWidth = 14;
409c9842 64 }
57ff8a87 65 if (nHeight == -1)
409c9842 66 {
57ff8a87
DW
67 if (lStyle & wxVERTICAL)
68 nHeight = 140;
409c9842 69 else
57ff8a87 70 nHeight = 14;
409c9842 71 }
0e320a79 72
57ff8a87
DW
73 DWORD dwStyle = WS_VISIBLE;
74
75 if (GetWindowStyleFlag() & wxCLIP_SIBLINGS)
76 dwStyle |= WS_CLIPSIBLINGS;
77
78 DWORD dwDirection = (lStyle & wxHORIZONTAL) ? SBS_HORZ: SBS_VERT;
79
80 HWND hScrollBar = ::WinCreateWindow( (HWND)GetHwndOf(pParent)
81 ,WC_SCROLLBAR
82 ,(PSZ)NULL
83 ,dwDirection | dwStyle
84 ,0, 0, 0, 0
85 ,(HWND)GetHwndOf(pParent)
86 ,HWND_TOP
87 ,(HMENU)m_windowId
88 ,NULL
89 ,NULL
90 );
91
92 m_nPageSize = 1;
93 m_nViewSize = 1;
94 m_nObjectSize = 1;
95 ::WinSendMsg( hScrollBar
96 ,SBM_SETSCROLLBAR
97 ,(MPARAM)0
98 ,MPFROM2SHORT(0,1)
99 );
100 ::WinShowWindow( hScrollBar
101 ,TRUE
102 );
103 SetFont(*wxSMALL_FONT);
104
105 m_hWnd = hScrollBar;
106
107 //
409c9842 108 // Subclass again for purposes of dialog editing mode
57ff8a87
DW
109 //
110 SubclassWin((WXHWND)hScrollBar);
111 SetSize( nX
112 ,nY
113 ,nWidth
114 ,nHeight
115 );
0e320a79 116 return TRUE;
57ff8a87 117} // end of wxScrollBar::Create
0e320a79
DW
118
119wxScrollBar::~wxScrollBar()
120{
121}
122
57ff8a87
DW
123bool wxScrollBar::OS2OnScroll (
124 int nOrientation
125, WXWORD wParam
126, WXWORD wPos
127, WXHWND hControl
128)
409c9842 129{
57ff8a87
DW
130 int nPosition;
131 int nMaxPos;
132 int nTrackPos = wPos;
133 int nMinPos;
134 int nScrollInc;
135 wxEventType vScrollEvent = wxEVT_NULL;
136
137 MRESULT vRange;
138
139 //
140 // When we're dragging the scrollbar we can't use pos parameter because it
141 // is limited to 16 bits
142 //
143 if (wParam == SB_SLIDERPOSITION || wParam == SB_SLIDERTRACK)
144 {
145 SBCDATA vScrollInfo;
146
147 vScrollInfo.sHilite = SB_SLIDERTRACK;
409c9842 148
57ff8a87
DW
149 ::WinSendMsg((HWND)GetHwnd(), WM_QUERYWINDOWPARAMS, (PVOID)&vScrollInfo, NULL);
150
151 nTrackPos = vScrollInfo.posThumb;
152 nPosition = vScrollInfo.posFirst;
153 nMaxPos = vScrollInfo.posLast;
154 }
155 else
156 {
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);
161 }
162 //
409c9842
DW
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
165 // reduce it again.
57ff8a87
DW
166 //
167 if (m_nPageSize > 1)
168 nMaxPos -= (m_nPageSize - 1);
169 switch (wParam)
409c9842 170 {
409c9842 171 case SB_LINEUP:
57ff8a87
DW
172 nScrollInc = -1;
173 vScrollEvent = wxEVT_SCROLL_LINEUP;
409c9842
DW
174 break;
175
176 case SB_LINEDOWN:
57ff8a87
DW
177 nScrollInc = 1;
178 vScrollEvent = wxEVT_SCROLL_LINEDOWN;
409c9842
DW
179 break;
180
181 case SB_PAGEUP:
57ff8a87
DW
182 nScrollInc = -GetPageSize();
183 vScrollEvent = wxEVT_SCROLL_PAGEUP;
409c9842
DW
184 break;
185
186 case SB_PAGEDOWN:
57ff8a87
DW
187 nScrollInc = GetPageSize();
188 vScrollEvent = wxEVT_SCROLL_PAGEDOWN;
189 break;
190
191 case SB_SLIDERTRACK:
192 nScrollInc = nTrackPos - nPosition;
193 vScrollEvent = wxEVT_SCROLL_THUMBTRACK;
409c9842
DW
194 break;
195
57ff8a87
DW
196 case SB_ENDSCROLL:
197 nScrollInc = 0;
198 vScrollEvent = wxEVT_SCROLL_ENDSCROLL;
409c9842
DW
199 break;
200
201 default:
202 nScrollInc = 0;
203 }
57ff8a87
DW
204 if (nScrollInc)
205 {
206 nPosition += nScrollInc;
409c9842 207
57ff8a87
DW
208 if (nPosition < 0)
209 nPosition = 0;
210 if (nPosition > nMaxPos)
211 nPosition = nMaxPos;
212 SetThumbPosition(nPosition);
213 }
214 else if ( vScrollEvent != wxEVT_SCROLL_THUMBRELEASE &&
215 vScrollEvent != wxEVT_SCROLL_ENDSCROLL
216 )
409c9842 217 {
57ff8a87
DW
218 //
219 // Don't process the event if there is no displacement,
220 // unless this is a thumb release or end scroll event.
221 //
409c9842
DW
222 return FALSE;
223 }
224
57ff8a87
DW
225 wxScrollEvent vEvent( vScrollEvent
226 ,m_windowId
227 );
409c9842 228
6e348b12 229 vEvent.SetOrientation(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
57ff8a87
DW
230 vEvent.SetPosition(nPosition);
231 vEvent.SetEventObject(this);
232 return GetEventHandler()->ProcessEvent(vEvent);
233} // end of wxScrollBar::OS2OnScroll
409c9842 234
57ff8a87
DW
235void wxScrollBar::SetThumbPosition (
236 int nViewStart
237)
409c9842 238{
57ff8a87 239 SBCDATA vInfo;
409c9842 240
57ff8a87
DW
241 memset(&vInfo, '\0', sizeof(SBCDATA));
242 vInfo.cb = sizeof(SBCDATA);
243 vInfo.posThumb = nViewStart;
409c9842 244
57ff8a87
DW
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
409c9842 248
57ff8a87 249int wxScrollBar::GetThumbPosition() const
409c9842 250{
57ff8a87
DW
251 return((int)(MRESULT)::WinSendMsg((HWND)GetHwnd(), SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL));
252} // end of wxScrollBar::GetThumbPosition
253
254void wxScrollBar::SetScrollbar (
255 int nPosition
256, int nThumbSize
257, int nRange
258, int nPageSize
259, bool bRefresh
260)
409c9842 261{
57ff8a87
DW
262 SBCDATA vInfo;
263 //
264 // The lRange (number of scroll steps) is the
265 // object length minus the page size.
266 //
267 int nRange1 = wxMax((m_nObjectSize - m_nPageSize), 0);
268
269 m_nViewSize = nPageSize;
270 m_nPageSize = nThumbSize;
271 m_nObjectSize = nRange;
272
273
274 //
275 // Try to adjust the lRange to cope with page size > 1
276 // (see comment for SetPageLength)
277 //
278 if (m_nPageSize > 1 )
279 {
280 nRange1 += (m_nPageSize - 1);
281 }
282 vInfo.cb = sizeof(SBCDATA);
283 vInfo.cVisible = m_nPageSize;
284 vInfo.posFirst = 0;
285 vInfo.posLast = nRange1;
286 vInfo.posThumb = nPosition;
287
288 ::WinSendMsg((HWND)GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vInfo, (MPARAM)NULL);
289} // end of wxScrollBar::SetScrollbar
290
291WXHBRUSH wxScrollBar::OnCtlColor (
292 WXHDC hDC
293, WXHWND hWnd
294, WXUINT uCtlColor
295, WXUINT uMessage
296, WXWPARAM wParam
297, WXLPARAM lParam
298)
409c9842 299{
57ff8a87
DW
300 //
301 // Does nothing under OS/2
302 //
303 return 0;
304} // end of wxScrollBar::OnCtlColor
0e320a79 305
57ff8a87
DW
306void wxScrollBar::Command (
307 wxCommandEvent& rEvent
308)
0e320a79 309{
57ff8a87
DW
310 SetThumbPosition(rEvent.m_commandInt);
311 ProcessCommand(rEvent);
312} // end of wxScrollBar::Command
0e320a79 313