]>
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 #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
,
39 # if defined(__VISAGECPP__)
40 const wxValidator
* validator
,
42 const wxValidator
& validator
,
49 parent
->AddChild(this);
52 SetValidator(validator
);
55 SetBackgroundColour(parent
->GetBackgroundColour()) ;
56 SetForegroundColour(parent
->GetForegroundColour()) ;
57 m_windowStyle
= style
;
60 m_windowId
= (int)NewControlId();
71 if (style
& wxHORIZONTAL
)
78 if (style
& wxVERTICAL
)
84 // TODO create scrollbar
90 SetFont(parent
->GetFont());
92 m_hWnd
= 0; // TODO: (WXHWND)scroll_bar;
94 HWND scroll_bar
= 0; // temporary
96 // Subclass again for purposes of dialog editing mode
97 SubclassWin((WXHWND
) scroll_bar
);
99 SetSize(x
, y
, width
, height
);
104 wxScrollBar::~wxScrollBar()
108 bool wxScrollBar::OS2OnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
109 WXWORD pos
, WXHWND control
)
113 int position = ::GetScrollPos((HWND) control, SB_CTL);
115 ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos);
117 #if defined(__WIN95__)
118 // A page size greater than one has the effect of reducing the effective
119 // range, therefore the range has already been boosted artificially - so
121 if ( m_pageSize > 1 )
122 maxPos -= (m_pageSize - 1);
125 wxEventType scrollEvent = wxEVT_NULL;
131 nScrollInc = maxPos - position;
132 scrollEvent = wxEVT_SCROLL_TOP;
136 nScrollInc = - position;
137 scrollEvent = wxEVT_SCROLL_BOTTOM;
142 scrollEvent = wxEVT_SCROLL_LINEUP;
147 scrollEvent = wxEVT_SCROLL_LINEDOWN;
151 nScrollInc = -GetPageSize();
152 scrollEvent = wxEVT_SCROLL_PAGEUP;
156 nScrollInc = GetPageSize();
157 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
161 case SB_THUMBPOSITION:
162 nScrollInc = pos - position;
163 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
170 if ( nScrollInc == 0 )
172 // no event to process, so don't process it
176 int new_pos = position + nScrollInc;
180 if (new_pos > maxPos)
183 SetThumbPosition(new_pos);
184 wxScrollEvent event(scrollEvent, m_windowId);
185 event.SetPosition(new_pos);
186 event.SetEventObject( this );
188 return GetEventHandler()->ProcessEvent(event);
193 void wxScrollBar::SetThumbPosition(int viewStart
)
198 int wxScrollBar::GetThumbPosition() const
204 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
207 m_viewSize
= pageSize
;
208 m_pageSize
= thumbSize
;
209 m_objectSize
= range
;
214 #if WXWIN_COMPATIBILITY
215 void wxScrollBar::SetPageSize(int pageLength
)
217 m_pageSize
= pageLength
;
222 void wxScrollBar::SetObjectLength(int objectLength
)
224 m_objectSize
= objectLength
;
226 // The range (number of scroll steps) is the
227 // object length minus the view size.
228 int range
= wxMax((objectLength
- m_viewSize
), 0) ;
233 void wxScrollBar::SetViewLength(int viewLength
)
235 m_viewSize
= viewLength
;
238 void wxScrollBar::GetValues(int *viewStart
, int *viewLength
, int *objectLength
,
239 int *pageLength
) const
243 *viewStart = ::GetScrollPos((HWND)m_hWnd, SB_CTL);
244 *viewLength = m_viewSize;
245 *objectLength = m_objectSize;
246 *pageLength = m_pageSize;
251 WXHBRUSH
wxScrollBar::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
252 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
257 void wxScrollBar::Command(wxCommandEvent
& event
)
259 SetThumbPosition(event
.m_commandInt
);
260 ProcessCommand(event
);
263 #if WXWIN_COMPATIBILITY
264 // Backward compatibility
265 void wxScrollBar::OnScroll(wxScrollEvent
& event
)
269 wxEventType oldEvent = event.GetEventType();
270 event.SetEventType( wxEVT_COMMAND_SCROLLBAR_UPDATED );
271 if ( !GetEventHandler()->ProcessEvent(event) )
273 event.SetEventType( oldEvent );
274 if (!GetParent()->GetEventHandler()->ProcessEvent(event))