]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
20 #include "wx/scrolbar.h"
21 #include "wx/os2/private.h"
23 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
25 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
26 #if WXWIN_COMPATIBILITY
27 EVT_SCROLL(wxScrollBar::OnScroll
)
33 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
35 const wxSize
& size
, long style
,
37 const wxValidator
& validator
,
43 parent
->AddChild(this);
46 SetValidator(validator
);
49 SetBackgroundColour(parent
->GetBackgroundColour()) ;
50 SetForegroundColour(parent
->GetForegroundColour()) ;
51 m_windowStyle
= style
;
54 m_windowId
= (int)NewControlId();
65 if (style
& wxHORIZONTAL
)
72 if (style
& wxVERTICAL
)
78 // TODO create scrollbar
84 SetFont(parent
->GetFont());
86 m_hWnd
= 0; // TODO: (WXHWND)scroll_bar;
88 HWND scroll_bar
= 0; // temporary
90 // Subclass again for purposes of dialog editing mode
91 SubclassWin((WXHWND
) scroll_bar
);
93 SetSize(x
, y
, width
, height
);
98 wxScrollBar::~wxScrollBar()
102 bool wxScrollBar::OS2OnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
103 WXWORD pos
, WXHWND control
)
107 int position = ::GetScrollPos((HWND) control, SB_CTL);
109 ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos);
111 #if defined(__WIN95__)
112 // A page size greater than one has the effect of reducing the effective
113 // range, therefore the range has already been boosted artificially - so
115 if ( m_pageSize > 1 )
116 maxPos -= (m_pageSize - 1);
119 wxEventType scrollEvent = wxEVT_NULL;
125 nScrollInc = maxPos - position;
126 scrollEvent = wxEVT_SCROLL_TOP;
130 nScrollInc = - position;
131 scrollEvent = wxEVT_SCROLL_BOTTOM;
136 scrollEvent = wxEVT_SCROLL_LINEUP;
141 scrollEvent = wxEVT_SCROLL_LINEDOWN;
145 nScrollInc = -GetPageSize();
146 scrollEvent = wxEVT_SCROLL_PAGEUP;
150 nScrollInc = GetPageSize();
151 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
155 case SB_THUMBPOSITION:
156 nScrollInc = pos - position;
157 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
164 if ( nScrollInc == 0 )
166 // no event to process, so don't process it
170 int new_pos = position + nScrollInc;
174 if (new_pos > maxPos)
177 SetThumbPosition(new_pos);
178 wxScrollEvent event(scrollEvent, m_windowId);
179 event.SetPosition(new_pos);
180 event.SetEventObject( this );
182 return GetEventHandler()->ProcessEvent(event);
187 void wxScrollBar::SetThumbPosition(int viewStart
)
192 int wxScrollBar::GetThumbPosition() const
198 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
201 m_viewSize
= pageSize
;
202 m_pageSize
= thumbSize
;
203 m_objectSize
= range
;
208 #if WXWIN_COMPATIBILITY
209 void wxScrollBar::SetPageSize(int pageLength
)
211 m_pageSize
= pageLength
;
216 void wxScrollBar::SetObjectLength(int objectLength
)
218 m_objectSize
= objectLength
;
220 // The range (number of scroll steps) is the
221 // object length minus the view size.
222 int range
= wxMax((objectLength
- m_viewSize
), 0) ;
227 void wxScrollBar::SetViewLength(int viewLength
)
229 m_viewSize
= viewLength
;
232 void wxScrollBar::GetValues(int *viewStart
, int *viewLength
, int *objectLength
,
233 int *pageLength
) const
237 *viewStart = ::GetScrollPos((HWND)m_hWnd, SB_CTL);
238 *viewLength = m_viewSize;
239 *objectLength = m_objectSize;
240 *pageLength = m_pageSize;
245 WXHBRUSH
wxScrollBar::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
246 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
251 void wxScrollBar::Command(wxCommandEvent
& event
)
253 SetThumbPosition(event
.m_commandInt
);
254 ProcessCommand(event
);
257 #if WXWIN_COMPATIBILITY
258 // Backward compatibility
259 void wxScrollBar::OnScroll(wxScrollEvent
& event
)
263 wxEventType oldEvent = event.GetEventType();
264 event.SetEventType( wxEVT_COMMAND_SCROLLBAR_UPDATED );
265 if ( !GetEventHandler()->ProcessEvent(event) )
267 event.SetEventType( oldEvent );
268 if (!GetParent()->GetEventHandler()->ProcessEvent(event))