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