]>
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
,
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 HWND scroll_bar
= 0; // temporary
88 // Subclass again for purposes of dialog editing mode
89 SubclassWin((WXHWND
) scroll_bar
);
91 SetSize(x
, y
, width
, height
);
96 wxScrollBar::~wxScrollBar()
100 bool wxScrollBar::OS2OnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
101 WXWORD pos
, WXHWND control
)
105 int position = ::GetScrollPos((HWND) control, SB_CTL);
107 ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos);
109 #if defined(__WIN95__)
110 // A page size greater than one has the effect of reducing the effective
111 // range, therefore the range has already been boosted artificially - so
113 if ( m_pageSize > 1 )
114 maxPos -= (m_pageSize - 1);
117 wxEventType scrollEvent = wxEVT_NULL;
123 nScrollInc = maxPos - position;
124 scrollEvent = wxEVT_SCROLL_TOP;
128 nScrollInc = - position;
129 scrollEvent = wxEVT_SCROLL_BOTTOM;
134 scrollEvent = wxEVT_SCROLL_LINEUP;
139 scrollEvent = wxEVT_SCROLL_LINEDOWN;
143 nScrollInc = -GetPageSize();
144 scrollEvent = wxEVT_SCROLL_PAGEUP;
148 nScrollInc = GetPageSize();
149 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
153 case SB_THUMBPOSITION:
154 nScrollInc = pos - position;
155 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
162 if ( nScrollInc == 0 )
164 // no event to process, so don't process it
168 int new_pos = position + nScrollInc;
172 if (new_pos > maxPos)
175 SetThumbPosition(new_pos);
176 wxScrollEvent event(scrollEvent, m_windowId);
177 event.SetPosition(new_pos);
178 event.SetEventObject( this );
180 return GetEventHandler()->ProcessEvent(event);
185 void wxScrollBar::SetThumbPosition(int viewStart
)
190 int wxScrollBar::GetThumbPosition() const
196 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
199 m_viewSize
= pageSize
;
200 m_pageSize
= thumbSize
;
201 m_objectSize
= range
;
206 #if WXWIN_COMPATIBILITY
207 void wxScrollBar::SetPageSize(int pageLength
)
209 m_pageSize
= pageLength
;
214 void wxScrollBar::SetObjectLength(int objectLength
)
216 m_objectSize
= objectLength
;
218 // The range (number of scroll steps) is the
219 // object length minus the view size.
220 int range
= wxMax((objectLength
- m_viewSize
), 0) ;
225 void wxScrollBar::SetViewLength(int viewLength
)
227 m_viewSize
= viewLength
;
230 void wxScrollBar::GetValues(int *viewStart
, int *viewLength
, int *objectLength
,
231 int *pageLength
) const
235 *viewStart = ::GetScrollPos((HWND)m_hWnd, SB_CTL);
236 *viewLength = m_viewSize;
237 *objectLength = m_objectSize;
238 *pageLength = m_pageSize;
243 WXHBRUSH
wxScrollBar::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
244 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
249 void wxScrollBar::Command(wxCommandEvent
& event
)
251 SetThumbPosition(event
.m_commandInt
);
252 ProcessCommand(event
);
255 #if WXWIN_COMPATIBILITY
256 // Backward compatibility
257 void wxScrollBar::OnScroll(wxScrollEvent
& event
)
261 wxEventType oldEvent = event.GetEventType();
262 event.SetEventType( wxEVT_COMMAND_SCROLLBAR_UPDATED );
263 if ( !GetEventHandler()->ProcessEvent(event) )
265 event.SetEventType( oldEvent );
266 if (!GetParent()->GetEventHandler()->ProcessEvent(event))