]> git.saurik.com Git - wxWidgets.git/blob - src/os2/scrolbar.cpp
Patch [ 688973 ] from William Gallafent: add missing wx/dc.h.
[wxWidgets.git] / src / os2 / scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
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"
18 #endif
19
20 #include "wx/scrolbar.h"
21 #include "wx/os2/private.h"
22
23 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
24
25 // Scrollbar
26 bool 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 )
37 {
38 int nX = rPos.x;
39 int nY = rPos.y;
40 int nWidth = rSize.x;
41 int nHeight = rSize.y;
42
43 if (!pParent)
44 return FALSE;
45 pParent->AddChild(this);
46 SetName(rsName);
47 #if wxUSE_VALIDATORS
48 SetValidator(rValidator);
49 #endif
50 SetBackgroundColour(pParent->GetBackgroundColour()) ;
51 SetForegroundColour(pParent->GetForegroundColour()) ;
52
53 if (vId == -1L)
54 m_windowId = (int)NewControlId();
55 else
56 m_windowId = vId;
57
58 if (nWidth == -1)
59 {
60 if (lStyle & wxHORIZONTAL)
61 nWidth = 140;
62 else
63 nWidth = 14;
64 }
65 if (nHeight == -1)
66 {
67 if (lStyle & wxVERTICAL)
68 nHeight = 140;
69 else
70 nHeight = 14;
71 }
72
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 //
108 // Subclass again for purposes of dialog editing mode
109 //
110 SubclassWin((WXHWND)hScrollBar);
111 SetSize( nX
112 ,nY
113 ,nWidth
114 ,nHeight
115 );
116 return TRUE;
117 } // end of wxScrollBar::Create
118
119 wxScrollBar::~wxScrollBar()
120 {
121 }
122
123 bool wxScrollBar::OS2OnScroll (
124 int nOrientation
125 , WXWORD wParam
126 , WXWORD wPos
127 , WXHWND hControl
128 )
129 {
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;
148
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 //
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.
166 //
167 if (m_nPageSize > 1)
168 nMaxPos -= (m_nPageSize - 1);
169 switch (wParam)
170 {
171 case SB_LINEUP:
172 nScrollInc = -1;
173 vScrollEvent = wxEVT_SCROLL_LINEUP;
174 break;
175
176 case SB_LINEDOWN:
177 nScrollInc = 1;
178 vScrollEvent = wxEVT_SCROLL_LINEDOWN;
179 break;
180
181 case SB_PAGEUP:
182 nScrollInc = -GetPageSize();
183 vScrollEvent = wxEVT_SCROLL_PAGEUP;
184 break;
185
186 case SB_PAGEDOWN:
187 nScrollInc = GetPageSize();
188 vScrollEvent = wxEVT_SCROLL_PAGEDOWN;
189 break;
190
191 case SB_SLIDERTRACK:
192 nScrollInc = nTrackPos - nPosition;
193 vScrollEvent = wxEVT_SCROLL_THUMBTRACK;
194 break;
195
196 case SB_ENDSCROLL:
197 nScrollInc = 0;
198 vScrollEvent = wxEVT_SCROLL_ENDSCROLL;
199 break;
200
201 default:
202 nScrollInc = 0;
203 }
204 if (nScrollInc)
205 {
206 nPosition += nScrollInc;
207
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 )
217 {
218 //
219 // Don't process the event if there is no displacement,
220 // unless this is a thumb release or end scroll event.
221 //
222 return FALSE;
223 }
224
225 wxScrollEvent vEvent( vScrollEvent
226 ,m_windowId
227 );
228
229 vEvent.SetPosition(nPosition);
230 vEvent.SetEventObject(this);
231 return GetEventHandler()->ProcessEvent(vEvent);
232 } // end of wxScrollBar::OS2OnScroll
233
234 void wxScrollBar::SetThumbPosition (
235 int nViewStart
236 )
237 {
238 SBCDATA vInfo;
239
240 memset(&vInfo, '\0', sizeof(SBCDATA));
241 vInfo.cb = sizeof(SBCDATA);
242 vInfo.posThumb = nViewStart;
243
244 ::WinSendMsg((HWND)GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vInfo, (MPARAM)NULL);
245 ::WinSendMsg((HWND)GetHwnd(), SBM_SETPOS, (MPARAM)nViewStart, (MPARAM)NULL);
246 } // end of wxScrollBar::SetThumbPosition
247
248 int wxScrollBar::GetThumbPosition() const
249 {
250 return((int)(MRESULT)::WinSendMsg((HWND)GetHwnd(), SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL));
251 } // end of wxScrollBar::GetThumbPosition
252
253 void wxScrollBar::SetScrollbar (
254 int nPosition
255 , int nThumbSize
256 , int nRange
257 , int nPageSize
258 , bool bRefresh
259 )
260 {
261 SBCDATA vInfo;
262 //
263 // The lRange (number of scroll steps) is the
264 // object length minus the page size.
265 //
266 int nRange1 = wxMax((m_nObjectSize - m_nPageSize), 0);
267
268 m_nViewSize = nPageSize;
269 m_nPageSize = nThumbSize;
270 m_nObjectSize = nRange;
271
272
273 //
274 // Try to adjust the lRange to cope with page size > 1
275 // (see comment for SetPageLength)
276 //
277 if (m_nPageSize > 1 )
278 {
279 nRange1 += (m_nPageSize - 1);
280 }
281 vInfo.cb = sizeof(SBCDATA);
282 vInfo.cVisible = m_nPageSize;
283 vInfo.posFirst = 0;
284 vInfo.posLast = nRange1;
285 vInfo.posThumb = nPosition;
286
287 ::WinSendMsg((HWND)GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vInfo, (MPARAM)NULL);
288 } // end of wxScrollBar::SetScrollbar
289
290 WXHBRUSH wxScrollBar::OnCtlColor (
291 WXHDC hDC
292 , WXHWND hWnd
293 , WXUINT uCtlColor
294 , WXUINT uMessage
295 , WXWPARAM wParam
296 , WXLPARAM lParam
297 )
298 {
299 //
300 // Does nothing under OS/2
301 //
302 return 0;
303 } // end of wxScrollBar::OnCtlColor
304
305 void wxScrollBar::Command (
306 wxCommandEvent& rEvent
307 )
308 {
309 SetThumbPosition(rEvent.m_commandInt);
310 ProcessCommand(rEvent);
311 } // end of wxScrollBar::Command
312