]>
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 const wxValidator
& validator
,
45 parent
->AddChild(this);
48 SetValidator(validator
);
51 SetBackgroundColour(parent
->GetBackgroundColour()) ;
52 SetForegroundColour(parent
->GetForegroundColour()) ;
53 m_windowStyle
= style
;
56 m_windowId
= (int)NewControlId();
67 if (style
& wxHORIZONTAL
)
74 if (style
& wxVERTICAL
)
80 // TODO create scrollbar
86 SetFont(parent
->GetFont());
88 m_hWnd
= 0; // TODO: (WXHWND)scroll_bar;
90 HWND scroll_bar
= 0; // temporary
92 // Subclass again for purposes of dialog editing mode
93 SubclassWin((WXHWND
) scroll_bar
);
95 SetSize(x
, y
, width
, height
);
100 wxScrollBar::~wxScrollBar()
104 bool wxScrollBar::OS2OnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
105 WXWORD pos
, WXHWND control
)
109 int position = ::GetScrollPos((HWND) control, SB_CTL);
111 ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos);
113 #if defined(__WIN95__)
114 // A page size greater than one has the effect of reducing the effective
115 // range, therefore the range has already been boosted artificially - so
117 if ( m_pageSize > 1 )
118 maxPos -= (m_pageSize - 1);
121 wxEventType scrollEvent = wxEVT_NULL;
127 nScrollInc = maxPos - position;
128 scrollEvent = wxEVT_SCROLL_TOP;
132 nScrollInc = - position;
133 scrollEvent = wxEVT_SCROLL_BOTTOM;
138 scrollEvent = wxEVT_SCROLL_LINEUP;
143 scrollEvent = wxEVT_SCROLL_LINEDOWN;
147 nScrollInc = -GetPageSize();
148 scrollEvent = wxEVT_SCROLL_PAGEUP;
152 nScrollInc = GetPageSize();
153 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
157 case SB_THUMBPOSITION:
158 nScrollInc = pos - position;
159 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
166 if ( nScrollInc == 0 )
168 // no event to process, so don't process it
172 int new_pos = position + nScrollInc;
176 if (new_pos > maxPos)
179 SetThumbPosition(new_pos);
180 wxScrollEvent event(scrollEvent, m_windowId);
181 event.SetPosition(new_pos);
182 event.SetEventObject( this );
184 return GetEventHandler()->ProcessEvent(event);
189 void wxScrollBar::SetThumbPosition(int viewStart
)
194 int wxScrollBar::GetThumbPosition() const
200 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
203 m_viewSize
= pageSize
;
204 m_pageSize
= thumbSize
;
205 m_objectSize
= range
;
210 #if WXWIN_COMPATIBILITY
211 void wxScrollBar::SetPageSize(int pageLength
)
213 m_pageSize
= pageLength
;
218 void wxScrollBar::SetObjectLength(int objectLength
)
220 m_objectSize
= objectLength
;
222 // The range (number of scroll steps) is the
223 // object length minus the view size.
224 int range
= wxMax((objectLength
- m_viewSize
), 0) ;
229 void wxScrollBar::SetViewLength(int viewLength
)
231 m_viewSize
= viewLength
;
234 void wxScrollBar::GetValues(int *viewStart
, int *viewLength
, int *objectLength
,
235 int *pageLength
) const
239 *viewStart = ::GetScrollPos((HWND)m_hWnd, SB_CTL);
240 *viewLength = m_viewSize;
241 *objectLength = m_objectSize;
242 *pageLength = m_pageSize;
247 WXHBRUSH
wxScrollBar::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
248 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
253 void wxScrollBar::Command(wxCommandEvent
& event
)
255 SetThumbPosition(event
.m_commandInt
);
256 ProcessCommand(event
);
259 #if WXWIN_COMPATIBILITY
260 // Backward compatibility
261 void wxScrollBar::OnScroll(wxScrollEvent
& event
)
265 wxEventType oldEvent = event.GetEventType();
266 event.SetEventType( wxEVT_COMMAND_SCROLLBAR_UPDATED );
267 if ( !GetEventHandler()->ProcessEvent(event) )
269 event.SetEventType( oldEvent );
270 if (!GetParent()->GetEventHandler()->ProcessEvent(event))