]> git.saurik.com Git - wxWidgets.git/blob - src/os2/scrolbar.cpp
Don't always maximize top-level windows on Smartphone
[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.SetOrientation(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
230 vEvent.SetPosition(nPosition);
231 vEvent.SetEventObject(this);
232 return GetEventHandler()->ProcessEvent(vEvent);
233 } // end of wxScrollBar::OS2OnScroll
234
235 void wxScrollBar::SetThumbPosition (
236 int nViewStart
237 )
238 {
239 SBCDATA vInfo;
240
241 memset(&vInfo, '\0', sizeof(SBCDATA));
242 vInfo.cb = sizeof(SBCDATA);
243 vInfo.posThumb = nViewStart;
244
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
248
249 int wxScrollBar::GetThumbPosition() const
250 {
251 return((int)(MRESULT)::WinSendMsg((HWND)GetHwnd(), SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL));
252 } // end of wxScrollBar::GetThumbPosition
253
254 void wxScrollBar::SetScrollbar (
255 int nPosition
256 , int nThumbSize
257 , int nRange
258 , int nPageSize
259 , bool bRefresh
260 )
261 {
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
291 WXHBRUSH wxScrollBar::OnCtlColor (
292 WXHDC hDC
293 , WXHWND hWnd
294 , WXUINT uCtlColor
295 , WXUINT uMessage
296 , WXWPARAM wParam
297 , WXLPARAM lParam
298 )
299 {
300 //
301 // Does nothing under OS/2
302 //
303 return 0;
304 } // end of wxScrollBar::OnCtlColor
305
306 void wxScrollBar::Command (
307 wxCommandEvent& rEvent
308 )
309 {
310 SetThumbPosition(rEvent.GetInt());
311 ProcessCommand(rEvent);
312 } // end of wxScrollBar::Command
313