]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/scrolbar.cpp
8c70f74b6026a68049d280b5b9ccc59ef7f16134
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 #if !USE_SHARED_LIBRARY
24 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
26 BEGIN_EVENT_TABLE(wxScrollBar
, wxControl
)
27 #if WXWIN_COMPATIBILITY
28 EVT_SCROLL(wxScrollBar::OnScroll
)
35 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
37 const wxSize
& size
, long style
,
38 const wxValidator
& validator
,
43 parent
->AddChild(this);
45 SetValidator(validator
);
47 SetBackgroundColour(parent
->GetBackgroundColour()) ;
48 SetForegroundColour(parent
->GetForegroundColour()) ;
49 m_windowStyle
= style
;
52 m_windowId
= (int)NewControlId();
63 if (style
& wxHORIZONTAL
)
70 if (style
& wxVERTICAL
)
76 // TODO create scrollbar
82 SetFont(parent
->GetFont());
84 m_hWnd
= 0; // TODO: (WXHWND)scroll_bar;
86 // Subclass again for purposes of dialog editing mode
87 SubclassWin((WXHWND
) scroll_bar
);
89 SetSize(x
, y
, width
, height
);
94 wxScrollBar::~wxScrollBar()
98 bool wxScrollBar::OS2OnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
99 WXWORD pos
, WXHWND control
)
103 int position = ::GetScrollPos((HWND) control, SB_CTL);
105 ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos);
107 #if defined(__WIN95__)
108 // A page size greater than one has the effect of reducing the effective
109 // range, therefore the range has already been boosted artificially - so
111 if ( m_pageSize > 1 )
112 maxPos -= (m_pageSize - 1);
115 wxEventType scrollEvent = wxEVT_NULL;
121 nScrollInc = maxPos - position;
122 scrollEvent = wxEVT_SCROLL_TOP;
126 nScrollInc = - position;
127 scrollEvent = wxEVT_SCROLL_BOTTOM;
132 scrollEvent = wxEVT_SCROLL_LINEUP;
137 scrollEvent = wxEVT_SCROLL_LINEDOWN;
141 nScrollInc = -GetPageSize();
142 scrollEvent = wxEVT_SCROLL_PAGEUP;
146 nScrollInc = GetPageSize();
147 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
151 case SB_THUMBPOSITION:
152 nScrollInc = pos - position;
153 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
160 if ( nScrollInc == 0 )
162 // no event to process, so don't process it
166 int new_pos = position + nScrollInc;
170 if (new_pos > maxPos)
173 SetThumbPosition(new_pos);
174 wxScrollEvent event(scrollEvent, m_windowId);
175 event.SetPosition(new_pos);
176 event.SetEventObject( this );
178 return GetEventHandler()->ProcessEvent(event);
183 void wxScrollBar::SetThumbPosition(int viewStart
)
188 int wxScrollBar::GetThumbPosition() const
194 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
197 m_viewSize
= pageSize
;
198 m_pageSize
= thumbSize
;
199 m_objectSize
= range
;
204 #if WXWIN_COMPATIBILITY
205 void wxScrollBar::SetPageSize(int pageLength
)
207 m_pageSize
= pageLength
;
212 void wxScrollBar::SetObjectLength(int objectLength
)
214 m_objectSize
= objectLength
;
216 // The range (number of scroll steps) is the
217 // object length minus the view size.
218 int range
= wxMax((objectLength
- m_viewSize
), 0) ;
223 void wxScrollBar::SetViewLength(int viewLength
)
225 m_viewSize
= viewLength
;
228 void wxScrollBar::GetValues(int *viewStart
, int *viewLength
, int *objectLength
,
229 int *pageLength
) const
233 *viewStart = ::GetScrollPos((HWND)m_hWnd, SB_CTL);
234 *viewLength = m_viewSize;
235 *objectLength = m_objectSize;
236 *pageLength = m_pageSize;
241 WXHBRUSH
wxScrollBar::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
242 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
247 void wxScrollBar::Command(wxCommandEvent
& event
)
249 SetThumbPosition(event
.m_commandInt
);
250 ProcessCommand(event
);
253 #if WXWIN_COMPATIBILITY
254 // Backward compatibility
255 void wxScrollBar::OnScroll(wxScrollEvent
& event
)
259 wxEventType oldEvent = event.GetEventType();
260 event.SetEventType( wxEVT_COMMAND_SCROLLBAR_UPDATED );
261 if ( !GetEventHandler()->ProcessEvent(event) )
263 event.SetEventType( oldEvent );
264 if (!GetParent()->GetEventHandler()->ProcessEvent(event))