no message
[wxWidgets.git] / src / os2 / scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/defs.h"
17 #include "wx/utils.h"
18 #endif
19
20 #include "wx/scrolbar.h"
21 #include "wx/os2/private.h"
22
23 #if !USE_SHARED_LIBRARY
24 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
25
26 BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
27 #if WXWIN_COMPATIBILITY
28 EVT_SCROLL(wxScrollBar::OnScroll)
29 #endif
30 END_EVENT_TABLE()
31
32 #endif
33
34 // Scrollbar
35 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
36 const wxPoint& pos,
37 const wxSize& size, long style,
38 const wxValidator& validator,
39 const wxString& name)
40 {
41 if (!parent)
42 return FALSE;
43 parent->AddChild(this);
44 SetName(name);
45 SetValidator(validator);
46
47 SetBackgroundColour(parent->GetBackgroundColour()) ;
48 SetForegroundColour(parent->GetForegroundColour()) ;
49 m_windowStyle = style;
50
51 if ( id == -1 )
52 m_windowId = (int)NewControlId();
53 else
54 m_windowId = id;
55
56 int x = pos.x;
57 int y = pos.y;
58 int width = size.x;
59 int height = size.y;
60
61 if (width == -1)
62 {
63 if (style & wxHORIZONTAL)
64 width = 140;
65 else
66 width = 14;
67 }
68 if (height == -1)
69 {
70 if (style & wxVERTICAL)
71 height = 140;
72 else
73 height = 14;
74 }
75
76 // TODO create scrollbar
77
78 m_pageSize = 1;
79 m_viewSize = 1;
80 m_objectSize = 1;
81
82 SetFont(parent->GetFont());
83
84 m_hWnd = 0; // TODO: (WXHWND)scroll_bar;
85
86 // Subclass again for purposes of dialog editing mode
87 SubclassWin((WXHWND) scroll_bar);
88
89 SetSize(x, y, width, height);
90
91 return TRUE;
92 }
93
94 wxScrollBar::~wxScrollBar()
95 {
96 }
97
98 bool wxScrollBar::OS2OnScroll(int WXUNUSED(orientation), WXWORD wParam,
99 WXWORD pos, WXHWND control)
100 {
101 // TODO:
102 /*
103 int position = ::GetScrollPos((HWND) control, SB_CTL);
104 int minPos, maxPos;
105 ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos);
106
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
110 // reduce it again.
111 if ( m_pageSize > 1 )
112 maxPos -= (m_pageSize - 1);
113 #endif // __WIN95__
114
115 wxEventType scrollEvent = wxEVT_NULL;
116
117 int nScrollInc;
118 switch ( wParam )
119 {
120 case SB_TOP:
121 nScrollInc = maxPos - position;
122 scrollEvent = wxEVT_SCROLL_TOP;
123 break;
124
125 case SB_BOTTOM:
126 nScrollInc = - position;
127 scrollEvent = wxEVT_SCROLL_BOTTOM;
128 break;
129
130 case SB_LINEUP:
131 nScrollInc = -1;
132 scrollEvent = wxEVT_SCROLL_LINEUP;
133 break;
134
135 case SB_LINEDOWN:
136 nScrollInc = 1;
137 scrollEvent = wxEVT_SCROLL_LINEDOWN;
138 break;
139
140 case SB_PAGEUP:
141 nScrollInc = -GetPageSize();
142 scrollEvent = wxEVT_SCROLL_PAGEUP;
143 break;
144
145 case SB_PAGEDOWN:
146 nScrollInc = GetPageSize();
147 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
148 break;
149
150 case SB_THUMBTRACK:
151 case SB_THUMBPOSITION:
152 nScrollInc = pos - position;
153 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
154 break;
155
156 default:
157 nScrollInc = 0;
158 }
159
160 if ( nScrollInc == 0 )
161 {
162 // no event to process, so don't process it
163 return FALSE;
164 }
165
166 int new_pos = position + nScrollInc;
167
168 if (new_pos < 0)
169 new_pos = 0;
170 if (new_pos > maxPos)
171 new_pos = maxPos;
172
173 SetThumbPosition(new_pos);
174 wxScrollEvent event(scrollEvent, m_windowId);
175 event.SetPosition(new_pos);
176 event.SetEventObject( this );
177
178 return GetEventHandler()->ProcessEvent(event);
179 */
180 return FALSE;
181 }
182
183 void wxScrollBar::SetThumbPosition(int viewStart)
184 {
185 // TODO
186 }
187
188 int wxScrollBar::GetThumbPosition() const
189 {
190 // TODO
191 return 0;
192 }
193
194 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
195 bool refresh)
196 {
197 m_viewSize = pageSize;
198 m_pageSize = thumbSize;
199 m_objectSize = range;
200
201 // TODO
202 }
203
204 #if WXWIN_COMPATIBILITY
205 void wxScrollBar::SetPageSize(int pageLength)
206 {
207 m_pageSize = pageLength;
208
209 // TODO:
210 }
211
212 void wxScrollBar::SetObjectLength(int objectLength)
213 {
214 m_objectSize = objectLength;
215
216 // The range (number of scroll steps) is the
217 // object length minus the view size.
218 int range = wxMax((objectLength - m_viewSize), 0) ;
219
220 // TODO:
221 }
222
223 void wxScrollBar::SetViewLength(int viewLength)
224 {
225 m_viewSize = viewLength;
226 }
227
228 void wxScrollBar::GetValues(int *viewStart, int *viewLength, int *objectLength,
229 int *pageLength) const
230 {
231 // TODO:
232 /*
233 *viewStart = ::GetScrollPos((HWND)m_hWnd, SB_CTL);
234 *viewLength = m_viewSize;
235 *objectLength = m_objectSize;
236 *pageLength = m_pageSize;
237 */
238 }
239 #endif
240
241 WXHBRUSH wxScrollBar::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
242 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
243 {
244 return 0;
245 }
246
247 void wxScrollBar::Command(wxCommandEvent& event)
248 {
249 SetThumbPosition(event.m_commandInt);
250 ProcessCommand(event);
251 }
252
253 #if WXWIN_COMPATIBILITY
254 // Backward compatibility
255 void wxScrollBar::OnScroll(wxScrollEvent& event)
256 {
257 // TODO:
258 /*
259 wxEventType oldEvent = event.GetEventType();
260 event.SetEventType( wxEVT_COMMAND_SCROLLBAR_UPDATED );
261 if ( !GetEventHandler()->ProcessEvent(event) )
262 {
263 event.SetEventType( oldEvent );
264 if (!GetParent()->GetEventHandler()->ProcessEvent(event))
265 event.Skip();
266 }
267 */
268 }
269 #endif