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